zet-lib 3.1.2 → 3.1.3
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/lib/zdataTable.js +49 -9
- package/package.json +1 -1
package/lib/zdataTable.js
CHANGED
|
@@ -20,10 +20,23 @@ class dataTable {
|
|
|
20
20
|
this.types = {}
|
|
21
21
|
this.roles = myCache.get('ROLES')[datas.zuser.role_id] || {}
|
|
22
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
|
|
23
|
+
this.hasLevels = Object.keys(this.level_approval).length > 0
|
|
24
24
|
this.visiblesKey = this.visibles.map((item) => item.key)
|
|
25
25
|
this.gridType = datas.gridType || 1
|
|
26
26
|
this.additionalCss = ''
|
|
27
|
+
this.moneyAttributes = {}
|
|
28
|
+
this.hasMoney = false
|
|
29
|
+
if (this.MYMODEL && this.MYMODEL.widgets) {
|
|
30
|
+
const widgets = this.MYMODEL.widgets
|
|
31
|
+
for (let i = 0; i < this.visiblesKey.length; i++) {
|
|
32
|
+
const item = this.visiblesKey[i]
|
|
33
|
+
const widget = widgets[item]
|
|
34
|
+
if (widget && widget.name == 'money') {
|
|
35
|
+
this.moneyAttributes[item] = widget
|
|
36
|
+
this.hasMoney = true
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
27
40
|
if (this.gridType == 1) {
|
|
28
41
|
this.dataTableScript = '/modules/datatable/normal.js'
|
|
29
42
|
} else if (this.gridType == 2) {
|
|
@@ -54,7 +67,26 @@ class dataTable {
|
|
|
54
67
|
this.relations = obj.relations
|
|
55
68
|
this.routeName = this.MYMODEL.routeName
|
|
56
69
|
this.types = obj.TYPES
|
|
57
|
-
this.totalFields =
|
|
70
|
+
this.totalFields = []
|
|
71
|
+
this.moneyAttributes = {}
|
|
72
|
+
this.hasMoney = false
|
|
73
|
+
if (this.MYMODEL && this.MYMODEL.widgets) {
|
|
74
|
+
const widgets = this.MYMODEL.widgets
|
|
75
|
+
for (let i = 0; i < this.visiblesKey.length; i++) {
|
|
76
|
+
const item = this.visiblesKey[i]
|
|
77
|
+
const widget = widgets[item]
|
|
78
|
+
if (widget) {
|
|
79
|
+
const widgetName = widget.name
|
|
80
|
+
if (widgetName == 'number' || widgetName == 'money') {
|
|
81
|
+
this.totalFields.push(item)
|
|
82
|
+
}
|
|
83
|
+
if (widgetName == 'money') {
|
|
84
|
+
this.moneyAttributes[item] = widget
|
|
85
|
+
this.hasMoney = true
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
58
90
|
delete obj.MYMODEL
|
|
59
91
|
delete obj.relations
|
|
60
92
|
delete obj.TYPES
|
|
@@ -72,9 +104,10 @@ class dataTable {
|
|
|
72
104
|
if (this.setColumns) return this.setColumns
|
|
73
105
|
let html = ''
|
|
74
106
|
if (Array.isArray(this.visibles)) {
|
|
75
|
-
this.visibles.
|
|
107
|
+
for (let i = 0; i < this.visibles.length; i++) {
|
|
108
|
+
const item = this.visibles[i]
|
|
76
109
|
html += `<th id="data_${item.key}_label">${item.name || ''}</th>`
|
|
77
|
-
}
|
|
110
|
+
}
|
|
78
111
|
} else {
|
|
79
112
|
for (const key in this.visibles) {
|
|
80
113
|
html += `<th id="data_${key}_label">${this.visibles[key]}</th>`
|
|
@@ -87,9 +120,10 @@ class dataTable {
|
|
|
87
120
|
get columnsFilter() {
|
|
88
121
|
let html = '<tr class="filters">'
|
|
89
122
|
if (Array.isArray(this.visibles)) {
|
|
90
|
-
this.visibles.
|
|
123
|
+
for (let i = 0; i < this.visibles.length; i++) {
|
|
124
|
+
const item = this.visibles[i]
|
|
91
125
|
html += `<th id="data_${item.key}_label">${this.searchColumns[item.key]}</th>`
|
|
92
|
-
}
|
|
126
|
+
}
|
|
93
127
|
} else {
|
|
94
128
|
for (const key in this.visibles) {
|
|
95
129
|
html += `<th id="data_${key}">${this.searchColumns[key]}</th>`
|
|
@@ -193,6 +227,9 @@ class dataTable {
|
|
|
193
227
|
script += `var dataTableTypes = ${JSON.stringify(this.types, null, 2)};${Util.newLine}`
|
|
194
228
|
script += `var dataTableRoute = "${this.routeName}";${Util.newLine}`
|
|
195
229
|
script += `var dataTableHasTotalFields = ${JSON.stringify(this.totalFields)};${Util.newLine}`
|
|
230
|
+
if(this.hasMoney) {
|
|
231
|
+
script += `var dataTableMoneyAttributes = ${JSON.stringify(this.moneyAttributes, null, 2)};${Util.newLine}`
|
|
232
|
+
}
|
|
196
233
|
script += `</script>${Util.newLine}`
|
|
197
234
|
script += `<script type="text/javascript" src="${this.dataTableScript}"></script>${Util.newLine}`
|
|
198
235
|
if (this.searchColumns.FILTERKEY) {
|
|
@@ -202,9 +239,10 @@ class dataTable {
|
|
|
202
239
|
|
|
203
240
|
//additional script for typeahead in grid
|
|
204
241
|
let typeaheadScript = ''
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
242
|
+
if (this.MYMODEL && this.MYMODEL.widgets) {
|
|
243
|
+
for (let key in this.MYMODEL.widgets) {
|
|
244
|
+
if (this.MYMODEL.widgets[key].name == 'typeahead') {
|
|
245
|
+
typeaheadScript += `if($("#${key}").val()){
|
|
208
246
|
setTimeout(()=>{
|
|
209
247
|
ajaxPost('/ztypeaheadpost/${this.MYMODEL.table}/${key}', {
|
|
210
248
|
id: $("#${key}").val()
|
|
@@ -217,11 +255,13 @@ class dataTable {
|
|
|
217
255
|
},1500)
|
|
218
256
|
};
|
|
219
257
|
`
|
|
258
|
+
}
|
|
220
259
|
}
|
|
221
260
|
}
|
|
222
261
|
if (typeaheadScript) {
|
|
223
262
|
script += `<script type="text/javascript">$(function () {${typeaheadScript}})</script>${Util.newLine}`
|
|
224
263
|
}
|
|
264
|
+
|
|
225
265
|
if (this.hasLevels) {
|
|
226
266
|
//modal-body-approval
|
|
227
267
|
let APPROVAL_LEVELS = myCache.get('APPROVAL_LEVELS')
|