|
@@ -323,7 +323,7 @@ function openNav() {
|
|
|
boxTitle.classList.add('box-title');
|
|
|
boxTitle.textContent = obj.name;
|
|
|
boxTitle.id = obj.id;
|
|
|
- boxTitle.setAttribute('onclick', `load_data(${obj.id})`);
|
|
|
+ boxTitle.setAttribute('onclick', `load_data(${obj.id}, ${loaded_data})`);
|
|
|
|
|
|
var boxLink = document.createElement('span');
|
|
|
boxLink.classList.add('box-link');
|
|
@@ -333,7 +333,7 @@ function openNav() {
|
|
|
contentBox.appendChild(boxTitle);
|
|
|
contentBox.appendChild(boxLink);
|
|
|
list.classList.add("historyList-item");
|
|
|
- list.setAttribute('onclick', `load_data(${obj.id})`);
|
|
|
+ list.setAttribute('onclick', `load_data(${obj.id}, ${loaded_data})`);
|
|
|
list.appendChild(divImgfr);
|
|
|
list.appendChild(contentBox);
|
|
|
historyList.appendChild(list);
|
|
@@ -379,22 +379,29 @@ function get_jwt_token(){
|
|
|
return jwt_raw.split('=')[1];
|
|
|
}
|
|
|
|
|
|
-function load_data(tid, loaded_data) {
|
|
|
+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;
|
|
@@ -435,12 +442,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();
|
|
@@ -547,6 +566,7 @@ $('.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();
|
|
@@ -567,7 +587,14 @@ $('.draft-btn').click(() => {
|
|
|
}
|
|
|
let multiLang = 0
|
|
|
if ($('#multiLang').prop("checked")) {multiLang = 1;}
|
|
|
- let dataOBJ = { "id": -1, "title": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang }
|
|
|
+ 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',
|
|
@@ -580,10 +607,35 @@ $('.draft-btn').click(() => {
|
|
|
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);
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
|