|
@@ -1,5 +1,10 @@
|
|
|
checkRoute();
|
|
|
|
|
|
+let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
|
|
|
+if(userBasics !== []){
|
|
|
+ $('.userName').html(`<h2 class="user-name text-white mt-4 fw-bold">Hello,${userBasics.user_info.userName}</h2>`);
|
|
|
+}
|
|
|
+
|
|
|
function checkRoute() {
|
|
|
let jwt_token = get_jwt_token();
|
|
|
if(jwt_token == undefined) {
|
|
@@ -323,7 +328,8 @@ function openNav() {
|
|
|
boxTitle.classList.add('box-title');
|
|
|
boxTitle.textContent = obj.name;
|
|
|
boxTitle.id = obj.id;
|
|
|
- boxTitle.setAttribute('onclick', `load_data(${obj.id})`);
|
|
|
+ console.log(loaded_data);
|
|
|
+ boxTitle.setAttribute('onclick', `direct(${obj.id})`);
|
|
|
|
|
|
var boxLink = document.createElement('span');
|
|
|
boxLink.classList.add('box-link');
|
|
@@ -333,7 +339,7 @@ function openNav() {
|
|
|
contentBox.appendChild(boxTitle);
|
|
|
contentBox.appendChild(boxLink);
|
|
|
list.classList.add("historyList-item");
|
|
|
- list.setAttribute('onclick', `load_data(${obj.id})`);
|
|
|
+ list.setAttribute('onclick', `direct(${obj.id})`);
|
|
|
list.appendChild(divImgfr);
|
|
|
list.appendChild(contentBox);
|
|
|
historyList.appendChild(list);
|
|
@@ -379,22 +385,34 @@ function get_jwt_token(){
|
|
|
return jwt_raw.split('=')[1];
|
|
|
}
|
|
|
|
|
|
-function load_data(tid, loaded_data) {
|
|
|
+function direct(id) {
|
|
|
+ location.href = `make_video.html?id=${id}`;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function load_data(tid, loaded_data, draft = false) {
|
|
|
if(!tid) {
|
|
|
return;
|
|
|
}
|
|
|
var title = document.getElementById("title");
|
|
|
var linker = document.getElementById("linker");
|
|
|
- myModal.hide()
|
|
|
- linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
|
|
|
- linker.setAttribute('target', '_blank')
|
|
|
- $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
|
|
|
- $("#linker").show();
|
|
|
- $(".linker__box").show();
|
|
|
-
|
|
|
+ myModal.hide();
|
|
|
+ if(!draft) {
|
|
|
+ linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
|
|
|
+ linker.setAttribute('target', '_blank')
|
|
|
+ $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
|
|
|
+ $("#linker").show();
|
|
|
+ $(".linker__box").show();
|
|
|
+ }
|
|
|
+ console.log(loaded_data);
|
|
|
let historyItem = loaded_data.filter(item => item.id == tid)[0];
|
|
|
- console.log(historyItem);
|
|
|
- $(".title_new").val(loaded_data.find(item => item.id == tid).name);
|
|
|
+ console.log(historyItem.title);
|
|
|
+ if(draft) {
|
|
|
+ $(".title_new").val(historyItem.title);
|
|
|
+ $("#avatar").val(historyItem.avatar);
|
|
|
+ } else {
|
|
|
+ $(".title_new").val(loaded_data.find(item => item.id == tid).name);
|
|
|
+ }
|
|
|
|
|
|
let txtlength = historyItem.text_content.length;
|
|
|
let imglength = historyItem.image_urls.length;
|
|
@@ -428,6 +446,7 @@ function load_data(tid, loaded_data) {
|
|
|
imguploadlabel.setAttribute('for', `img${i + 1}`);
|
|
|
imguploadlabel.classList.add('upload-btn');
|
|
|
imguploadlabel.textContent = '上傳檔案';
|
|
|
+ imguploadlabel.setAttribute('set-lan', `html:upload_file`);
|
|
|
imgInputs.appendChild(imguploadlabel);
|
|
|
}
|
|
|
|
|
@@ -435,12 +454,24 @@ function load_data(tid, loaded_data) {
|
|
|
|
|
|
getpathId();
|
|
|
|
|
|
-function getpathId() {
|
|
|
- id = window.location.search.split('?').pop();
|
|
|
+function getMode() {
|
|
|
+ let id = window.location.search.split('?').pop();
|
|
|
+ let mode = id.split('=')[0];
|
|
|
+ if(mode == 'draftid') {
|
|
|
+ getDraftData();
|
|
|
+ } else if(mode == 'id') {
|
|
|
+ getData()
|
|
|
+ }
|
|
|
return id.split('=')[1];
|
|
|
//load_data(id);
|
|
|
}
|
|
|
-getData();
|
|
|
+
|
|
|
+getMode();
|
|
|
+
|
|
|
+function getpathId(){
|
|
|
+ let id = window.location.search.split('?').pop();
|
|
|
+ return id.split('=')[1];
|
|
|
+}
|
|
|
|
|
|
function getData() {
|
|
|
let jwt_token = get_jwt_token();
|
|
@@ -518,6 +549,7 @@ function renderimgBlock(i) {
|
|
|
imguploadlabel.setAttribute('for', `img${i}`);
|
|
|
imguploadlabel.classList.add('upload-btn');
|
|
|
imguploadlabel.textContent = '上傳檔案';
|
|
|
+ imguploadlabel.setAttribute('set-lan', `html:upload_file`);
|
|
|
imgInputs.appendChild(imguploadlabel);
|
|
|
$('input[type=file]').on('change', prepareUpload);
|
|
|
}
|
|
@@ -546,4 +578,104 @@ $('.owl-carousel').owlCarousel({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+$('.draft-btn').click(() => {
|
|
|
+ $('.draft-btn').text('Loading...');
|
|
|
+ let jwt_token = get_jwt_token();
|
|
|
+ let avatar = $('.avatar').val();
|
|
|
+ let name_title = $('.title_new').val();
|
|
|
+ let txtARR = [];
|
|
|
+ let imgARR = [];
|
|
|
+ var step;
|
|
|
+ let contentIdx = document.querySelectorAll(".txtsrc").length;
|
|
|
+ for (let i = 1; i < (contentIdx + 1); i++) {
|
|
|
+ if ($(`.txtsrc${i}`).val() != "") {
|
|
|
+ txtARR.push($(`.txtsrc${i}`).val())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let imgIdx = document.querySelectorAll(".imgsrc").length;
|
|
|
+ for (let i = 1; i < (imgIdx + 1); i++) {
|
|
|
+ if ($(`.imgsrc${i}`).val() != "") {
|
|
|
+ imgARR.push($(`.imgsrc${i}`).val())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let multiLang = 0
|
|
|
+ if ($('#multiLang').prop("checked")) {multiLang = 1;}
|
|
|
+ let id = window.location.search.split('?').pop();
|
|
|
+ let mode = id.split('=')[0];
|
|
|
+ if(mode == 'draftid') {
|
|
|
+ id = Number(id.split('=')[1]);
|
|
|
+ } else {
|
|
|
+ id = -1;
|
|
|
+ }
|
|
|
+ let dataOBJ = { "id": id, "title": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang }
|
|
|
+ console.log(dataOBJ);
|
|
|
+ axios({
|
|
|
+ method: 'post',
|
|
|
+ url: 'https://www.choozmo.com:8887/save_draft',
|
|
|
+ headers: {
|
|
|
+ 'accept': 'application/json',
|
|
|
+ 'Authorization': `Bearer ${jwt_token}`,
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ },
|
|
|
+ data: dataOBJ
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res.data);
|
|
|
+ $('.draft-btn').text('存為草稿');
|
|
|
+ Swal.fire({
|
|
|
+ title: "儲存完成",
|
|
|
+ icon: 'success',
|
|
|
+ confirmButtonColor: '#3085d6',
|
|
|
+ });
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+
|
|
|
+});
|
|
|
+
|
|
|
+function getDraftData() {
|
|
|
+ let token = get_jwt_token();
|
|
|
+ axios({
|
|
|
+ method: 'post',
|
|
|
+ url: 'https://www.choozmo.com:8887/draft_list',
|
|
|
+ headers: {
|
|
|
+ 'accept': 'application/json',
|
|
|
+ 'Authorization': `Bearer ${token}`
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res.data);
|
|
|
+ let result = [...res.data];
|
|
|
+ let id = getpathId();
|
|
|
+ load_data(id, result, true);
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+$(".copy").click(function(){
|
|
|
+ const copyStr = $(this).next().text();
|
|
|
+ copyToClipboard(copyStr);
|
|
|
+});
|
|
|
+
|
|
|
+const copyToClipboard = str => {
|
|
|
+ const el = document.createElement('textarea');
|
|
|
+ el.value = str;
|
|
|
+ el.setAttribute('readonly', '');
|
|
|
+ el.style.position = 'absolute';
|
|
|
+ el.style.left = '-9999px';
|
|
|
+ document.body.appendChild(el);
|
|
|
+ el.select();
|
|
|
+ document.execCommand('copy');
|
|
|
+ document.body.removeChild(el);
|
|
|
+ Swal.fire({
|
|
|
+ toast: true,
|
|
|
+ icon: 'success',
|
|
|
+ position: 'top-end',
|
|
|
+ title: 'Link copied!',
|
|
|
+ timerProgressBar: true,
|
|
|
+ showConfirmButton: false,
|
|
|
+ timer: 1000,
|
|
|
+ backdrop: false
|
|
|
+ })
|
|
|
+};
|
|
|
|