Pages.Trash = { _template: 'trash.html', template: '
this is trash.html
', data: function () { return { lang_choose: localStorage.getItem('lang_choose') || 'th', lang_txt: lang_trash, lang_err: "", display: false, list_document: [], list_document2: [], txt_search: "", filter: { doc: "", signer: "", send: "", date: "", }, count_check: 0, selectAllDocument: [], // added delete draft selectDocument: [], selectDraftDocument: [], // end delete draft // mv_folder: [], selectFolder: "", list_folder: [], btn_multi_remove: false, } }, mounted: function () { window.myApp = this this.get_list_document() // this.get_folder() }, filters: { date(value) { value = value || '' var date = new Date(value) var day = date.getDate() if (Number(day) <= 9) day = "0" + day var month = date.getMonth() + 1 if (Number(month) <= 9) month = "0" + month var year = date.getFullYear() value = day + "/" + month + "/" + year return value || "" }, time(value) { value = value || '' var date = new Date(value) var horus = date.getHours() if (Number(horus) <= 9) horus = "0" + horus var minutes = date.getMinutes() if (Number(minutes) <= 9) minutes = "0" + minutes var seconds = date.getSeconds() if (Number(seconds) <= 9) seconds = "0" + seconds value = horus + ":" + minutes + ":" + seconds return value || "" }, fomat_date(value) { var res = value.split("-"); var text = res[2] + '/' + res[1] + '/' + res[0] return text } }, methods: { // move_list_folder: function () { // var that = this // if (that.list_folder.length > 0) { // for (i = 0; i < that.list_folder.length; i++) { // var data = [] // for (j = 0; j < that.selectAllDocument.length; j++) { // data.push({ id_doc: that.selectAllDocument[j], id_folder: that.list_folder[i] }) // } // $.ajax({ // type: "POST", // url: api_host + "move_folder", // data: JSON.stringify(data), // dataType: "json", // success: function (res) { // // alert('ย้ายสำเร็จ') // }, // error: function (request, status, error) { // alert("|" + status + ' |' + error); // } // }); // } // alert(that.lang_txt.complete[that.lang_choose]) // } else { // console.log('not folder'); // } // }, // get_folder: function () { // var that = this // var adminEmail = JSON.parse(localStorage.getItem("register_obj")).adminEmail || "" // that.mv_folder = [] // // setTimeout(function(){ // if (adminEmail) { // var data = { owner_folder: adminEmail } // $.ajax({ // type: "POST", // url: api_host + "get_folder", // data: JSON.stringify(data), // dataType: "json", // success: function (res) { // that.mv_folder = res.data // }, // error: function (request, status, error) { // alert("|" + status + ' |' + error); // } // }); // } // // }, 3000); // }, restore_single: function (id) { var that = this Swal.fire({ title: that.lang_txt.want_restore[that.lang_choose], showDenyButton: true, confirmButtonText: that.lang_txt.confirm[that.lang_choose], denyButtonText: that.lang_txt.cancel[that.lang_choose], }).then((result) => { if (result.isConfirmed) { var data = { list_id: [], email: getUsername(), } data.list_id.push(id) list_document_load(id) $.ajax({ type: "POST", data: JSON.stringify(data), url: api_host + 'accept_restore_document', dataType: "json", success: function (resp) { if(resp.success) { that.lang_err = err_s["s_" + resp.error_code][that.lang_choose] display_alert("er_alert", "block", "none", "alert-success") // that.show_all_table() setTimeout(function(){ document.location.reload() }, 3000); } else { display_alert("er_alert", "block", "none", "alert-danger") } }, error: function (error) { alert("Something went wrong!" + error); } }) } else if (result.isDenied) { console.log("cancel remove draft") } }) }, restore_single_draft: function (id) { var that = this Swal.fire({ title: that.lang_txt.want_restore[that.lang_choose], showDenyButton: true, confirmButtonText: that.lang_txt.confirm[that.lang_choose], denyButtonText: that.lang_txt.cancel[that.lang_choose], }).then((result) => { if (result.isConfirmed) { var data = { id: id } $.ajax({ type: "POST", url: api_host + "restore_draft_bla", data: JSON.stringify(data), dataType: "json", success: function (resp) { if (resp.success) { that.lang_err = err_s["s_" + resp.error_code][that.lang_choose] display_alert("er_alert", "block", "none", "alert-success") // that.show_all_table() setTimeout(function(){ document.location.reload() }, 3000); } else { display_alert("er_alert", "block", "none", "alert-danger") } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); } else if (result.isDenied) { console.log("cancel remove draft") } }) }, check_btn_remove: function(arr){ var that = this that.btn_multi_remove = false var list = [] var list_doc = that.list_document for(i=0;i < arr.length; i++){ var select = list_doc.find(function(s){ return arr[i] == s._id }) if (select) list.push(select) } var list_not_remove = list.filter(function(l){ // added delete draft if (l.status_draft_delete) { return l.status_draft_delete != true } else { return l.status != 1 && l.status != 3 } // end delete draft // return l.status != 1 && l.status != 3 }) console.log(list_not_remove) if(list_not_remove.length == 0 ){ that.btn_multi_remove = true } }, restore_multi: function(){ var that = this Swal.fire({ title: that.lang_txt.want_restore[that.lang_choose], showDenyButton: true, confirmButtonText: that.lang_txt.confirm[that.lang_choose], denyButtonText: that.lang_txt.cancel[that.lang_choose], }).then((result) => { if (result.isConfirmed) { var data = { list_id: that.selectDocument, email: getUsername() || "N/A", } // added delete draft var data2 = { list_id: that.selectDraftDocument, email: getUsername() || "N/A", } for(i=0;i < that.selectAllDocument.length;i++) { list_document_load(that.selectAllDocument[i]) } // for(i=0;i < data.list_id.length;i++) { // list_document_load(data.list_id[i]) // } var del_normal_succ = false var del_draft_succ = false $.when( $.ajax({ type: "POST", data: JSON.stringify(data), url: api_host + 'accept_restore_document', dataType: "json", success: function (resp) { console.log(resp) if (resp.success) { del_normal_succ = true } else { del_normal_succ = false } }, error: function (request, status, error) { del_normal_succ = false } }), $.ajax({ type: "POST", url: api_host + "restore_multi_draft_bla", data: JSON.stringify(data2), dataType: "json", success: function (resp2) { console.log(resp2) if (resp2.success) { del_draft_succ = true } else { del_draft_succ = false } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }) ).then(function() { if (del_normal_succ && del_draft_succ) { that.lang_err = err_s["s_2102"][that.lang_choose] display_alert("er_alert", "block", "none", "alert-success") // that.show_all_table() setTimeout(function(){ document.location.reload() }, 3000); } else { display_alert("er_alert", "block", "none", "alert-danger") } }); // end delete draft // $.ajax({ // type: "POST", // data: JSON.stringify(data), // url: api_host + 'accept_restore_document', // dataType: "json", // success: function (resp) { // if(resp.success) { // console.log(resp) // var data2 = { // list_id: that.selectDraftDocument, // email: getUsername() || "N/A", // } // $.ajax({ // type: "POST", // url: api_host + "restore_multi_draft_bla", // data: JSON.stringify(data2), // dataType: "json", // success: function (resp2) { // console.log(resp2) // if (resp2.success) { // that.lang_err = err_s["s_" + resp2.error_code][that.lang_choose] // display_alert("er_alert", "block", "none", "alert-success") // // that.show_all_table() // setTimeout(function(){ // document.location.reload() // }, 3000); // } // else { // display_alert("er_alert", "block", "none", "alert-danger") // } // }, // error: function (request, status, error) { // alert("|" + status + ' |' + error); // } // }); // } // else { // display_alert("er_alert", "block", "none", "alert-danger") // } // }, // error: function (error) { // alert("Something went wrong!" + error); // } // }) } else if (result.isDenied) { console.log("cancel remove draft") } }) }, openBar: function (e) { var that = this; // added delete draft let elem = $(e.target) if (elem.is(':checked')) { if (elem.attr("data-draft") == "true") { that.selectDraftDocument.push(elem.val()) console.log("check-draft") } else { that.selectDocument.push(elem.val()) console.log("check-nodraft") } } else { if (elem.attr("data-draft") == "true") { that.selectDraftDocument = that.selectDraftDocument.filter(ev => ev !== elem.val()) console.log("uncheck-draft") } else { that.selectDocument = that.selectDocument.filter(ev => ev !== elem.val()) console.log("uncheck-nodraft") } } // end delete draft that.count_check = that.selectAllDocument.length that.check_btn_remove(that.selectAllDocument) }, get_list_document: function () { var that = this var data = { "company_id": "", "email": getUsername() || "N/A", "cat": 'trash' }; $.ajax({ type: "POST", url: api_host + "list_document_bla", data: JSON.stringify(data), dataType: "json", success: function (resp) { if (resp.success) { if (!resp.data.length) resp.data = [] var list = resp.data if (list.length > 0) { list.sort(function (a, b) { return b.createdDtm - a.createdDtm }) for (i = 0; i < list.length; i++) { list[i].diff_date = that.cal_date(list[i].createdDtm) list[i].date_remove = that.get_date_remove(list[i]) if (list[i].exp_date) { var c = that.cal_exp_date(list[i].exp_date) if (c <= 30) { list[i].chk_exp = true list[i].exp_date = that.$options.filters.fomat_date(list[i].exp_date) } else { list[i].chk_exp = false } } } that.list_document = list that.list_document2 = list that.set_table() } else { that.set_table() } } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); }, get_date_remove: function(arr){ var myemail = getUsername() || "N/A" var time = new Date().getTime() // console.log(arr) if (myemail == arr.owner) { console.log(arr.owner + " : " + arr.owner_time_remove) time = arr.owner_time_remove } else { var sign = arr.signers.find(function(s){ if (s.is_group == true) { return group = s.user_group.find(function(g){ return myemail == g.email && g.is_remove == true }) } else { return myemail == s.email && s.is_remove == true } }) if(!sign.time_remove) { var t = sign.user_group.find(function(s){ return s.email == myemail }) sign = t } time = sign.time_remove } // console.log(time) return time }, count_signer: function (signer, fields) { if (fields.length > 0) { var total = 0 for (i = 0; i < signer.length; i++) { if (signer[i].needToSign == true) { var f_owner = fields.filter(function (f) { return (signer[i].email == f.email) }) var f_sign = fields.filter(function (f) { return (signer[i].email == f.email && f.status == 1) }) if (f_sign.length == f_owner.length) { total = total + 1 } } else { total = total + 1 } } return total } else { return signer.length } }, my_status_signer: function (signer, fields, status) { if (fields && fields.length > 0 && status == 0 || !status) { var email = getUsername() || "N/A" if (!fields.length) fields = [] var my = fields.filter(function (f) { return (f.email == email && f.status == "0") }) var other = fields.filter(function (f) { return (f.email != email && f.status == "0") }) if (my.length > 0) return "0" else if (my.length == 0 && other.length > 0) return "1" else return "" } else { return "" } }, gotoDoc: function (id) { document.location.href = "#/document?id=" + id }, set_table: function () { var that = this setTimeout(function () { table = $('#table').DataTable({ paging: true, searching: false, ordering: false, info: false, lengthChange: true, responsive: true, lengthMenu: [[20, 50, 100, -1], [20, 50, 100, "ทั้งหมด"]], dom: '<"top"i>rt<"bottom"flp><"clear">', language: { lengthMenu: "_MENU_", }, fnDrawCallback: function( oSettings ) { var list = document.getElementsByClassName("checkfile") var list_check = [] for(i=0; i ev !== elem.val()) console.log("uncheck-draft") } else { that.selectDocument = that.selectDocument.filter(ev => ev !== elem.val()) console.log("uncheck-nodraft") } var select = that.selectAllDocument.find(function(s) { return list[i].value == s }) // end delete draft section if(select) list_select.push(select) list[i].checked = all.checked } var remove_select = that.selectAllDocument.filter(function(s) { return list_select.indexOf(s) == -1; }); that.selectAllDocument = remove_select that.count_check = that.selectAllDocument.length that.btn_multi_remove = false } }, t_onover: function (id) { var selected = document.getElementById(id) var tooltip = new bootstrap.Tooltip(selected) tooltip.show() } } } routes.push({ path: '/trash', component: Pages.Trash }) var lang_trash = { "inbox_title": { "th": "เอกสารที่ได้รับ", "en": "Inbox" }, "adv_search": { "th": "ค้นหาขั้นสูง", "en": "Advanced search" }, "clear": { "th": "ล้าง", "en": "Clear" }, "des_search": { "th": "ชื่อเอกสาร, ผู้ส่ง, ผู้รับ, อีเมล", "en": "Subject, Sender, Reciever, Email" }, "doc_status": { "th": "สถานะเอกสาร", "en": "Document Status" }, "sign_status": { "th": "สถานะการเซ็น", "en": "Signing Status" }, "sender": { "th": "ผู้ส่ง", "en": "Sender" }, "year": { "th": "12 เดือนย้อนหลัง", "en": "Last 12 months" }, "six": { "th": "6 เดือนย้อนหลัง", "en": "Last 6 months" }, "month": { "th": "30 วัน", "en": "Last 30 days" }, "week": { "th": "1 สัปดาห์", "en": "Last 1 weeks" }, "day": { "th": "1 วัน", "en": "Last 1 days" }, "me": { "th": "ฉัน", "en": "Me" }, "notme": { "th": "ไม่ใช่ฉัน", "en": "Not me" }, "date": { "th": "วันที่", "en": "Date" }, "subject": { "th": "เรื่อง", "en": "Subject" }, "status": { "th": "สถานะ", "en": "Status" }, "date_time": { "th": "วัน-เวลาที่ลบ", "en": "Date & Time Delete" }, "sign": { "th": "เซ็นเอกสาร", "en": "Sign" }, "signed": { "th": "เซ็นแล้ว", "en": "Signed" }, "notsign": { "th": "ยังไม่ได้เซ็น", "en": "Not Sign" }, "exp_date": { "th": "หมดอายุเมื่อ", "en": "Expiration Date" }, "doc_cancel": { "th": "เอกสารถูกยกเลิก", "en": "Cancelled" }, "exp": { "th": "(หมดอายุ)", "en": "(Expired)" }, "list": { "th": "รายการ", "en": "List" }, "incomplete": { "th": "ยังไม่สมบูรณ์", "en": "Incomplete" }, "exp_soon": { "th": "หมดอายุเร็วๆ นี้", "en": "Expired soon" }, "complete": { "th": "เสร็จสมบูรณ์", "en": "Completed" }, "move": { "th": "ย้าย", "en": "Move to folder" }, "select_move": { "th": "แฟ้มที่ต้องการย้าย", "en": "Select Folder to Move" }, "confirm_move": { "th": "ยืนยันย้าย", "en": "Confirm to Move" }, "wait": { "th": "กรุณารอสักครู่..", "en": "Please wait.." }, "des_create_folder": { "th": "เริ่มต้นด้วยการเพิ่มเอกสารลงในแฟ้มได้โดยคลิกที่ ​”ปุ่มเพิ่มเอกสาร", "en": "Click “Add New Document” button to add a document to the folder" }, "cancelled": { "th": "ถูกยกเลิก", "en": "Cancelled" }, "action_requi": { "th": "ที่ต้องดำเนินการ", "en": "Action Required" }, "waiting_other": { "th": "รอคนอื่นดำเนินการ", "en": "Waiting for Others" }, "trash": { "th": "ถังขยะ", "en": "Trash" }, "noti_trash": { "th": `คุณสามารถค้นหาเอกสารที่ถูกลบทั้งหมดได้ใน "ถังขยะ" และเอกสารจะถูกลบออกภายใน 24 ชั่วโมงจากบัญชีของคุณ`, "en": `You can find all deleted documents in “Trash”, and the document will be removed within 24 hours from your account.` }, "doc_list": { "th": "รายการ", "en": "Document" }, "want_restore": { "th": "คุณต้องการกู้คืนเอกสาร", "en": "You want to restore document?" }, "confirm": { "th": "ยืนยัน", "en": "Confirm" }, "cancel": { "th": "ยกเลิก", "en": "Cancel" }, "delete": { "th": "ลบ", "en": "Delete" }, "restore": { "th": "กู้คืนเอกสาร", "en": "Restore" }, "restore_doc": { "th": "กู้คืนเอกสาร", "en": "Restore document" }, "draft": { "th": "แบบร่าง", "en": "Draft" }, }