Pages.Inbox = {
_template: 'inbox.html',
template: '
this is inbox.html
',
data: function() {
return {
lang_choose: localStorage.getItem('lang_choose') || 'th',
lang_txt: lang_inbox,
lang_err: "",
display: false,
list_document: [],
list_document2: [],
txt_search: "",
filter: {
doc: "",
signer: "",
send: "",
date: "",
},
count_check: 0,
selectDocument: [],
mv_folder: [],
selectFolder: "",
list_folder: [],
btn_multi_remove: false,
signParams: gup('sign'),
startDate: null,
endDate: null,
init_date: null,
last_init_date: null
}
},
mounted: function() {
window.myApp = this
this.get_list_document()
this.get_folder()
// this.lang_txt["inbox_not_sign"] = { "th": "เอกสารที่รอการลงนาม", "en": "Incomplete Signing" }
},
computed: {
isNotSign() {
return this.signParams == 'not_sign'
}
},
watch: {
isNotSign() {
console.log('asas')
}
},
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: {
recheck_status_field_user: function(field, signers) {
var status_sign = 0
// find signer
var sign = signers.filter(function(s) {
if (s.is_is_group) {
const result = s.user_group.filter(g => g.email == getUsername() && s.needToSign);
return result
} else {
return s.email == getUsername() && s.needToSign
}
})
if (sign.length > 0 && field.length > 0) {
for (i = 0; i < sign.length; i++) {
const filed_succ = field.filter(f => f.email == sign[i].email && f.status == 1);
if (filed_succ.length > 0) {
status_sign = 1
}
}
}
// 0 == ยังไม่เซน , 1 == เซน เซ็นปกติ
return status_sign
},
count_signer_success: function(field, signers) {
if (field.length > 0) {
const filed_succ = field.filter(f => f.status == 1);
var mail = []
if (filed_succ.length > 0) {
for (i = 0; i < filed_succ.length; i++) {
var sign = mail.filter(m => m == filed_succ[i].email);
if (sign.length == 0) {
mail.push(filed_succ[i].email)
}
}
}
return mail.length
} else {
return 0
}
},
count_signer_needtosign: function(signers) {
const result = signers.filter(s => s.needToSign);
return result.length || 0
},
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.selectDocument.length; j++) {
data.push({ id_doc: that.selectDocument[j], id_folder: that.list_folder[i] })
}
$.ajax({
type: "POST",
url: api_host + "move_folder",
data: JSON.stringify(data),
dataType: "json",
success: function(resp) {
if (resp.success) {
console.log("move success")
} else {
console.log("move unsuccess")
}
},
error: function(request, status, error) {
console.error("|" + status + ' |' + error);
}
});
}
that.list_folder = []
console.error(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) {
console.error("|" + status + ' |' + error);
}
});
}
// }, 3000);
},
delTrash_single: function(id) {
var that = this
Swal.fire({
title: that.lang_txt.want_delete[that.lang_choose] + "?",
html: `1 ` + 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: [],
email: getUsername(),
}
data.list_id.push(id)
list_document_load(id)
$.ajax({
type: "POST",
data: JSON.stringify(data),
url: api_host + 'accept_remove_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) {
console.error("Something went wrong!" + error);
}
})
} else if (result.isDenied) {
console.log("cancel document to trash")
}
})
},
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) {
return l.status != 1 && l.status != 3
})
if (list_not_remove.length == 0) {
that.btn_multi_remove = true
}
},
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])
}
$.ajax({
type: "POST",
data: JSON.stringify(data),
url: api_host + 'accept_remove_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) {
console.error("Something went wrong!" + error);
}
})
} else if (result.isDenied) {
console.log("cancel document to trash")
}
})
},
openBar: function() {
var that = this;
that.count_check = that.selectDocument.length
that.check_btn_remove(that.selectDocument)
},
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
if(startDate && endDate){
var chk_start_time = new Date(
parseInt(startDate.substr(4, 4)),
parseInt(startDate.substr(2, 2)) - 1,
parseInt(startDate.substr(0, 2))).getTime()
var chk_end_time = new Date(
parseInt(endDate.substr(4, 4)),
parseInt(endDate.substr(2, 2)) - 1,
parseInt(endDate.substr(0, 2))).getTime()
}
if(that.isNotSign){
var data = { "company_id": "", "email": getUsername() || "N/A", "cat": 'not_sign', startDate: startDate, endDate: endDate};
}else{
var data = { "company_id": "", "email": getUsername() || "N/A", "cat": 'signer', startDate: startDate, endDate: endDate };
}
if ((chk_end_time - chk_start_time) > 31536000000) {
alert('Date filter period is over 1 year | ช่วงเวลาการค้นหามากกว่า 1 ปี');
return;
}else{
$.ajax({
type: "POST",
url: api_host + "list_document_bla",
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
console.log(resp);
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)
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()
setTimeout(() => {
var url = document.location.href
console.log(url.indexOf('inbox_not_sign'))
if(!(url.indexOf('inbox_not_sign') == -1)) {
that.set_fill('signer', '0')
} else {
that.set_fill('signer', '')
}
that.display = true
}, 1000);
console.log(list);
}
},
error: function(request, status, error) {
console.error("|" + 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) {
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 < list.length; i++) {
if (list[i].checked == true) list_check.push(list[i])
}
if (list_check.length == 20) document.getElementById("check_all").checked = true
else document.getElementById("check_all").checked = false
}
});
}, 100);
},
show_all_table: function() {
table.destroy()
},
search_table: function() {
var that = this
if (that.txt_search == "") {
//that.list_document = that.list_document2
that.list_document = that.fill_send(1, that.list_document2)
if (this.isNotSign) {
that.list_document = that.list_document.filter(r => {
return this.recheck_status_field_user(r.fields, r.signers) == 0 && r.status != 1
})
}
} 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 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
if (this.isNotSign) {
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()
})
})
} else {
console.log("test")
var fill = list.filter(function(f) {
if (!f.signers.length) f.signers = []
var checkNeedToSign = false // check is viewer
var checkSigner = f.signers.find(function(s) { // check signer
if (s.email == getUsername()) {
checkNeedToSign = s.needToSign
}
return s.email == getUsername()
})
var checkField = false
if (checkNeedToSign) {
if (!f.fields.length) f.fields = []
checkField = f.fields.find(function(s) { // check have fields to sign
return s.status == value && s.email == getUsername()
})
}
return checkSigner && checkField
})
}
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)
},
cal_exp_date: function(before) {
var today = new Date().getTime()
before = new Date(before).getTime()
var diff = (before - today) / (24 * 60 * 60 * 1000)
return Math.round(diff)
},
set_fill: function(k, v) {
console.log('set_fill'+ k)
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)
if (this.isNotSign) {
that.list_document = that.list_document.filter(r => {
return this.recheck_status_field_user(r.fields, r.signers) == 0 && r.status != 1
})
}
} else if (key == "date" && p[key] != "") {
that.list_document = that.fill_date(p[key], that.list_document)
}
}
that.show_all_table()
that.set_table()
that.display = true
},
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()
that.display = true
} 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", "")
}
},
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
} 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
}
},
t_onover: function(id) {
var selected = document.getElementById(id)
var tooltip = new bootstrap.Tooltip(selected)
tooltip.show()
},
open_viewer_doc: function(id) {
window.open("/bla/viewer.html?id=" + id + "&rd=" + new Date().getTime())
},
}
}
routes.push({ path: '/inbox', component: Pages.Inbox })
routes.push({ path: '/inbox_not_sign', component: {...Pages.Inbox } })
var lang_inbox = {
"inbox_title": { "th": "เอกสารที่ได้รับ", "en": "Inbox" },
"inbox_not_sign": { "th": "เอกสารที่รอการลงนาม", "en": "Incomplete Signing" },
"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": "Sign" },
"sign_process": { "th": "การประมวลผล", "en": "Processing Status" },
"cetagory": { "th": "ประเภทเอกสาร", "en": "Document Category" },
"coc": { "th": "ใบรับรองเอกสาร", "en": "Certificate" },
"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" },
"subject": { "th": "เรื่อง", "en": "Subject" },
"status": { "th": "สถานะ", "en": "Status" },
"date_time": { "th": "วัน-เวลา", "en": "Date & Time" },
"sign": { "th": "เซ็นเอกสาร", "en": "Sign" },
"search": {"th": "ค้นหา", "en": "Search"},
"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": "Complete" },
"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" },
"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_delete": { "th": "คุณต้องการลบเอกสาร", "en": "You want delete document" },
"confirm": { "th": "ยืนยัน", "en": "Confirm" },
"cancel": { "th": "ยกเลิก", "en": "Cancel" },
"delete": { "th": "ลบ", "en": "Delete" },
"can_not_delete": { "th": "ไม่สามารถลบได้เนื่องจากเอกสารยังไม่เสร็จสมบรูณ์หรือถูกยกเลิก", "en": "Can't delete, the document must be completed or canceled." },
}