zet-lib 1.3.39 → 1.3.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +15 -15
- package/lib/ErrorWithCode.js +6 -6
- package/lib/Form.js +1020 -1019
- package/lib/Mail.js +68 -68
- package/lib/Modal.js +95 -95
- package/lib/Pool.js +437 -437
- package/lib/UI.js +7 -7
- package/lib/Util.js +1384 -1384
- package/lib/access.js +6 -6
- package/lib/cache.js +3 -3
- package/lib/connection.js +409 -409
- package/lib/debug.js +22 -22
- package/lib/index.js +36 -36
- package/lib/io.js +44 -44
- package/lib/languages/lang_en.js +125 -125
- package/lib/languages/lang_fr.js +125 -125
- package/lib/languages/lang_id.js +126 -126
- package/lib/languages/lang_jp.js +125 -125
- package/lib/moduleLib.js +661 -661
- package/lib/tableForm.js +10 -10
- package/lib/views/generator.ejs +598 -598
- package/lib/views/generator_layout.ejs +224 -224
- package/lib/views/generatorjs.ejs +927 -927
- package/lib/zAppRouter.js +1637 -1637
- package/lib/zCache.js +301 -301
- package/lib/zComponent.js +27 -27
- package/lib/zFn.js +58 -58
- package/lib/zFunction.js +20 -20
- package/lib/zGeneratorRouter.js +1641 -1641
- package/lib/zMenuRouter.js +556 -556
- package/lib/zPage.js +188 -188
- package/lib/zReport.js +982 -982
- package/lib/zRole.js +256 -256
- package/lib/zRoleRouter.js +609 -609
- package/lib/zRoute.js +5025 -5024
- package/lib/zTester.js +93 -93
- package/lib/zapp.js +65 -65
- package/lib/zdataTable.js +330 -330
- package/package.json +56 -56
package/lib/zdataTable.js
CHANGED
|
@@ -1,330 +1,330 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by sintret dev on 1/6/2022.
|
|
3
|
-
*/
|
|
4
|
-
const Util = require('./Util')
|
|
5
|
-
const myCache = require('./cache')
|
|
6
|
-
|
|
7
|
-
class dataTable {
|
|
8
|
-
constructor(datas) {
|
|
9
|
-
//console.log(datas)
|
|
10
|
-
this.visibles = datas.visiblesObj //array object
|
|
11
|
-
this.setColumns = ''
|
|
12
|
-
this.setTable = ''
|
|
13
|
-
this.srcScript = '/modules/datatable/datatables.min.js'
|
|
14
|
-
this.dataTableButtons = '/js/datatable-buttons.js'
|
|
15
|
-
this.customButtons = ''
|
|
16
|
-
this.MYMODEL = null
|
|
17
|
-
this.searchColumns = {}
|
|
18
|
-
this.relations
|
|
19
|
-
this.routeName
|
|
20
|
-
this.types = {}
|
|
21
|
-
this.roles = myCache.get('ROLES')[datas.zuser.role_id] || {}
|
|
22
|
-
this.level_approval = this.roles.approvals && this.roles.approvals[datas.routeName] ? this.roles.approvals[datas.routeName] : {}
|
|
23
|
-
this.hasLevels = Object.keys(this.level_approval).length == 0 ? false : true
|
|
24
|
-
this.visiblesKey = this.visibles.map((item) => item.key)
|
|
25
|
-
this.gridType = datas.gridType || 1
|
|
26
|
-
this.additionalCss = ''
|
|
27
|
-
if (this.gridType == 1) {
|
|
28
|
-
this.dataTableScript = '/modules/datatable/normal.js'
|
|
29
|
-
} else if (this.gridType == 2) {
|
|
30
|
-
this.dataTableScript = '/modules/datatable/fixed-header.js'
|
|
31
|
-
} else if (this.gridType == 3) {
|
|
32
|
-
this.dataTableScript = '/modules/datatable/footer-total.js'
|
|
33
|
-
} else if (this.gridType == 4) {
|
|
34
|
-
this.dataTableScript = '/modules/datatable/normal.js'
|
|
35
|
-
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
36
|
-
} else if (this.gridType == 5) {
|
|
37
|
-
this.dataTableScript = '/modules/datatable/fixed-header.js'
|
|
38
|
-
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
39
|
-
} else if (this.gridType == 6) {
|
|
40
|
-
this.dataTableScript = '/modules/datatable/footer-total.js'
|
|
41
|
-
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
42
|
-
} else if (this.gridType == 7) {
|
|
43
|
-
this.dataTableScript = '/modules/datatable/fixed-header-totalnowrap.js'
|
|
44
|
-
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
45
|
-
} else {
|
|
46
|
-
this.dataTableScript = '/modules/datatable/normal.js'
|
|
47
|
-
}
|
|
48
|
-
this.totalFields = []
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// for filter html
|
|
52
|
-
set filterMODEL(obj) {
|
|
53
|
-
this.MYMODEL = obj.MYMODEL
|
|
54
|
-
this.relations = obj.relations
|
|
55
|
-
this.routeName = this.MYMODEL.routeName
|
|
56
|
-
this.types = obj.TYPES
|
|
57
|
-
this.totalFields = this.visiblesKey.filter((item) => this.MYMODEL.widgets[item] && this.MYMODEL.widgets[item].name == 'number')
|
|
58
|
-
delete obj.MYMODEL
|
|
59
|
-
delete obj.relations
|
|
60
|
-
delete obj.TYPES
|
|
61
|
-
this.searchColumns = obj
|
|
62
|
-
}
|
|
63
|
-
set buttons(html) {
|
|
64
|
-
return html
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
set buttons2(html) {
|
|
68
|
-
return html
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get columns() {
|
|
72
|
-
if (this.setColumns) return this.setColumns
|
|
73
|
-
let html = ''
|
|
74
|
-
if (Array.isArray(this.visibles)) {
|
|
75
|
-
this.visibles.map((item) => {
|
|
76
|
-
html += `<th id="data_${item.key}_label">${item.name || ''}</th>`
|
|
77
|
-
})
|
|
78
|
-
} else {
|
|
79
|
-
for (const key in this.visibles) {
|
|
80
|
-
html += `<th id="data_${key}_label">${this.visibles[key]}</th>`
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return html
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
get columnsFilter() {
|
|
88
|
-
let html = '<tr class="filters">'
|
|
89
|
-
if (Array.isArray(this.visibles)) {
|
|
90
|
-
this.visibles.map((item) => {
|
|
91
|
-
html += `<th id="data_${item.key}_label">${this.searchColumns[item.key]}</th>`
|
|
92
|
-
})
|
|
93
|
-
} else {
|
|
94
|
-
for (const key in this.visibles) {
|
|
95
|
-
html += `<th id="data_${key}">${this.searchColumns[key]}</th>`
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
html += '</tr>'
|
|
99
|
-
return html
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/*
|
|
103
|
-
Create table html header
|
|
104
|
-
*/
|
|
105
|
-
get table() {
|
|
106
|
-
if (this.setTable) return this.setTable
|
|
107
|
-
return `<table id="dataTable" class="display table table-hover table-responsive" style="width:100%">
|
|
108
|
-
<thead>${this.columns} ${this.columnsFilter}</thead>
|
|
109
|
-
</table>`
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
get buttons() {
|
|
113
|
-
let html = this.additionalCss
|
|
114
|
-
html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
115
|
-
if (this.levels.create) {
|
|
116
|
-
html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"> ${LANGUAGE.create}</button>`
|
|
117
|
-
}
|
|
118
|
-
if (this.levels.import) {
|
|
119
|
-
html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`
|
|
120
|
-
}
|
|
121
|
-
if (this.levels.lock) {
|
|
122
|
-
html += `<button title="Lock/Unlock" style="background-color: #332D2D; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/cloud-lock.svg" class="icons-bg-white"> Lock/Unlock</span></span></button>`
|
|
123
|
-
}
|
|
124
|
-
if (this.hasLevels) {
|
|
125
|
-
html += `<button title="Approval" style="background-color: #E4A11B; color:white" class="btn buttons-html5 boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-approval" type="button"><img src="/assets/icons/rubber-stamp.svg" class="icons-bg-white"> Approval</span></span></button>`
|
|
126
|
-
}
|
|
127
|
-
html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`
|
|
128
|
-
html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
|
|
129
|
-
if (this.levels.export) {
|
|
130
|
-
html += `<div class="btn-group" role="group">
|
|
131
|
-
<button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
132
|
-
<img src="/assets/icons/download.svg" class="icons-bg-black"> ${LANGUAGE.download}
|
|
133
|
-
</button>
|
|
134
|
-
<div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`
|
|
135
|
-
html += `<a class="dropdown-header">Excel</a>`
|
|
136
|
-
html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`
|
|
137
|
-
html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`
|
|
138
|
-
html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`
|
|
139
|
-
html += `<hr>`
|
|
140
|
-
html += `<a class="dropdown-header">PDF</a>`
|
|
141
|
-
html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`
|
|
142
|
-
html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`
|
|
143
|
-
html += `</div>`
|
|
144
|
-
}
|
|
145
|
-
html += `</div></div>`
|
|
146
|
-
return html
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
get buttons2() {
|
|
150
|
-
let html = this.additionalCss
|
|
151
|
-
html += `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
152
|
-
if (this.levels.create) {
|
|
153
|
-
html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"></button>`
|
|
154
|
-
}
|
|
155
|
-
if (this.levels.import) {
|
|
156
|
-
html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> </span></span></button>`
|
|
157
|
-
}
|
|
158
|
-
if (this.levels.lock) {
|
|
159
|
-
html += `<button title="Lock/Unlock" style="background-color: #E4A11B; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/lock-check.svg" class="icons-bg-white"> </span></span></button>`
|
|
160
|
-
}
|
|
161
|
-
if (this.levels.delete_all) {
|
|
162
|
-
html += `<button title="Delete selected data" style="background-color: #DC4C64; color:white" class="btn btn-danger buttons-lock buttons-html5 copy griddeleteall boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-delete-all" type="button"><img src="/assets/icons/http-delete.svg" class="icons-bg-white"> </span></span></button>`
|
|
163
|
-
}
|
|
164
|
-
if (this.hasLevels) {
|
|
165
|
-
html += `<button title="Approval" style="background-color: #E4A11B; color:white" class="btn buttons-html5 boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-approval" type="button"><img src="/assets/icons/rubber-stamp.svg" class="icons-bg-white"> </span></span></button>`
|
|
166
|
-
}
|
|
167
|
-
html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"></button>`
|
|
168
|
-
html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
|
|
169
|
-
if (this.levels.export) {
|
|
170
|
-
html += `<div class="btn-group" role="group">
|
|
171
|
-
<button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
172
|
-
<img src="/assets/icons/download.svg" class="icons-bg-black">
|
|
173
|
-
</button>
|
|
174
|
-
<div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`
|
|
175
|
-
html += `<a class="dropdown-header">Excel</a>`
|
|
176
|
-
html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`
|
|
177
|
-
html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`
|
|
178
|
-
html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`
|
|
179
|
-
html += `<hr>`
|
|
180
|
-
html += `<a class="dropdown-header">PDF</a>`
|
|
181
|
-
html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`
|
|
182
|
-
html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`
|
|
183
|
-
html += `</div>`
|
|
184
|
-
}
|
|
185
|
-
html += `</div></div>`
|
|
186
|
-
return html
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
get scripts() {
|
|
190
|
-
let script = `<script type="text/javascript" src="${this.srcScript}"></script>`
|
|
191
|
-
script += `<script>${Util.newLine}`
|
|
192
|
-
script += `var dataTableFields = ${JSON.stringify(this.visiblesKey, null, 2)};${Util.newLine}`
|
|
193
|
-
script += `var dataTableTypes = ${JSON.stringify(this.types, null, 2)};${Util.newLine}`
|
|
194
|
-
script += `var dataTableRoute = "${this.routeName}";${Util.newLine}`
|
|
195
|
-
script += `var dataTableHasTotalFields = ${JSON.stringify(this.totalFields)};${Util.newLine}`
|
|
196
|
-
script += `</script>${Util.newLine}`
|
|
197
|
-
script += `<script type="text/javascript" src="${this.dataTableScript}"></script>${Util.newLine}`
|
|
198
|
-
if (this.searchColumns.FILTERKEY) {
|
|
199
|
-
script += `<script>$(function () { setTimeout(function () { ${this.searchColumns.FILTERKEY} },500) });</script>${Util.newLine}`
|
|
200
|
-
}
|
|
201
|
-
script += `<script type="text/javascript" src="${this.dataTableButtons}"></script>${Util.newLine}`
|
|
202
|
-
|
|
203
|
-
//additional script for typeahead in grid
|
|
204
|
-
let typeaheadScript = ''
|
|
205
|
-
for (let key in this.MYMODEL.widgets) {
|
|
206
|
-
if (this.MYMODEL.widgets[key].name == 'typeahead') {
|
|
207
|
-
typeaheadScript += `if($("#${key}").val()){
|
|
208
|
-
setTimeout(()=>{
|
|
209
|
-
ajaxPost('/ztypeaheadpost/${this.MYMODEL.table}/${key}', {
|
|
210
|
-
id: $("#${key}").val()
|
|
211
|
-
}, function(data) {
|
|
212
|
-
$("#${key}Typeahead").val(data);$("#${key}Typeahead").change();
|
|
213
|
-
$("#${key}").change();
|
|
214
|
-
$("#data_table_${key}").change();
|
|
215
|
-
|
|
216
|
-
})
|
|
217
|
-
},1500)
|
|
218
|
-
};
|
|
219
|
-
`
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (typeaheadScript) {
|
|
223
|
-
script += `<script type="text/javascript">$(function () {${typeaheadScript}})</script>${Util.newLine}`
|
|
224
|
-
}
|
|
225
|
-
if (this.hasLevels) {
|
|
226
|
-
//modal-body-approval
|
|
227
|
-
let APPROVAL_LEVELS = myCache.get('APPROVAL_LEVELS')
|
|
228
|
-
let approvalButtonHtml = ``
|
|
229
|
-
for (let item in this.level_approval) {
|
|
230
|
-
let imageapproval = 'brand-bunpo'
|
|
231
|
-
if (item == 22) {
|
|
232
|
-
imageapproval = 'rubber-stamp-off'
|
|
233
|
-
} else if (item == 2) {
|
|
234
|
-
imageapproval = 'list-check'
|
|
235
|
-
} else if (item == 21) {
|
|
236
|
-
imageapproval = 'rubber-stamp'
|
|
237
|
-
}
|
|
238
|
-
let name = APPROVAL_LEVELS.hasOwnProperty(item) ? APPROVAL_LEVELS[item].name : ''
|
|
239
|
-
let color = APPROVAL_LEVELS.hasOwnProperty(item) ? APPROVAL_LEVELS[item].color : ''
|
|
240
|
-
approvalButtonHtml += ` <button title="${name}" data-value="${item}" style="background-color: ${color}; color:white" class="btn btn-approval-levels boxy-small dimens2x image-button mb-3" type="button"><img src="/assets/icons/${imageapproval}.svg" class="icons-bg-white"> ${name}</button> `
|
|
241
|
-
}
|
|
242
|
-
approvalButtonHtml += `<div class="row"><div class="col-md-10"><textarea class="form-control boxy purple-border" id="zapproval_message" placeholder="tulis alasan..." rows="2"></textarea></div><div class="col-md-1"></div></div>`
|
|
243
|
-
|
|
244
|
-
script += `<script type="text/javascript">$(function () {
|
|
245
|
-
$(".modal-body-approval").html('${approvalButtonHtml}');
|
|
246
|
-
$(".btn-approval-levels").on("click", function () {
|
|
247
|
-
ajaxPost('/zapproval-update/${this.MYMODEL.table}', {
|
|
248
|
-
text : $("#zapproval_message").val(),
|
|
249
|
-
value : $(this).attr('data-value'),
|
|
250
|
-
datas: $(".ck").serializeArray()
|
|
251
|
-
}, function (data) {
|
|
252
|
-
toastrForm(data);
|
|
253
|
-
if(data.status == 1) {
|
|
254
|
-
if(data.dataStatus.length > 0) {
|
|
255
|
-
data.dataStatus.map((item) => {
|
|
256
|
-
toastr.error(item);
|
|
257
|
-
});
|
|
258
|
-
setTimeout(function() {
|
|
259
|
-
if(data.status ==1) {
|
|
260
|
-
location.href='';
|
|
261
|
-
}
|
|
262
|
-
},4000);
|
|
263
|
-
} else {
|
|
264
|
-
if(data.status ==1) {
|
|
265
|
-
location.href='';
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
})
|
|
270
|
-
})
|
|
271
|
-
})</script>${Util.newLine}`
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
script += `<script type="text/javascript">
|
|
275
|
-
$(function () {
|
|
276
|
-
$("#ck_all").on('click', function () {
|
|
277
|
-
if($(this).is(':checked')) {
|
|
278
|
-
$(".ck").prop('checked',true)
|
|
279
|
-
} else {
|
|
280
|
-
$(".ck").prop('checked',false)
|
|
281
|
-
}
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
$(".btn-save-lock").on("click", function () {
|
|
285
|
-
ajaxPost('/zlock-unlock/${this.MYMODEL.table}', {
|
|
286
|
-
type : 1,
|
|
287
|
-
datas: $(".ck").serializeArray()
|
|
288
|
-
}, function (data) {
|
|
289
|
-
toastrForm(data);
|
|
290
|
-
if(data.status ==1) {
|
|
291
|
-
location.href='';
|
|
292
|
-
}
|
|
293
|
-
})
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
$(".btn-save-unlock").on("click", function () {
|
|
297
|
-
ajaxPost('/zlock-unlock/${this.MYMODEL.table}', {
|
|
298
|
-
type : 0,
|
|
299
|
-
datas: $(".ck").serializeArray()
|
|
300
|
-
}, function (data) {
|
|
301
|
-
toastrForm(data);
|
|
302
|
-
if(data.status ==1) {
|
|
303
|
-
location.href='';
|
|
304
|
-
}
|
|
305
|
-
})
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
$(".btn-save-delete-selected").on("click", function () {
|
|
309
|
-
if(window.confirm("sure to delete selected data ?")) {
|
|
310
|
-
ajaxPost('/zdeleted-selected/${this.MYMODEL.table}', {
|
|
311
|
-
type : 1,
|
|
312
|
-
datas: $(".ck").serializeArray()
|
|
313
|
-
}, function (data) {
|
|
314
|
-
toastrForm(data);
|
|
315
|
-
if(data.status ==1) {
|
|
316
|
-
location.href='';
|
|
317
|
-
}
|
|
318
|
-
})
|
|
319
|
-
}
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
$("#zgrid_default_type").val(${this.gridType});
|
|
323
|
-
|
|
324
|
-
})</script>${Util.newLine}`
|
|
325
|
-
|
|
326
|
-
return script
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
module.exports = dataTable
|
|
1
|
+
/**
|
|
2
|
+
* Created by sintret dev on 1/6/2022.
|
|
3
|
+
*/
|
|
4
|
+
const Util = require('./Util')
|
|
5
|
+
const myCache = require('./cache')
|
|
6
|
+
|
|
7
|
+
class dataTable {
|
|
8
|
+
constructor(datas) {
|
|
9
|
+
//console.log(datas)
|
|
10
|
+
this.visibles = datas.visiblesObj //array object
|
|
11
|
+
this.setColumns = ''
|
|
12
|
+
this.setTable = ''
|
|
13
|
+
this.srcScript = '/modules/datatable/datatables.min.js'
|
|
14
|
+
this.dataTableButtons = '/js/datatable-buttons.js'
|
|
15
|
+
this.customButtons = ''
|
|
16
|
+
this.MYMODEL = null
|
|
17
|
+
this.searchColumns = {}
|
|
18
|
+
this.relations
|
|
19
|
+
this.routeName
|
|
20
|
+
this.types = {}
|
|
21
|
+
this.roles = myCache.get('ROLES')[datas.zuser.role_id] || {}
|
|
22
|
+
this.level_approval = this.roles.approvals && this.roles.approvals[datas.routeName] ? this.roles.approvals[datas.routeName] : {}
|
|
23
|
+
this.hasLevels = Object.keys(this.level_approval).length == 0 ? false : true
|
|
24
|
+
this.visiblesKey = this.visibles.map((item) => item.key)
|
|
25
|
+
this.gridType = datas.gridType || 1
|
|
26
|
+
this.additionalCss = ''
|
|
27
|
+
if (this.gridType == 1) {
|
|
28
|
+
this.dataTableScript = '/modules/datatable/normal.js'
|
|
29
|
+
} else if (this.gridType == 2) {
|
|
30
|
+
this.dataTableScript = '/modules/datatable/fixed-header.js'
|
|
31
|
+
} else if (this.gridType == 3) {
|
|
32
|
+
this.dataTableScript = '/modules/datatable/footer-total.js'
|
|
33
|
+
} else if (this.gridType == 4) {
|
|
34
|
+
this.dataTableScript = '/modules/datatable/normal.js'
|
|
35
|
+
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
36
|
+
} else if (this.gridType == 5) {
|
|
37
|
+
this.dataTableScript = '/modules/datatable/fixed-header.js'
|
|
38
|
+
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
39
|
+
} else if (this.gridType == 6) {
|
|
40
|
+
this.dataTableScript = '/modules/datatable/footer-total.js'
|
|
41
|
+
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
42
|
+
} else if (this.gridType == 7) {
|
|
43
|
+
this.dataTableScript = '/modules/datatable/fixed-header-totalnowrap.js'
|
|
44
|
+
this.additionalCss = `<style>thead > tr > th {white-space: nowrap;}</style>`
|
|
45
|
+
} else {
|
|
46
|
+
this.dataTableScript = '/modules/datatable/normal.js'
|
|
47
|
+
}
|
|
48
|
+
this.totalFields = []
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// for filter html
|
|
52
|
+
set filterMODEL(obj) {
|
|
53
|
+
this.MYMODEL = obj.MYMODEL
|
|
54
|
+
this.relations = obj.relations
|
|
55
|
+
this.routeName = this.MYMODEL.routeName
|
|
56
|
+
this.types = obj.TYPES
|
|
57
|
+
this.totalFields = this.visiblesKey.filter((item) => this.MYMODEL.widgets[item] && this.MYMODEL.widgets[item].name == 'number')
|
|
58
|
+
delete obj.MYMODEL
|
|
59
|
+
delete obj.relations
|
|
60
|
+
delete obj.TYPES
|
|
61
|
+
this.searchColumns = obj
|
|
62
|
+
}
|
|
63
|
+
set buttons(html) {
|
|
64
|
+
return html
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set buttons2(html) {
|
|
68
|
+
return html
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get columns() {
|
|
72
|
+
if (this.setColumns) return this.setColumns
|
|
73
|
+
let html = ''
|
|
74
|
+
if (Array.isArray(this.visibles)) {
|
|
75
|
+
this.visibles.map((item) => {
|
|
76
|
+
html += `<th id="data_${item.key}_label">${item.name || ''}</th>`
|
|
77
|
+
})
|
|
78
|
+
} else {
|
|
79
|
+
for (const key in this.visibles) {
|
|
80
|
+
html += `<th id="data_${key}_label">${this.visibles[key]}</th>`
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return html
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get columnsFilter() {
|
|
88
|
+
let html = '<tr class="filters">'
|
|
89
|
+
if (Array.isArray(this.visibles)) {
|
|
90
|
+
this.visibles.map((item) => {
|
|
91
|
+
html += `<th id="data_${item.key}_label">${this.searchColumns[item.key]}</th>`
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
for (const key in this.visibles) {
|
|
95
|
+
html += `<th id="data_${key}">${this.searchColumns[key]}</th>`
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
html += '</tr>'
|
|
99
|
+
return html
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
Create table html header
|
|
104
|
+
*/
|
|
105
|
+
get table() {
|
|
106
|
+
if (this.setTable) return this.setTable
|
|
107
|
+
return `<table id="dataTable" class="display table table-hover table-responsive" style="width:100%">
|
|
108
|
+
<thead>${this.columns} ${this.columnsFilter}</thead>
|
|
109
|
+
</table>`
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get buttons() {
|
|
113
|
+
let html = this.additionalCss
|
|
114
|
+
html = `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
115
|
+
if (this.levels.create) {
|
|
116
|
+
html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"> ${LANGUAGE.create}</button>`
|
|
117
|
+
}
|
|
118
|
+
if (this.levels.import) {
|
|
119
|
+
html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> ${LANGUAGE.import}</span></span></button>`
|
|
120
|
+
}
|
|
121
|
+
if (this.levels.lock) {
|
|
122
|
+
html += `<button title="Lock/Unlock" style="background-color: #332D2D; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/cloud-lock.svg" class="icons-bg-white"> Lock/Unlock</span></span></button>`
|
|
123
|
+
}
|
|
124
|
+
if (this.hasLevels) {
|
|
125
|
+
html += `<button title="Approval" style="background-color: #E4A11B; color:white" class="btn buttons-html5 boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-approval" type="button"><img src="/assets/icons/rubber-stamp.svg" class="icons-bg-white"> Approval</span></span></button>`
|
|
126
|
+
}
|
|
127
|
+
html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"> ${LANGUAGE.settings}</button>`
|
|
128
|
+
html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
|
|
129
|
+
if (this.levels.export) {
|
|
130
|
+
html += `<div class="btn-group" role="group">
|
|
131
|
+
<button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
132
|
+
<img src="/assets/icons/download.svg" class="icons-bg-black"> ${LANGUAGE.download}
|
|
133
|
+
</button>
|
|
134
|
+
<div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`
|
|
135
|
+
html += `<a class="dropdown-header">Excel</a>`
|
|
136
|
+
html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`
|
|
137
|
+
html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`
|
|
138
|
+
html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`
|
|
139
|
+
html += `<hr>`
|
|
140
|
+
html += `<a class="dropdown-header">PDF</a>`
|
|
141
|
+
html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`
|
|
142
|
+
html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`
|
|
143
|
+
html += `</div>`
|
|
144
|
+
}
|
|
145
|
+
html += `</div></div>`
|
|
146
|
+
return html
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get buttons2() {
|
|
150
|
+
let html = this.additionalCss
|
|
151
|
+
html += `<div class="dataTables_wrapper dt-bootstrap5 no-footer "><div class="dt-buttons btn-group flex-wrap">`
|
|
152
|
+
if (this.levels.create) {
|
|
153
|
+
html += `<button title="${LANGUAGE.create_info}" class="btn create gridadd image-button boxy-small dimens2x" tabindex="0" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/plus.svg" class="icons-bg-black"></button>`
|
|
154
|
+
}
|
|
155
|
+
if (this.levels.import) {
|
|
156
|
+
html += `<button title="${LANGUAGE.import_info}" class="btn buttons-copy buttons-html5 copy gridimport boxy-small dimens2x image-button" type="button"><img src="/assets/icons/database-import.svg" class="icons-bg-black"> </span></span></button>`
|
|
157
|
+
}
|
|
158
|
+
if (this.levels.lock) {
|
|
159
|
+
html += `<button title="Lock/Unlock" style="background-color: #E4A11B; color:white" class="btn btn-danger buttons-lock buttons-html5 copy gridlock boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-lock" type="button"><img src="/assets/icons/lock-check.svg" class="icons-bg-white"> </span></span></button>`
|
|
160
|
+
}
|
|
161
|
+
if (this.levels.delete_all) {
|
|
162
|
+
html += `<button title="Delete selected data" style="background-color: #DC4C64; color:white" class="btn btn-danger buttons-lock buttons-html5 copy griddeleteall boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-delete-all" type="button"><img src="/assets/icons/http-delete.svg" class="icons-bg-white"> </span></span></button>`
|
|
163
|
+
}
|
|
164
|
+
if (this.hasLevels) {
|
|
165
|
+
html += `<button title="Approval" style="background-color: #E4A11B; color:white" class="btn buttons-html5 boxy-small dimens2x image-button" data-bs-toggle="modal" data-bs-target="#grid-approval" type="button"><img src="/assets/icons/rubber-stamp.svg" class="icons-bg-white"> </span></span></button>`
|
|
166
|
+
}
|
|
167
|
+
html += `<button title="${LANGUAGE.settings}" class="btn buttons-excel buttons-html5 setting gridsettings boxy-small dimens2x image-button" type="button" data-bs-toggle="modal" data-bs-target="#grid-modal"><img src="/assets/icons/settings.svg" class="icons-bg-black"></button>`
|
|
168
|
+
html += `<button class="btn refresh gridreload boxy-small dimens2x image-button" title="${LANGUAGE.grid_refresh}" aria-controls="DataTables_Table_0" type="button"><img src="/assets/icons/refresh.svg" class="icons-bg-black"></button>`
|
|
169
|
+
if (this.levels.export) {
|
|
170
|
+
html += `<div class="btn-group" role="group">
|
|
171
|
+
<button id="dropdownExport" type="button" class="btn dropdown-toggle boxy-small dimens2x image-button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
172
|
+
<img src="/assets/icons/download.svg" class="icons-bg-black">
|
|
173
|
+
</button>
|
|
174
|
+
<div class="dropdown-menu dimens3x" aria-labelledby="dropdownExport">`
|
|
175
|
+
html += `<a class="dropdown-header">Excel</a>`
|
|
176
|
+
html += `<a class="dropdown-item export-search-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel</a>`
|
|
177
|
+
html += `<a class="dropdown-item export-search-raw" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.import}) </a>`
|
|
178
|
+
html += `<a class="dropdown-item export-all-prety" href="#"><i class="text-success fa fa-file-excel-o"></i>Excel (${LANGUAGE.all}) </a>`
|
|
179
|
+
html += `<hr>`
|
|
180
|
+
html += `<a class="dropdown-header">PDF</a>`
|
|
181
|
+
html += `<a class="dropdown-item export-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF </a>`
|
|
182
|
+
html += `<a class="dropdown-item export-all-pdf" href="#"><i class="text-success fa fa-file-excel-o"></i>PDF (${LANGUAGE.all}) </a>`
|
|
183
|
+
html += `</div>`
|
|
184
|
+
}
|
|
185
|
+
html += `</div></div>`
|
|
186
|
+
return html
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get scripts() {
|
|
190
|
+
let script = `<script type="text/javascript" src="${this.srcScript}"></script>`
|
|
191
|
+
script += `<script>${Util.newLine}`
|
|
192
|
+
script += `var dataTableFields = ${JSON.stringify(this.visiblesKey, null, 2)};${Util.newLine}`
|
|
193
|
+
script += `var dataTableTypes = ${JSON.stringify(this.types, null, 2)};${Util.newLine}`
|
|
194
|
+
script += `var dataTableRoute = "${this.routeName}";${Util.newLine}`
|
|
195
|
+
script += `var dataTableHasTotalFields = ${JSON.stringify(this.totalFields)};${Util.newLine}`
|
|
196
|
+
script += `</script>${Util.newLine}`
|
|
197
|
+
script += `<script type="text/javascript" src="${this.dataTableScript}"></script>${Util.newLine}`
|
|
198
|
+
if (this.searchColumns.FILTERKEY) {
|
|
199
|
+
script += `<script>$(function () { setTimeout(function () { ${this.searchColumns.FILTERKEY} },500) });</script>${Util.newLine}`
|
|
200
|
+
}
|
|
201
|
+
script += `<script type="text/javascript" src="${this.dataTableButtons}"></script>${Util.newLine}`
|
|
202
|
+
|
|
203
|
+
//additional script for typeahead in grid
|
|
204
|
+
let typeaheadScript = ''
|
|
205
|
+
for (let key in this.MYMODEL.widgets) {
|
|
206
|
+
if (this.MYMODEL.widgets[key].name == 'typeahead') {
|
|
207
|
+
typeaheadScript += `if($("#${key}").val()){
|
|
208
|
+
setTimeout(()=>{
|
|
209
|
+
ajaxPost('/ztypeaheadpost/${this.MYMODEL.table}/${key}', {
|
|
210
|
+
id: $("#${key}").val()
|
|
211
|
+
}, function(data) {
|
|
212
|
+
$("#${key}Typeahead").val(data);$("#${key}Typeahead").change();
|
|
213
|
+
$("#${key}").change();
|
|
214
|
+
$("#data_table_${key}").change();
|
|
215
|
+
|
|
216
|
+
})
|
|
217
|
+
},1500)
|
|
218
|
+
};
|
|
219
|
+
`
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (typeaheadScript) {
|
|
223
|
+
script += `<script type="text/javascript">$(function () {${typeaheadScript}})</script>${Util.newLine}`
|
|
224
|
+
}
|
|
225
|
+
if (this.hasLevels) {
|
|
226
|
+
//modal-body-approval
|
|
227
|
+
let APPROVAL_LEVELS = myCache.get('APPROVAL_LEVELS')
|
|
228
|
+
let approvalButtonHtml = ``
|
|
229
|
+
for (let item in this.level_approval) {
|
|
230
|
+
let imageapproval = 'brand-bunpo'
|
|
231
|
+
if (item == 22) {
|
|
232
|
+
imageapproval = 'rubber-stamp-off'
|
|
233
|
+
} else if (item == 2) {
|
|
234
|
+
imageapproval = 'list-check'
|
|
235
|
+
} else if (item == 21) {
|
|
236
|
+
imageapproval = 'rubber-stamp'
|
|
237
|
+
}
|
|
238
|
+
let name = APPROVAL_LEVELS.hasOwnProperty(item) ? APPROVAL_LEVELS[item].name : ''
|
|
239
|
+
let color = APPROVAL_LEVELS.hasOwnProperty(item) ? APPROVAL_LEVELS[item].color : ''
|
|
240
|
+
approvalButtonHtml += ` <button title="${name}" data-value="${item}" style="background-color: ${color}; color:white" class="btn btn-approval-levels boxy-small dimens2x image-button mb-3" type="button"><img src="/assets/icons/${imageapproval}.svg" class="icons-bg-white"> ${name}</button> `
|
|
241
|
+
}
|
|
242
|
+
approvalButtonHtml += `<div class="row"><div class="col-md-10"><textarea class="form-control boxy purple-border" id="zapproval_message" placeholder="tulis alasan..." rows="2"></textarea></div><div class="col-md-1"></div></div>`
|
|
243
|
+
|
|
244
|
+
script += `<script type="text/javascript">$(function () {
|
|
245
|
+
$(".modal-body-approval").html('${approvalButtonHtml}');
|
|
246
|
+
$(".btn-approval-levels").on("click", function () {
|
|
247
|
+
ajaxPost('/zapproval-update/${this.MYMODEL.table}', {
|
|
248
|
+
text : $("#zapproval_message").val(),
|
|
249
|
+
value : $(this).attr('data-value'),
|
|
250
|
+
datas: $(".ck").serializeArray()
|
|
251
|
+
}, function (data) {
|
|
252
|
+
toastrForm(data);
|
|
253
|
+
if(data.status == 1) {
|
|
254
|
+
if(data.dataStatus.length > 0) {
|
|
255
|
+
data.dataStatus.map((item) => {
|
|
256
|
+
toastr.error(item);
|
|
257
|
+
});
|
|
258
|
+
setTimeout(function() {
|
|
259
|
+
if(data.status ==1) {
|
|
260
|
+
location.href='';
|
|
261
|
+
}
|
|
262
|
+
},4000);
|
|
263
|
+
} else {
|
|
264
|
+
if(data.status ==1) {
|
|
265
|
+
location.href='';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
})</script>${Util.newLine}`
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
script += `<script type="text/javascript">
|
|
275
|
+
$(function () {
|
|
276
|
+
$("#ck_all").on('click', function () {
|
|
277
|
+
if($(this).is(':checked')) {
|
|
278
|
+
$(".ck").prop('checked',true)
|
|
279
|
+
} else {
|
|
280
|
+
$(".ck").prop('checked',false)
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
$(".btn-save-lock").on("click", function () {
|
|
285
|
+
ajaxPost('/zlock-unlock/${this.MYMODEL.table}', {
|
|
286
|
+
type : 1,
|
|
287
|
+
datas: $(".ck").serializeArray()
|
|
288
|
+
}, function (data) {
|
|
289
|
+
toastrForm(data);
|
|
290
|
+
if(data.status ==1) {
|
|
291
|
+
location.href='';
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
$(".btn-save-unlock").on("click", function () {
|
|
297
|
+
ajaxPost('/zlock-unlock/${this.MYMODEL.table}', {
|
|
298
|
+
type : 0,
|
|
299
|
+
datas: $(".ck").serializeArray()
|
|
300
|
+
}, function (data) {
|
|
301
|
+
toastrForm(data);
|
|
302
|
+
if(data.status ==1) {
|
|
303
|
+
location.href='';
|
|
304
|
+
}
|
|
305
|
+
})
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
$(".btn-save-delete-selected").on("click", function () {
|
|
309
|
+
if(window.confirm("sure to delete selected data ?")) {
|
|
310
|
+
ajaxPost('/zdeleted-selected/${this.MYMODEL.table}', {
|
|
311
|
+
type : 1,
|
|
312
|
+
datas: $(".ck").serializeArray()
|
|
313
|
+
}, function (data) {
|
|
314
|
+
toastrForm(data);
|
|
315
|
+
if(data.status ==1) {
|
|
316
|
+
location.href='';
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
$("#zgrid_default_type").val(${this.gridType});
|
|
323
|
+
|
|
324
|
+
})</script>${Util.newLine}`
|
|
325
|
+
|
|
326
|
+
return script
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
module.exports = dataTable
|