|
1
|
|
|
const requirejs_vendor = "/node_modules"; |
|
2
|
|
|
const require_config: RequireConfig = { |
|
3
|
|
|
paths: { |
|
4
|
|
|
app: "../require", |
|
5
|
|
|
jquery: requirejs_vendor + "/jquery/dist/jquery.min", |
|
6
|
|
|
"jquery-ui": "//code.jquery.com/ui/1.11.4/jquery-ui", |
|
7
|
|
|
"jquery-migrate": "//code.jquery.com/jquery-migrate-git.min", |
|
8
|
|
|
|
|
9
|
|
|
//DataTables |
|
10
|
|
|
"datatables.net": |
|
11
|
|
|
requirejs_vendor + "/datatables.net/js/jquery.dataTables.min", |
|
12
|
|
|
"datatables.net-bs4": |
|
13
|
|
|
requirejs_vendor + "/datatables.net-bs4/js/datatables.bootstrap4.min", |
|
14
|
|
|
"datatables.net-autofill": |
|
15
|
|
|
requirejs_vendor + "/datatables.net-autofill/js/dataTables.autoFill.min", |
|
16
|
|
|
"datatables.net-buttons": |
|
17
|
|
|
requirejs_vendor + "/datatables.net-buttons/js/dataTables.buttons.min", |
|
18
|
|
|
"datatables.net-buttons-html5": |
|
19
|
|
|
requirejs_vendor + "/datatables.net-buttons/js/buttons.html5.min", |
|
20
|
|
|
"datatables.net-buttons-flash": |
|
21
|
|
|
requirejs_vendor + "/datatables.net-buttons/js/buttons.flash.min", |
|
22
|
|
|
"datatables.net-buttons-print": |
|
23
|
|
|
requirejs_vendor + "/datatables.net-buttons/js/buttons.print.min", |
|
24
|
|
|
"datatables.net-colreorder": |
|
25
|
|
|
requirejs_vendor + |
|
26
|
|
|
"/datatables.net-colreorder/js/dataTables.colReorder.min", |
|
27
|
|
|
"datatables.net-rowreorder": |
|
28
|
|
|
requirejs_vendor + |
|
29
|
|
|
"/datatables.net-rowreorder/js/dataTables.rowReorder.min", |
|
30
|
|
|
"datatables.net-scroller": |
|
31
|
|
|
requirejs_vendor + "/datatables.net-scroller/js/dataTables.scroller.min", |
|
32
|
|
|
"datatables.net-select": |
|
33
|
|
|
requirejs_vendor + "/datatables.net-select/js/dataTables.select.min", |
|
34
|
|
|
"datatables.net-responsive": |
|
35
|
|
|
requirejs_vendor + |
|
36
|
|
|
"/datatables.net-responsive/js/dataTables.responsive.min", |
|
37
|
|
|
"datatables.net-editor": |
|
38
|
|
|
"https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min", |
|
39
|
|
|
|
|
40
|
|
|
//select2 |
|
41
|
|
|
select2: requirejs_vendor + "/select2/dist/js/select2.full.min", |
|
42
|
|
|
}, |
|
43
|
|
|
shim: { |
|
44
|
|
|
/** |
|
45
|
|
|
* jQuery Compatibility |
|
46
|
|
|
*/ |
|
47
|
|
|
jquery: { |
|
48
|
|
|
exports: "$", |
|
49
|
|
|
}, |
|
50
|
|
|
"datatables.net": { |
|
51
|
|
|
deps: ["jquery"], |
|
52
|
|
|
}, |
|
53
|
|
|
}, |
|
54
|
|
|
css: { |
|
55
|
|
|
select2: requirejs_vendor + "/select2/dist/css/select2.min", |
|
56
|
|
|
}, |
|
57
|
|
|
}; |
|
58
|
|
|
interface RequireConfig { |
|
59
|
|
|
css: object; |
|
60
|
|
|
} |
|
61
|
|
|
const dtpackage = function () { |
|
62
|
|
|
return [ |
|
63
|
|
|
"datatables.net", |
|
64
|
|
|
"datatables.net-colreorder", |
|
65
|
|
|
"datatables.net-rowreorder", |
|
66
|
|
|
"datatables.net-scroller", |
|
67
|
|
|
"datatables.net-select", |
|
68
|
|
|
"datatables.net-buttons", |
|
69
|
|
|
"datatables.net-buttons-html5", |
|
70
|
|
|
]; |
|
71
|
|
|
}; |
|
72
|
|
|
|
|
73
|
|
|
var requirejs_ignited = false; |
|
74
|
|
|
if (!isnode()) { |
|
75
|
|
|
function downloadRequireJS(win?, event?) { |
|
76
|
|
|
return new Promise(function (resolve) { |
|
77
|
|
|
console.log(`Loading RequireJS using`, event); |
|
78
|
|
|
if (!requirejs_ignited) { |
|
79
|
|
|
var element = document.createElement("script"); |
|
80
|
|
|
element.src = "/node_modules/requirejs/require.js"; |
|
81
|
|
|
element.onload = element.onreadystatechange = function () { |
|
82
|
|
|
if (typeof requirejs != "undefined") { |
|
83
|
|
|
console.log("requirejs ignited and loaded successfuly"); |
|
84
|
|
|
requirejs.config(require_config); |
|
85
|
|
|
} |
|
86
|
|
|
resolve(true); |
|
87
|
|
|
}; |
|
88
|
|
|
document.body.appendChild(element); |
|
89
|
|
|
} |
|
90
|
|
|
}); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Load requirejs |
|
96
|
|
|
*/ |
|
97
|
|
|
function load_requirejs() { |
|
98
|
|
|
if (!requirejs_ignited) { |
|
99
|
|
|
console.info("RequireJS not loaded, loading them now"); |
|
100
|
|
|
return downloadRequireJS(); |
|
101
|
|
|
} else { |
|
102
|
|
|
console.info("RequireJS already ignited"); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Load Modules From node_modules folder |
|
108
|
|
|
* @param name |
|
109
|
|
|
* @param callback |
|
110
|
|
|
*/ |
|
111
|
|
|
function load_module(name: string | string[], callback: Function) { |
|
112
|
|
|
if (typeof name == "string") { |
|
113
|
|
|
name = [name]; |
|
114
|
|
|
} |
|
115
|
|
|
var scripts_List = []; |
|
116
|
|
|
var style_List = []; |
|
117
|
|
|
|
|
118
|
|
|
for (const key in require_config.paths) { |
|
119
|
|
|
if (require_config.paths.hasOwnProperty(key)) { |
|
120
|
|
|
const element = require_config.paths[key]; |
|
121
|
|
|
if (name.includes(key)) { |
|
122
|
|
|
scripts_List.push(element + ".js"); |
|
123
|
|
|
if (require_config.css.hasOwnProperty(key)) { |
|
124
|
|
|
style_List.push(require_config.css[key] + ".css"); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
//console.log(scripts_List); |
|
130
|
|
|
if (!style_List.length) { |
|
131
|
|
|
LoadScript(scripts_List, callback); |
|
132
|
|
|
} else { |
|
133
|
|
|
LoadScript(scripts_List, function () { |
|
134
|
|
|
loadCSS(style_List, callback); |
|
135
|
|
|
}); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Datatables loader |
|
141
|
|
|
* @param callback |
|
142
|
|
|
*/ |
|
143
|
|
|
function load_datatables(callback: Function) { |
|
144
|
|
|
LoadScript( |
|
145
|
|
|
[ |
|
146
|
|
|
"/assets/mdb-dashboard/js/addons/datatables.min.js", |
|
147
|
|
|
"/assets/mdb-dashboard/js/addons/datatables-select.min.js", |
|
148
|
|
|
//"/node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js", |
|
149
|
|
|
"/node_modules/datatables.net-rowreorder/js/dataTables.rowReorder.min.js", |
|
150
|
|
|
"/node_modules/datatables.net-responsive/js/dataTables.responsive.min.js", |
|
151
|
|
|
"/node_modules/datatables.net-buttons/js/dataTables.buttons.min.js", |
|
152
|
|
|
"/node_modules/datatables.net-buttons/js/buttons.print.min.js", |
|
153
|
|
|
], |
|
154
|
|
|
function () { |
|
155
|
|
|
loadCSS( |
|
156
|
|
|
[ |
|
157
|
|
|
"/src/MVC/themes/assets/partial/datatables.min.css", |
|
158
|
|
|
"/assets/mdb-dashboard/css/addons/datatables-select.min.css", |
|
159
|
|
|
"/assets/mdb-dashboard/css/addons/datatables.min.css", |
|
160
|
|
|
"https://cdn.datatables.net/responsive/2.2.5/css/responsive.dataTables.min.css", |
|
161
|
|
|
"https://cdn.datatables.net/rowreorder/1.2.7/css/rowReorder.dataTables.min.css", |
|
162
|
|
|
], |
|
163
|
|
|
null |
|
164
|
|
|
); |
|
165
|
|
|
datatables_init().then(function () { |
|
166
|
|
|
var dtl = $(".dataTables_length"); |
|
167
|
|
|
var toolbar = $("div.dt-toolbar"); |
|
168
|
|
|
var button = $("button.dt-button").not(".btn"); |
|
169
|
|
|
setTimeout(function () { |
|
170
|
|
|
if (button.length) { |
|
171
|
|
|
button.addClass("btn btn-info"); |
|
172
|
|
|
} |
|
173
|
|
|
if (dtl.length) { |
|
174
|
|
|
dtl.addClass("bs-select"); |
|
175
|
|
|
} |
|
176
|
|
|
if (toolbar.length) { |
|
177
|
|
|
toolbar.html(``); |
|
178
|
|
|
} |
|
179
|
|
|
}, 5000); |
|
180
|
|
|
if (typeof callback == "function") { |
|
181
|
|
|
callback(); |
|
182
|
|
|
} |
|
183
|
|
|
}); |
|
184
|
|
|
} |
|
185
|
|
|
); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
var datatables_ignited = false; |
|
189
|
|
|
/** |
|
190
|
|
|
* Datatables init |
|
191
|
|
|
* @todo disable error warning |
|
192
|
|
|
* @todo add refresh button |
|
193
|
|
|
*/ |
|
194
|
|
|
function datatables_init() { |
|
195
|
|
|
return new Promise(function (resolve, reject) { |
|
196
|
|
|
if (datatables_ignited) { |
|
197
|
|
|
console.error("datatables already ignited"); |
|
198
|
|
|
} else { |
|
199
|
|
|
if (typeof jQuery.fn.dataTable != "undefined") { |
|
200
|
|
|
jQuery.fn.dataTable.ext.errMode = "none"; |
|
201
|
|
|
jQuery.fn.dataTable.ext.buttons.refresh = { |
|
202
|
|
|
extend: "collection", |
|
203
|
|
|
text: '<i class="fas fa-sync"></i>', |
|
204
|
|
|
className: "btn btn-info", |
|
205
|
|
|
action: function (e, dt, node, config) { |
|
206
|
|
|
dt.clear().draw(); |
|
207
|
|
|
dt.ajax.reload(); |
|
208
|
|
|
}, |
|
209
|
|
|
}; |
|
210
|
|
|
console.info("datatables ignited successfully"); |
|
211
|
|
|
datatables_ignited = true; |
|
212
|
|
|
} else { |
|
213
|
|
|
console.error("Datatables not loaded"); |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
resolve(); |
|
217
|
|
|
}); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
var optimized_ids = []; |
|
221
|
|
|
/** |
|
222
|
|
|
* Optimize Material Datatables |
|
223
|
|
|
* @param id id table |
|
224
|
|
|
* @param callback additional function to optimizer |
|
225
|
|
|
*/ |
|
226
|
|
|
function datatables_optimize(id: string, callback?: Function) { |
|
227
|
|
|
if (optimized_ids.includes(id)) { |
|
228
|
|
|
console.error(`Datatables #${id} already optimized`); |
|
229
|
|
|
return; |
|
230
|
|
|
} |
|
231
|
|
|
optimized_ids.push(id); |
|
232
|
|
|
$("#" + id + "_wrapper") |
|
233
|
|
|
.add("#pkgList_wrapper") |
|
234
|
|
|
.find("label") |
|
235
|
|
|
.each(function () { |
|
236
|
|
|
$(this).parent().append($(this).children()); |
|
237
|
|
|
}); |
|
238
|
|
|
$("#" + id + "_wrapper .dataTables_filter") |
|
239
|
|
|
.find("input") |
|
240
|
|
|
.each(function () { |
|
241
|
|
|
const $this = $(this); |
|
242
|
|
|
$this.attr("placeholder", "Search"); |
|
243
|
|
|
$this.removeClass("form-control-sm"); |
|
244
|
|
|
}); |
|
245
|
|
|
$("#" + id + "_wrapper .dataTables_length") |
|
246
|
|
|
.add("#pkgList_wrapper .dataTables_length") |
|
247
|
|
|
.addClass("d-flex flex-row"); |
|
248
|
|
|
$("#" + id + "_wrapper .dataTables_filter") |
|
249
|
|
|
.add("#pkgList_wrapper .dataTables_filter") |
|
250
|
|
|
.addClass("md-form"); |
|
251
|
|
|
$("#" + id + "_wrapper select") |
|
252
|
|
|
.add("#pkgList_wrapper select") |
|
253
|
|
|
.removeClass("custom-select custom-select-sm form-control form-control-sm"); |
|
254
|
|
|
$("#" + id + "_wrapper select") |
|
255
|
|
|
.add("#pkgList_wrapper select") |
|
256
|
|
|
.addClass("mdb-select"); |
|
257
|
|
|
if (typeof $.fn.materialSelect == "function") { |
|
258
|
|
|
$("#" + id + "_wrapper .mdb-select") |
|
259
|
|
|
.add("#pkgList_wrapper .mdb-select") |
|
260
|
|
|
.materialSelect(); |
|
261
|
|
|
} |
|
262
|
|
|
$("#" + id + "_wrapper .dataTables_filter") |
|
263
|
|
|
.add("#pkgList_wrapper .dataTables_filter") |
|
264
|
|
|
.find("label") |
|
265
|
|
|
.remove(); |
|
266
|
|
|
if (typeof callback == "function") { |
|
267
|
|
|
callback(); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Scroll up after click pagination dt |
|
273
|
|
|
* @param target |
|
274
|
|
|
*/ |
|
275
|
|
|
function pagination_up(target: JQuery) { |
|
276
|
|
|
if (!(target instanceof jQuery)) { |
|
277
|
|
|
return console.error( |
|
278
|
|
|
getFuncName() + " target element not instance of jQuery" |
|
279
|
|
|
); |
|
280
|
|
|
} |
|
281
|
|
|
target.on("page.dt", function () { |
|
282
|
|
|
$("html, body").animate( |
|
283
|
|
|
{ |
|
284
|
|
|
scrollTop: jQuery(".dataTables_wrapper").offset().top, |
|
285
|
|
|
}, |
|
286
|
|
|
"slow" |
|
287
|
|
|
); |
|
288
|
|
|
|
|
289
|
|
|
$("thead tr th:first-child").focus().blur(); |
|
290
|
|
|
}); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Optimize Datatables Columns Options |
|
295
|
|
|
* @param data |
|
296
|
|
|
* @param exclude |
|
297
|
|
|
*/ |
|
298
|
|
|
function datatables_colums_options( |
|
299
|
|
|
data?: DataTables.ColumnSettings, |
|
300
|
|
|
exclude?: string[] |
|
301
|
|
|
) { |
|
302
|
|
|
if ( |
|
303
|
|
|
!data.hasOwnProperty("defaultContent") && |
|
304
|
|
|
exclude && |
|
305
|
|
|
!exclude.includes("defaultContent") |
|
306
|
|
|
) { |
|
307
|
|
|
data.defaultContent = "<i>Not set</i>"; |
|
308
|
|
|
} |
|
309
|
|
|
if ( |
|
310
|
|
|
!data.hasOwnProperty("render") && |
|
311
|
|
|
exclude && |
|
312
|
|
|
!exclude.includes("render") |
|
313
|
|
|
) { |
|
314
|
|
|
data.render = function (data, type, row, meta) { |
|
315
|
|
|
if (["string", "number"].includes(typeof data) || Array.isArray(data)) { |
|
316
|
|
|
if (!data.length) { |
|
317
|
|
|
return data.defaultContent; |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
if (!data) { |
|
321
|
|
|
return data.defaultContent; |
|
322
|
|
|
} else { |
|
323
|
|
|
return data; |
|
324
|
|
|
} |
|
325
|
|
|
}; |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|