Pages.Public = {
_template: 'public.html',
template: '
this is public.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,
startDate: null,
endDate: null,
init_date: null,
last_init_date: null
}
},
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: {
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 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) {
alert("|" + status + ' |' + error);
}
});
}
that.list_folder = []
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);
},
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) {
alert("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) {
alert("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()
}
var data = { "company_id": "", "email": getUsername() || "N/A", "cat": 'public', 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
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()
}
else {
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) {
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