script_util.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. //checkRoute();
  2. let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
  3. if(userBasics.length > 0 && typeof(userBasics) !== 'string'){
  4. $('.userName').html(`<h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi ${userBasics.user_info.userName}</h2>`);
  5. }
  6. function checkRoute() {
  7. let jwt_token = get_jwt_token();
  8. /* if(jwt_token == undefined) {
  9. window.location.replace("login.html");
  10. } */
  11. axios({
  12. method: 'post',
  13. url: 'https://www.choozmo.com:8887/user_profile',
  14. headers: {
  15. 'accept': 'text/html',
  16. 'Authorization': `Bearer ${jwt_token}`
  17. }
  18. }).then(res => {
  19. console.log(res.data);
  20. if(res.status !== 200) {
  21. window.location.replace("login.html");
  22. }
  23. var userName='';
  24. userName+=`<h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi ${res.data.user_info.userName}</h2>`;
  25. $('.userName').html(userName);
  26. }).catch(err => {
  27. console.log(err);
  28. window.location.replace("login.html");
  29. });
  30. }
  31. const btnLoginPage = document.querySelector('.btn-login');
  32. const btnUserProfile = document.querySelector('.btn-userProfile');
  33. const btnLogout = document.querySelector('.btn-logout');
  34. function loginControl() {
  35. btnLoginPage.style.display = 'none';
  36. btnLogout.style.display = 'block';
  37. btnUserProfile.style.display = 'block';
  38. }
  39. loginControl();
  40. let lan = localStorage.getItem('lan');
  41. $('.dropdown-toggle').click(() => {
  42. lan = localStorage.getItem('lan');
  43. checkLan();
  44. });
  45. checkLan();
  46. function checkLan() {
  47. if(lan == 'en') {
  48. $('.btn-makev').css('display', 'none');
  49. $('.btn-makelong').css('display', 'none');
  50. } else {
  51. $('.btn-makev').css('display', 'block');
  52. $('.btn-makelong').css('display', 'block');
  53. }
  54. }
  55. function getAvatar() {
  56. let jwt_token = get_jwt_token();
  57. if(jwt_token == undefined) {
  58. window.location.replace("login.html");
  59. }
  60. axios({
  61. method: 'post',
  62. url: 'https://www.choozmo.com:8887/get_avatar_by_role',
  63. headers: {
  64. 'accept': 'text/html',
  65. 'Authorization': `Bearer ${jwt_token}`
  66. }
  67. }).then(res => {
  68. console.log(res.data);
  69. let result = [...res.data];
  70. let str = '';
  71. let carStr = '';
  72. for(let i = 0; i < result.length; i++) {
  73. str += `<option value="${result[i].num}">${result[i].name}</option>`
  74. }
  75. for(let i = 0; i < result.length; i++) {
  76. carStr += `<div class="card item col" data-avatar="${result[i].name}" data-img="${result[i].name.toLowerCase()}">
  77. <div class="imgfr"><img src="static/img/${result[i].name.toLowerCase()}.webp" class="card-img-top" alt="..."></div>
  78. <div class="card-body">
  79. <h5 class="card-title">${result[i].name.toLowerCase()}</h5>
  80. </div>
  81. </div>`;
  82. }
  83. $('#avatar').html(`<option set-lan="html:p_choose_character" value="請選擇人物" selected="selected" disabled>>請選擇人物</option>${str}`);
  84. $('.owl-carousel').html(carStr);
  85. // card = document.getElementsByClassName('card');
  86. console.log(card);
  87. addCardListener(card);
  88. }).catch(err => {
  89. console.log(err);
  90. });
  91. }
  92. //getAvatar();
  93. const card = document.getElementsByClassName('card');
  94. var client_id = Date.now()
  95. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  96. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  97. return new bootstrap.Tooltip(tooltipTriggerEl)
  98. });
  99. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  100. keyboard: false
  101. })
  102. var avatarModal = new bootstrap.Modal(document.getElementById('avatarmega'), {
  103. keyboard: false
  104. })
  105. var modalImg = document.querySelector("#avatarmega .modal-img");
  106. var modalTitle = document.querySelector("#avatarmega .modal-title");
  107. var avatarSelector = document.getElementById("avatar");
  108. avatarSelector.addEventListener('change', avatarChange);
  109. avatarChange();
  110. function addCardListener() {
  111. for (let i = 0; i < card.length; i++) {
  112. card[i].addEventListener('click', openavatarModel);
  113. }
  114. }
  115. addCardListener();
  116. function avatarChange() {
  117. var value = avatarSelector.options[avatarSelector.selectedIndex].text;
  118. $('.owl-carousel').trigger('to.owl.carousel', avatarSelector.selectedIndex);
  119. for (let i = 0; i < card.length; i++) {
  120. card[i].classList.remove('active');
  121. if (card[i].dataset.avatar == value) {
  122. card[i].classList.add('active');
  123. }
  124. }
  125. }
  126. function openavatarModel() {
  127. console.log(this.dataset.img);
  128. modalImg.setAttribute("src", `static/img/${this.dataset.img}.webp`);
  129. modalTitle.textContent = `${this.dataset.avatar}`;
  130. avatarModal.show();
  131. }
  132. $('input[type=file]').on('change', prepareUpload);
  133. $('.upload-btn').change(prepareUpload);
  134. function prepareUpload(event) {
  135. files = event.target.files;
  136. $(this).prev().val('');
  137. var data = new FormData();
  138. //data.append('file', $('.img_up1').prop('files')[0]);
  139. data.append('file', files[0]);
  140. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  141. $(this).next().text('');
  142. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  143. $.ajax({
  144. type: 'POST',
  145. processData: false, // important
  146. contentType: false, // important
  147. data: data,
  148. url: 'https://www.choozmo.com:8887/uploadfile',
  149. dataType: 'json',
  150. success: function (jsonData) {
  151. event.target.previousSibling.value = jsonData.msg;
  152. console.log(jsonData.msg);
  153. $(this).prev().val(jsonData.msg);
  154. if(jsonData.msg.zh) {
  155. $(this).prev().val(jsonData.msg.zh);
  156. event.target.previousSibling.value = jsonData.msg.zh;
  157. }
  158. event.target.nextSibling.innerHTML = '';
  159. event.target.nextSibling.textContent = '上傳檔案';
  160. //console.log($(this).next());
  161. //$(this).next().html('上傳檔案');
  162. //$(this).next().text('上傳檔案');
  163. },
  164. error: function (error) {
  165. event.target.nextSibling.innerHTML = '';
  166. event.target.nextSibling.textContent = '上傳檔案';
  167. alert('圖片錯誤');
  168. }
  169. });
  170. }
  171. const button = document.querySelector('.next');
  172. $(".next").click(function () {
  173. button.setAttribute('disabled', '');
  174. setTimeout(function () {
  175. button.removeAttribute('disabled')
  176. }, 15000);
  177. avatar = $('.avatar').val();
  178. name_title = $('.title_new').val();
  179. txtARR = [];
  180. imgARR = [];
  181. var step;
  182. let contentIdx = document.querySelectorAll(".txtsrc").length;
  183. for (let i = 1; i < (contentIdx + 1); i++) {
  184. if ($(`.txtsrc${i}`).val() != "") {
  185. txtARR.push($(`.txtsrc${i}`).val())
  186. }
  187. }
  188. let imgIdx = document.querySelectorAll(".imgsrc").length;
  189. for (let i = 1; i < (imgIdx + 1); i++) {
  190. if ($(`.imgsrc${i}`).val() != "") {
  191. imgARR.push($(`.imgsrc${i}`).val())
  192. }
  193. }
  194. multiLang = 0;
  195. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  196. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang, "client_id": client_id }
  197. objstr = JSON.stringify(dataOBJ);
  198. console.log(dataOBJ)
  199. jwt_token = get_jwt_token()
  200. var xhr = new XMLHttpRequest();
  201. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video");
  202. xhr.setRequestHeader("accept", "application/json");
  203. xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
  204. xhr.setRequestHeader("Content-Type", "application/json");
  205. xhr.onreadystatechange = function () {
  206. if (xhr.readyState === 4) {
  207. responseOBJ = JSON.parse(xhr.responseText)
  208. console.log(responseOBJ.msg);
  209. //let title = "資料已送出";
  210. let text;
  211. if(lan == 'en') {
  212. //title = 'Submitted Successfully!';
  213. text = responseOBJ.msg.eng;
  214. } else {
  215. text = responseOBJ.msg.zh;
  216. }
  217. Swal.fire({
  218. // title: title,
  219. icon: 'info',
  220. text: text,
  221. confirmButtonColor: '#3085d6',
  222. });
  223. }
  224. };
  225. var data = renderXHR_data(dataOBJ)
  226. console.log(data)
  227. result = xhr.send(objstr);
  228. });
  229. $(".gen_avatar").click(function () {
  230. dataOBJ = { "imgurl": $('.img_src').val() }
  231. objstr = JSON.stringify(dataOBJ);
  232. console.log(dataOBJ)
  233. //alert('資料已送出! 請耐心等候')
  234. $.ajax({
  235. url: 'https://www.choozmo.com:8887/swapFace',
  236. dataType: 'json', // 預期從server接收的資料型態
  237. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  238. type: 'post',
  239. data: objstr,
  240. success: function (suc_data) {
  241. alert(suc_data.msg)
  242. },
  243. //data:JSON.stringify({n1:"12",n2:"22"}),
  244. error: function (error) {
  245. console.error(error)
  246. }
  247. });
  248. });
  249. var loaded_data = ''
  250. function openNav() {
  251. document.getElementById("mySidenav").style.width = "250px";
  252. document.querySelector('.loader').style.display = "block";
  253. let jwt_token = get_jwt_token();
  254. axios({
  255. method: 'post',
  256. url: 'https://www.choozmo.com:8887/history_input',
  257. headers: {
  258. 'accept': 'application/json',
  259. 'Authorization': `Bearer ${jwt_token}`
  260. }
  261. }).then(res => {
  262. console.log(res.data);
  263. loaded_data = res.data;
  264. var historyList = document.querySelector('.historyList');
  265. historyList.innerHTML = '';
  266. for (var obj of loaded_data) {
  267. var list = document.createElement('li');
  268. list.id = obj.id;
  269. // div-imgfr
  270. var divImgfr = document.createElement('div');
  271. divImgfr.classList.add('item_imgfr');
  272. var img = document.createElement('img');
  273. img.setAttribute('src', obj['image_urls'][0]);
  274. divImgfr.appendChild(img);
  275. // div-content
  276. var contentBox = document.createElement('div');
  277. contentBox.classList.add('content-box');
  278. var boxTitle = document.createElement('p');
  279. boxTitle.classList.add('box-title');
  280. boxTitle.textContent = obj.name;
  281. boxTitle.id = obj.id;
  282. console.log(loaded_data);
  283. boxTitle.setAttribute('onclick', `direct(${obj.id})`);
  284. var boxLink = document.createElement('span');
  285. boxLink.classList.add('box-link');
  286. boxLink.setAttribute("data-url", obj.link);
  287. boxLink.setAttribute('onclick', 'view()');
  288. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  289. contentBox.appendChild(boxTitle);
  290. contentBox.appendChild(boxLink);
  291. list.classList.add("historyList-item");
  292. list.setAttribute('onclick', `direct(${obj.id})`);
  293. list.appendChild(divImgfr);
  294. list.appendChild(contentBox);
  295. historyList.appendChild(list);
  296. }
  297. document.querySelector('.loader').style.display = "none";
  298. }).catch(err => {
  299. console.log(err);
  300. });
  301. }
  302. function closeNav() {
  303. document.getElementById("mySidenav").style.width = "250px";
  304. }
  305. function view() {
  306. event.stopPropagation();
  307. console.log(event.target);
  308. if (event.target.nodeName === 'I') {
  309. return;
  310. } else {
  311. window.open(`http://${event.target.dataset.url}`, '_blank');
  312. }
  313. }
  314. function renderXHR_data(jsonObj) {
  315. XHRstring = ''
  316. for (const [key, value] of Object.entries(jsonObj)) {
  317. console.log(value)
  318. if (typeof (value) == "object") {
  319. XHRstring += (key+'=['+value.join(',')+']&')
  320. }
  321. else {
  322. XHRstring += (key + '=' + value + '&')
  323. }
  324. }
  325. XHRstring = XHRstring.substring(0, XHRstring.length - 1);
  326. return XHRstring
  327. }
  328. function get_jwt_token(){
  329. jwt_raw = document.cookie.split(';').filter(s=>s.includes('jwt_token'))[0];
  330. if(!jwt_raw) {return}
  331. return jwt_raw.split('=')[1];
  332. }
  333. function direct(id) {
  334. location.href = `make_video2.html?id=${id}`;
  335. }
  336. function load_data(tid, loaded_data, draft = false) {
  337. if(!tid) {
  338. return;
  339. }
  340. var title = document.getElementById("title");
  341. var linker = document.getElementById("linker");
  342. myModal.hide();
  343. if(!draft) {
  344. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  345. linker.setAttribute('target', '_blank')
  346. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  347. $("#linker").show();
  348. $(".linker__box").show();
  349. }
  350. console.log(loaded_data);
  351. let historyItem = loaded_data.filter(item => item.id == tid)[0];
  352. console.log(historyItem.title);
  353. if(draft) {
  354. $(".title_new").val(historyItem.title);
  355. $("#avatar").val(historyItem.avatar);
  356. } else {
  357. $(".title_new").val(loaded_data.find(item => item.id == tid).name);
  358. $("#avatar").val(historyItem.avatar);
  359. }
  360. let txtlength = historyItem.text_content.length;
  361. let imglength = historyItem.image_urls.length;
  362. subtitleInputs.innerHTML = '';
  363. imgInputs.innerHTML = '';
  364. for (let i = 0; i < txtlength; i++) {
  365. var txtinput = document.createElement("input");
  366. txtinput.setAttribute('type', 'text');
  367. txtinput.setAttribute('name', `t${i + 1}`);
  368. txtinput.value = historyItem.text_content[i];
  369. txtinput.setAttribute('placeholder', `${i + 1}`);
  370. txtinput.classList.add('txtsrc', `txtsrc${i + 1}`)
  371. subtitleInputs.appendChild(txtinput);
  372. }
  373. for (let i = 0; i < imglength; i++) {
  374. var imginput = document.createElement("input");
  375. imginput.setAttribute('type', 'text');
  376. imginput.setAttribute('name', `m${i + 1}`);
  377. imginput.classList.add('imgsrc', `imgsrc${i + 1}`);
  378. imginput.value = historyItem.image_urls[i];
  379. imginput.setAttribute('placeholder', `${i + 1}`);
  380. imgInputs.appendChild(imginput);
  381. var imgupload = document.createElement("input");
  382. imgupload.setAttribute('id', `img${i + 1}`);
  383. imgupload.setAttribute('type', `file`);
  384. imgupload.classList.add('img_uploader', 'img_up');
  385. imgInputs.appendChild(imgupload);
  386. var imguploadlabel = document.createElement("label");
  387. imguploadlabel.setAttribute('for', `img${i + 1}`);
  388. imguploadlabel.classList.add('upload-btn');
  389. imguploadlabel.textContent = '上傳檔案';
  390. if(lan == 'en') {
  391. imguploadlabel.textContent = 'Upload';
  392. }
  393. imguploadlabel.setAttribute('set-lan', `html:upload_file`);
  394. $('input[type=file]').on('change', prepareUpload);
  395. imgInputs.appendChild(imguploadlabel);
  396. }
  397. setTimeout(() => {
  398. JsLoadingOverlay.hide();
  399. }, 0);
  400. }
  401. getpathId();
  402. function getMode() {
  403. let id = window.location.search.split('?').pop();
  404. let mode = id.split('=')[0];
  405. if(mode == 'draftid') {
  406. /* JsLoadingOverlay.show({
  407. "overlayBackgroundColor": "#FFFFFF",
  408. "overlayOpacity": "0.9",
  409. "spinnerIcon": "ball-circus",
  410. "spinnerColor": "#B9DDF3",
  411. "spinnerSize": "2x",
  412. "overlayIDName": "overlay",
  413. "spinnerIDName": "spinner",
  414. "offsetX": 0,
  415. "offsetY": 0,
  416. "containerID": null,
  417. "lockScroll": false,
  418. "overlayZIndex": 9998,
  419. "spinnerZIndex": 9999
  420. }); */
  421. getDraftData();
  422. } else if(mode == 'id') {
  423. /* JsLoadingOverlay.show({
  424. "overlayBackgroundColor": "#FFFFFF",
  425. "overlayOpacity": "0.9",
  426. "spinnerIcon": "ball-circus",
  427. "spinnerColor": "#B9DDF3",
  428. "spinnerSize": "2x",
  429. "overlayIDName": "overlay",
  430. "spinnerIDName": "spinner",
  431. "offsetX": 0,
  432. "offsetY": 0,
  433. "containerID": null,
  434. "lockScroll": false,
  435. "overlayZIndex": 9998,
  436. "spinnerZIndex": 9999
  437. }); */
  438. getData();
  439. }
  440. return id.split('=')[1];
  441. //load_data(id);
  442. }
  443. getMode();
  444. function getpathId(){
  445. let id = window.location.search.split('?').pop();
  446. return id.split('=')[1];
  447. }
  448. function getData() {
  449. let jwt_token = get_jwt_token();
  450. axios({
  451. method: 'post',
  452. url: 'https://www.choozmo.com:8887/history_input',
  453. headers: {
  454. 'accept': 'application/json',
  455. 'Authorization': `Bearer ${jwt_token}`
  456. }
  457. }).then(res => {
  458. loaded_data = res.data;
  459. console.log(loaded_data);
  460. const id = getpathId();
  461. load_data(id, loaded_data);
  462. }).catch(err => {
  463. console.log(err);
  464. });
  465. }
  466. var subtitleInputs = document.querySelector(".subtitle-inputs");
  467. var imgInputs = document.querySelector(".img-inputs");
  468. let length = 5;
  469. function initial() {
  470. for (let i = 0; i < length; i++) {
  471. rendertxtBlock(i + 1);
  472. renderimgBlock(i + 1);
  473. }
  474. console.log(document.querySelectorAll(".txtsrc").length + 1);
  475. }
  476. initial();
  477. var addbtn = document.querySelector(".add");
  478. var addimgbtn = document.querySelector(".addimg");
  479. addbtn.addEventListener('click', addtxtBlock);
  480. addimgbtn.addEventListener('click', addimgBlock);
  481. function addtxtBlock() {
  482. let newIdx = document.querySelectorAll(".txtsrc").length + 1;
  483. rendertxtBlock(newIdx);
  484. }
  485. function addimgBlock() {
  486. let newimgIdx = document.querySelectorAll(".imgsrc").length + 1;
  487. renderimgBlock(newimgIdx);
  488. }
  489. function rendertxtBlock(i) {
  490. var txtinput = document.createElement("input");
  491. txtinput.setAttribute('type', 'text');
  492. txtinput.setAttribute('name', `t${i}`);
  493. txtinput.value = "";
  494. txtinput.setAttribute('placeholder', `${i}`);
  495. txtinput.classList.add('txtsrc', `txtsrc${i}`)
  496. subtitleInputs.appendChild(txtinput);
  497. }
  498. function renderimgBlock(i) {
  499. var imginput = document.createElement("input");
  500. imginput.setAttribute('type', 'text');
  501. imginput.setAttribute('name', `m${i}`);
  502. imginput.classList.add('imgsrc', `imgsrc${i}`);
  503. imginput.value = "";
  504. imginput.setAttribute('placeholder', `${i}`);
  505. imgInputs.appendChild(imginput);
  506. var imgupload = document.createElement("input");
  507. imgupload.setAttribute('id', `img${i}`);
  508. imgupload.setAttribute('type', `file`);
  509. imgupload.classList.add('img_uploader', 'img_up');
  510. imgInputs.appendChild(imgupload);
  511. var imguploadlabel = document.createElement("label");
  512. imguploadlabel.setAttribute('for', `img${i}`);
  513. imguploadlabel.classList.add('upload-btn');
  514. imguploadlabel.textContent = '上傳檔案';
  515. if(lan == 'en') {
  516. imguploadlabel.textContent = 'Upload';
  517. }
  518. imguploadlabel.setAttribute('set-lan', `html:upload_file`);
  519. imgInputs.appendChild(imguploadlabel);
  520. $('input[type=file]').on('change', prepareUpload);
  521. }
  522. $('.owl-carousel').owlCarousel({
  523. loop: true,
  524. margin: 10,
  525. nav: false,
  526. mouseDrag: true,
  527. touchDrag: true,
  528. smartSpeed: 1000,
  529. autoplay: true,
  530. autoplayTimeout: 8000,
  531. autoplayHoverPause: false,
  532. responsive: {
  533. 0: {
  534. items: 1
  535. },
  536. 600: {
  537. items: 2
  538. },
  539. 1000: {
  540. items: 4
  541. }
  542. }
  543. });
  544. $('.draft-btn').click(() => {
  545. let text = '儲存中...';
  546. if (lan == 'en') {
  547. text = 'Saving...';
  548. }
  549. $('.draft-btn').text(text);
  550. let jwt_token = get_jwt_token();
  551. let avatar = $('.avatar').val();
  552. let name_title = $('.title_new').val();
  553. let txtARR = [];
  554. let imgARR = [];
  555. var step;
  556. let contentIdx = document.querySelectorAll(".txtsrc").length;
  557. for (let i = 1; i < (contentIdx + 1); i++) {
  558. if ($(`.txtsrc${i}`).val() != "") {
  559. txtARR.push($(`.txtsrc${i}`).val())
  560. }
  561. }
  562. let imgIdx = document.querySelectorAll(".imgsrc").length;
  563. for (let i = 1; i < (imgIdx + 1); i++) {
  564. if ($(`.imgsrc${i}`).val() != "") {
  565. imgARR.push($(`.imgsrc${i}`).val())
  566. }
  567. }
  568. let multiLang = 0
  569. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  570. let id = window.location.search.split('?').pop();
  571. let mode = id.split('=')[0];
  572. if(mode == 'draftid') {
  573. id = Number(id.split('=')[1]);
  574. } else {
  575. id = -1;
  576. }
  577. let dataOBJ = { "id": id, "title": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang }
  578. console.log(dataOBJ);
  579. axios({
  580. method: 'post',
  581. url: 'https://www.choozmo.com:8887/save_draft',
  582. headers: {
  583. 'accept': 'application/json',
  584. 'Authorization': `Bearer ${jwt_token}`,
  585. 'Content-Type': 'application/json',
  586. },
  587. data: dataOBJ
  588. }).then(res => {
  589. console.log(res.data);
  590. $('.draft-btn').text('存為草稿');
  591. let title = "儲存完成";
  592. if(lan == 'en') {
  593. title = 'Saved!'
  594. $('.draft-btn').text('Save as Draft');
  595. }
  596. Swal.fire({
  597. title: title,
  598. icon: 'success',
  599. confirmButtonColor: '#3085d6',
  600. });
  601. }).catch(err => {
  602. console.log(err);
  603. });
  604. });
  605. function getDraftData() {
  606. let token = get_jwt_token();
  607. axios({
  608. method: 'post',
  609. url: 'https://www.choozmo.com:8887/draft_list',
  610. headers: {
  611. 'accept': 'application/json',
  612. 'Authorization': `Bearer ${token}`
  613. }
  614. }).then(res => {
  615. console.log(res.data);
  616. let result = [...res.data];
  617. let id = getpathId();
  618. load_data(id, result, true);
  619. }).catch(err => {
  620. console.log(err);
  621. });
  622. }
  623. $(".copy").click(function(){
  624. const copyStr = $(this).next().text();
  625. copyToClipboard(copyStr);
  626. });
  627. const copyToClipboard = str => {
  628. const el = document.createElement('textarea');
  629. el.value = str;
  630. el.setAttribute('readonly', '');
  631. el.style.position = 'absolute';
  632. el.style.left = '-9999px';
  633. document.body.appendChild(el);
  634. el.select();
  635. document.execCommand('copy');
  636. document.body.removeChild(el);
  637. Swal.fire({
  638. toast: true,
  639. icon: 'success',
  640. position: 'top-end',
  641. title: 'Link copied!',
  642. timerProgressBar: true,
  643. showConfirmButton: false,
  644. timer: 1000,
  645. backdrop: false
  646. })
  647. };
  648. $("#lang-manu").hide();
  649. $( "#changeLanguage" ).click(function() {
  650. $("#lang-manu").slideToggle();
  651. $("#lang-arrow").toggleClass("arrowdoup");
  652. });