script_long.js 21 KB

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