Pages.Draft = { _template: 'draft.html', template: '
this is draft.html
', data: function () { return { display: false, list_document: [], list_document2: [], txt_search: "", filter: { doc: "", signer: "", send: "", date: "", }, count_check: 0, selectDocument: [], mv_folder: [], selectFolder: "", lang_choose: localStorage.getItem('lang_choose') || 'th', lang_txt: lang_draft, table_loading : false, btn_multi_remove: true, lang_err: "", startDate: null, endDate: null, init_date: null, last_init_date: null } }, Year(){ value = day + "/" + month + "/" + year return value || "" }, 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_folder: function (id_doc, id_folder) { var that = this var data = [] var alert_move = "" var alert_move_success = "" var aler_selecFol = "" if (this.lang_choose == 'th') { alert_move = "ต้องการย้ายเอกสารหรือไม่" alert_move_success = "ย้ายเอกสารเรียบร้อย" aler_selecFol = "กรุณาเลือกแฟ้มเอกสาร" } else { alert_move = "Do you want to move document?" alert_move_success = "Move document success" aler_selecFol = "Please select folder" } if (that.selectFolder.length > 0) { var conf = confirm(alert_move) if (conf == true) { for (j = 0; j < that.selectDocument.length; j++) { data.push({ id_doc: that.selectDocument[j], id_folder: that.selectFolder }) } $.ajax({ type: "POST", url: api_host + "move_folder", data: JSON.stringify(data), dataType: "json", success: function (res) { alert('ย้ายสำเร็จ') document.location.reload() }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); } } else { alert(aler_selecFol) } console.log(data) }, 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); }, remove_draft: function (id) { var that = this Swal.fire({ title: that.lang_txt.want_delete[that.lang_choose] + "?", html: that.lang_txt.noti_trash[that.lang_choose], icon: 'warning', 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 + "remove_draft_bla", data: JSON.stringify(data), dataType: "json", success: function (resp) { if (resp.success) { that.show_all_table() setTimeout(that.get_list_document(), 1500); } else { } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); } else if (result.isDenied) { console.log("cancel remove draft") } }) }, check_all: function (s) { var that = this var all = document.getElementById("check_all") var list = document.getElementsByClassName("checkfile") if (all.checked) { for (i = 0; i < list.length; i++) { list[i].checked = all.checked that.selectDocument.push(list[i].value) } var uniqueChars = [...new Set(that.selectDocument)]; that.selectDocument = uniqueChars // that.check_btn_remove(that.selectDocument) that.count_check = that.selectDocument.length console.log(that.count_check) } else { var list_select = [] for (i = 0; i < list.length; i++) { var select = that.selectDocument.find(function (s) { return list[i].value == s }) if (select) list_select.push(select) list[i].checked = all.checked } var remove_select = that.selectDocument.filter(function (s) { return list_select.indexOf(s) == -1; }); that.selectDocument = remove_select that.count_check = that.selectDocument.length // that.btn_multi_remove = false } }, openBar: function () { var that = this; that.count_check = that.selectDocument.length }, delTrash_multi: function () { var that = this Swal.fire({ title: that.lang_txt.want_delete[that.lang_choose] + "?", html: `` + that.selectDocument.length + " " + that.lang_txt.doc_list[that.lang_choose] + `
` + that.lang_txt.noti_trash[that.lang_choose], icon: 'warning', 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", } for (i = 0; i < data.list_id.length; i++) { list_document_load(data.list_id[i]) } console.log(data) $.ajax({ type: "POST", data: JSON.stringify(data), url: api_host + 'remove_multi_draft_bla', 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) { console.error("Something went wrong!" + error); } }) } else if (result.isDenied) { console.log("cancel document to trash") } }) }, get_date: function(){ that = this if(that.init_date == null && that.last_init_date == null){ const init_date = new Date() const cal_year = init_date.getFullYear() const cal_month = init_date.getMonth() + 1 const days_in_month = new Date(cal_year, cal_month, 0).getDate() const last_init_date = new Date(init_date.getTime() - days_in_month * 24 * 60 * 60 * 1000) const s_ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(init_date) const s_mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(init_date) const s_da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(init_date) const l_ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(last_init_date) const l_mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(last_init_date) const l_da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(last_init_date) this.endDate = `${s_ye}-${s_mo}-${s_da}` this.startDate = `${l_ye}-${l_mo}-${l_da}` this.init_date = `${s_da}/${s_mo}/${s_ye}` this.last_init_date = `${l_da}/${l_mo}/${l_ye}` console.log('not have rc') }else{ const init_date = that.init_date const last_init_date = that. last_init_date const s_ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(init_date) const s_mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(init_date) const s_da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(init_date) const l_ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(last_init_date) const l_mo = new Intl.DateTimeFormat('en', { month: '2-digit' }).format(last_init_date) const l_da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(last_init_date) this.endDate = `${s_ye}-${s_mo}-${s_da}` this.startDate = `${l_ye}-${l_mo}-${l_da}` this.init_date = `${s_da}/${s_mo}/${s_ye}` this.last_init_date = `${l_da}/${l_mo}/${l_ye}` console.log('have rc') } }, format_date: function (e) { value = e.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 e.setAttribute( "data-date-format", value) }, replaceString: function(str){ console.log(str.replace(/(\d{4})-(\d{2})-(\d{2})/g, '$3$2$1')) return str.replace(/(\d{4})-(\d{2})-(\d{2})/g, '$3$2$1'); }, get_list_document: function (startDate, endDate) { var that = this var data = { "email": getUsername() || "N/A", startDate: startDate, endDate: endDate }; $.ajax({ type: "POST", url: api_host + "list_document_draft", data: JSON.stringify(data), dataType: "json", success: function (resp) { if (resp.success) { that.init_date = resp.endDate that.last_init_date = resp.startDate that.get_date() if (!resp.data.length) resp.data = [] var list = resp.data if (list.length > 0) { list.sort(function (a, b) { return b.createdDtm - a.createdDtm }) that.list_document = list that.list_document2 = list that.set_table() } else { that.list_document = list that.list_document2 = list that.set_table() } } }, error: function (request, status, error) { alert("|" + status + ' |' + error); } }); }, 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) { console.log(id) document.location.href = "/bla/upload_new.html?id=" + id }, set_table: function () { var that = this if(that.table_loading == true){ return } that.table_loading = true; 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_", } }); that.table_loading = false; }, 100); that.display = true }, show_all_table: function () { table.destroy() }, search_table: function () { var that = this if (that.txt_search == "") { that.list_document = that.list_document2 } else if (event.keyCode == "8" || event.keyCode == "46") { that.list_document = that.list_document2 var list = that.list_document if (list.length == 0) return false var search = list.filter(function (s) { var subject = s.subject.search(that.txt_search) != -1 var owner = s.owner.search(that.txt_search) != -1 var signers = s.signers.find(function (sig) { return sig.email.search(that.txt_search) != -1 }) var list = subject || owner || signers return list }) that.list_document = search } else { var list = that.list_document if (list.length == 0) return false var search = list.filter(function (s) { var subject = s.subject.search(that.txt_search) != -1 var owner = s.owner.search(that.txt_search) != -1 var signers = s.signers.find(function (sig) { return sig.email.search(that.txt_search) != -1 }) var list = subject || owner || signers return list }) that.list_document = search } }, fill_doc: function (value, arr) { if (value == "") return false var that = this var list = arr var fill = list.filter(function (f) { if(!f.status) f.status = 0 return f.status == value }) return fill }, fill_sign: function (value, arr) { if (value == "") return false var that = this var list = arr var fill = list.filter(function (f) { if (!f.fields.length) f.fields = [] return f.fields.find(function (s) { return s.status == value && s.email == getUsername() && that.not_field(s.toolName) }) }) return fill }, not_field(field) { var not = ["Qrcode", "secretly_1", "secretly_2", "secretly_3", "urgent_1", "urgent_2", "urgent_3", "company"] var chk = (not.find(function (n) { return n == field })) return chk }, fill_send: function (value, arr) { if (value == "") return false var that = this var list = arr var fill = [] var email = getUsername() || "N/A" that.filter.send = value if (value == "0") { fill = list.filter(function (f) { return f.owner == email }) } else if (value == "1") { fill = list.filter(function (f) { return f.owner != email }) } return fill }, fill_date: function (value, arr) { if (value == "") return false var that = this var list = arr var maxDate = Number(value) var fill = list.filter(function (f) { return f.diff_date <= maxDate }) return fill }, cal_date: function (before) { var today = new Date().getTime() var diff = (today - before) / (24 * 60 * 60 * 1000) return Math.round(diff) }, set_fill: function (k, v) { var that = this var p = that.filter if (p[k] != "" || v == "") that.list_document = that.list_document2 p[k] = v for (var key in p) { if (key == "doc" && p[key] != "") { that.list_document = that.fill_doc(p[key], that.list_document) } else if (key == "signer" && p[key] != "") { that.list_document = that.fill_sign(p[key], that.list_document) } else if (key == "send" && p[key] != "") { that.list_document = that.fill_send(p[key], that.list_document) } else if (key == "date" && p[key] != "") { that.list_document = that.fill_date(p[key], that.list_document) } } that.show_all_table() that.set_table() }, clear_filter: function (value) { var that = this if (value == "all") { that.list_document = that.list_document2 that.filter = { doc: "", signer: "", send: "", date: "" } that.show_all_table() that.set_table() } else if (value == "doc") { that.filter.doc = "" that.set_fill("doc", "") } else if (value == "signer") { that.filter.signer = "" that.set_fill("signer", "") } else if (value == "send") { that.filter.send = "" that.set_fill("send", "") } else if (value == "date") { that.filter.date = "" that.set_fill("date", "") } }, t_onover: function(id) { var selected = document.getElementById(id) var tooltip = new bootstrap.Tooltip(selected) tooltip.show() }, get_signer_str_list: function(list_signers) { console.log() return list_signers.map(e => e.email).join(", ") }, } } routes.push({ path: '/draft', component: Pages.Draft }) var lang_draft = { "title": { "th": "เอกสารร่าง", "en": "Draft Document" }, "adv_search": { "th": "ค้นหาขั้นสูง", "en": "Advanced search" }, "clear": { "th": "ล้าง", "en": "Clear" }, "des_search": { "th": "ชื่อเอกสาร, ผู้รับ, อีเมล", "en": "Subject, 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" }, "startdate": {"th": "วันเริ่มต้น : ", "en": "Start Date : "}, "enddate": {"th": "ถึงวันที่ : ", "en": "End Date : "}, "me": { "th": "ฉัน", "en": "Me" }, "notme": { "th": "ไม่ใช่ฉัน", "en": "Not me" }, "date": { "th": "วันที่", "en": "Date" }, "search": {"th": "ค้นหา", "en": "Search"}, "subject": { "th": "เรื่อง", "en": "Subject" }, "status": { "th": "สถานะ", "en": "Status" }, "date_time": { "th": "วัน-เวลา", "en": "Date & Time" }, "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" }, "delete": { "th": "ลบ", "en": "Delete" }, "draft": { "th": "แบบร่าง", "en": "Draft" }, "continue": { "th": "ทำต่อ", "en": "Continue" }, "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" }, // "noti_trash": { "th": `เอกสารร่างที่ถูกลบจะไม่สามารถกู้คืนได้`, "en": `Draft documents can not be restore.` }, "noti_trash": { "th": `คุณสามารถค้นหาเอกสารที่ถูกลบทั้งหมดได้ใน "ถังขยะ"`, "en": `You can find all deleted documents in “Trash”.` }, "doc_list": { "th": "รายการ", "en": "Document" }, "want_delete": { "th": "คุณต้องการลบเอกสาร", "en": "You want to delete document" }, "confirm": { "th": "ยืนยัน", "en": "Confirm" }, "cancel": { "th": "ยกเลิก", "en": "Cancel" }, "delete": { "th": "ลบ", "en": "Delete" }, "reciever": { "th": "ผู้รับ", "en": "Reciever" }, // "can_not_delete": { "th": "ไม่สามารถลบได้เนื่องจากเอกสารยังไม่เสร็จสมบรูณ์หรือถูกยกเลิก", "en": "Can't delete, the document must be completed or canceled." }, }