zet-lib 1.4.17 → 1.4.19
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/Form.js +24 -0
- package/lib/moduleLib.js +403 -299
- package/lib/zAppRouter.js +18 -10
- package/lib/zRoute.js +79 -39
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -613,6 +613,30 @@ Form.field = (obj) => {
|
|
|
613
613
|
</div></div>
|
|
614
614
|
</label></div>${information}${append}`;
|
|
615
615
|
break;
|
|
616
|
+
|
|
617
|
+
case "dropboxview":
|
|
618
|
+
let countdropboxFiles =
|
|
619
|
+
obj.value && obj.value.length ? obj.value.length + " Files" : "";
|
|
620
|
+
let bodydropboxview =
|
|
621
|
+
countdropboxFiles == ""
|
|
622
|
+
? ""
|
|
623
|
+
: `<div class="card-header">${countdropboxFiles} <div class="float-end">
|
|
624
|
+
<span class="icon-small icons-light" title="Download"><img onclick="location.href= '/zdownloads-dropbox/${obj.routeName}/${obj.key}/${obj.dataId}'" class="icons-bg-black gridview icon-image" src="/assets/icons/download.svg"></span>
|
|
625
|
+
<span class="icon-small icons-light" title="Compress Images"><img onclick="if(window.confirm('Compress Images ?')) {ajaxPost('/zcompress-dropbox',{table:'${obj.routeName}',field:'${obj.key}',id:${obj.dataId}},(data) => toastrForm(data))}" class="icons-bg-black gridextract icon-image" src="/assets/icons/file-zip.svg"></span>
|
|
626
|
+
</div></div>`;
|
|
627
|
+
displayForm = `<div id="div-progress"></div><div class="card">
|
|
628
|
+
${bodydropboxview}
|
|
629
|
+
<div class="card-body">`;
|
|
630
|
+
if (obj.value && obj.value.length > 0) {
|
|
631
|
+
obj.value.map((item) => {
|
|
632
|
+
let extFile = Util.fileExtension(item);
|
|
633
|
+
let filename = item;
|
|
634
|
+
let filePath = `/${obj.routeName}/${obj.key}/${item}`;
|
|
635
|
+
displayForm += `<img src="/img/dropbox.png" class="boxy zoom mx-2 my-2 zdropbox-view" width="200px" data-ext="${extFile.ext}" data-path="${filePath}" data-table="${obj.table}" data-field="${obj.key}" data-name="${item}" alt="${item}">`;
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
displayForm += `</div></div>`;
|
|
639
|
+
break;
|
|
616
640
|
default:
|
|
617
641
|
value = value ? value.replace(/"/g, """) : obj.value;
|
|
618
642
|
displayForm = `${prepend}${inputGroupLeft}<input ${disabled} autocomplete="nope" autofocus="" ${readonly} ${tabindex} type="${type}" class="form-control ${obj.class}" ${id} ${name} ${placeholder} ${required} value="${value}" data-t="${value}" ${htmlOptions}>${inputGroupRight}${information}${append}`;
|
package/lib/moduleLib.js
CHANGED
|
@@ -1,115 +1,118 @@
|
|
|
1
|
-
const Util = require(
|
|
2
|
-
const newLine = Util.newLine
|
|
1
|
+
const Util = require("./Util");
|
|
2
|
+
const newLine = Util.newLine;
|
|
3
3
|
|
|
4
|
-
const m = {}
|
|
4
|
+
const m = {};
|
|
5
5
|
|
|
6
6
|
//module for ide code editor
|
|
7
7
|
m.ideCDN = function (req, res) {
|
|
8
|
-
let script =
|
|
9
|
-
let head =
|
|
10
|
-
let end =
|
|
11
|
-
end += `<script src="/modules/ace.js"></script>${Util.newLine}
|
|
8
|
+
let script = "";
|
|
9
|
+
let head = ``;
|
|
10
|
+
let end = ``;
|
|
11
|
+
end += `<script src="/modules/ace.js"></script>${Util.newLine}`;
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
14
|
head: head,
|
|
15
15
|
end: end,
|
|
16
16
|
script: script,
|
|
17
|
-
}
|
|
18
|
-
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
19
|
|
|
20
20
|
m.ide = function (req, res, elem) {
|
|
21
|
-
let script =
|
|
22
|
-
let head =
|
|
23
|
-
let end =
|
|
24
|
-
elem = elem ||
|
|
21
|
+
let script = "";
|
|
22
|
+
let head = ``;
|
|
23
|
+
let end = ``;
|
|
24
|
+
elem = elem || "#ide_editor";
|
|
25
25
|
end += `<script> var editor_${elem} = ace.edit("${elem}");
|
|
26
26
|
editor_${elem}.getSession().setMode("ace/mode/ejs");
|
|
27
|
-
</script> ${Util.newLine}
|
|
27
|
+
</script> ${Util.newLine}`;
|
|
28
28
|
return {
|
|
29
29
|
head: head,
|
|
30
30
|
end: end,
|
|
31
31
|
script: script,
|
|
32
|
-
}
|
|
33
|
-
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
34
|
|
|
35
35
|
m.tags = function (req, res, elem) {
|
|
36
|
-
let script =
|
|
37
|
-
let head =
|
|
38
|
-
let end =
|
|
39
|
-
elem = elem ||
|
|
40
|
-
end += `<script type="module">import Tags from "/modules/tags.js";Tags.init("${elem}");</script
|
|
36
|
+
let script = "";
|
|
37
|
+
let head = ``;
|
|
38
|
+
let end = ``;
|
|
39
|
+
elem = elem || ".tags";
|
|
40
|
+
end += `<script type="module">import Tags from "/modules/tags.js";Tags.init("${elem}");</script>`;
|
|
41
41
|
return {
|
|
42
42
|
head: head,
|
|
43
43
|
end: end,
|
|
44
44
|
script: script,
|
|
45
|
-
}
|
|
46
|
-
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
47
|
//module for datepicker
|
|
48
48
|
m.datepicker = function (req, res, elem) {
|
|
49
|
-
let script =
|
|
50
|
-
let head =
|
|
51
|
-
let end =
|
|
52
|
-
elem = elem ||
|
|
49
|
+
let script = "";
|
|
50
|
+
let head = ``;
|
|
51
|
+
let end = ``;
|
|
52
|
+
elem = elem || ".datepicker";
|
|
53
53
|
/* head += '<link href="/css/bootstrap-datepicker.css" rel="stylesheet">';
|
|
54
54
|
end += '<script src="/js/bootstrap-datepicker.min.js"></script>';*/
|
|
55
|
-
head +=
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
head +=
|
|
56
|
+
'<link href="/modules/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet">';
|
|
57
|
+
end +=
|
|
58
|
+
'<script src="/modules/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>';
|
|
59
|
+
script = `$.fn.datepicker.defaults.format = "yyyy-mm-dd";$.fn.datepicker.defaults.todayHighlight = true;$("body").on("click", "${elem}", function(){$(this).datepicker();$(this).datepicker("show");});`;
|
|
58
60
|
|
|
59
61
|
return {
|
|
60
62
|
head: head,
|
|
61
63
|
end: end,
|
|
62
64
|
script: script,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
65
67
|
|
|
66
68
|
//module for selectize
|
|
67
69
|
//https://selectize.dev
|
|
68
70
|
//https://github.com/selectize/selectize.js
|
|
69
71
|
m.selectize = function (req, res, elem) {
|
|
70
|
-
let script =
|
|
71
|
-
let head =
|
|
72
|
-
let end =
|
|
73
|
-
elem = elem ||
|
|
74
|
-
head +=
|
|
75
|
-
|
|
72
|
+
let script = "";
|
|
73
|
+
let head = ``;
|
|
74
|
+
let end = ``;
|
|
75
|
+
elem = elem || ".selectize";
|
|
76
|
+
head +=
|
|
77
|
+
'<link href="/modules/selectizejs/css/selectize.bootstrap5.css" rel="stylesheet">';
|
|
78
|
+
end += '<script src="/modules/selectizejs/js/selectize.min.js"></script>';
|
|
76
79
|
|
|
77
80
|
script += `$(() => {
|
|
78
81
|
$('${elem}').selectize({
|
|
79
82
|
sortField: 'text'
|
|
80
83
|
});
|
|
81
|
-
})
|
|
84
|
+
});`;
|
|
82
85
|
|
|
83
86
|
return {
|
|
84
87
|
head: head,
|
|
85
88
|
end: end,
|
|
86
89
|
script: script,
|
|
87
|
-
}
|
|
88
|
-
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
89
92
|
|
|
90
93
|
//module for dropzone
|
|
91
94
|
m.dropzone = function (req, res, elem) {
|
|
92
|
-
let script =
|
|
93
|
-
let head =
|
|
94
|
-
let end =
|
|
95
|
-
elem = elem ||
|
|
96
|
-
head += '<link href="/modules/dropzone/dropzone.css" rel="stylesheet">'
|
|
97
|
-
end += '<script src="/modules/dropzone/dropzone.min.js"></script>'
|
|
95
|
+
let script = "";
|
|
96
|
+
let head = ``;
|
|
97
|
+
let end = ``;
|
|
98
|
+
elem = elem || ".dropzone";
|
|
99
|
+
head += '<link href="/modules/dropzone/dropzone.css" rel="stylesheet">';
|
|
100
|
+
end += '<script src="/modules/dropzone/dropzone.min.js"></script>';
|
|
98
101
|
|
|
99
102
|
return {
|
|
100
103
|
head: head,
|
|
101
104
|
end: end,
|
|
102
105
|
script: script,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
105
108
|
|
|
106
109
|
//module for dragdrop
|
|
107
110
|
m.dragdrop = function (req, res, elem) {
|
|
108
|
-
let script =
|
|
109
|
-
let head =
|
|
110
|
-
let end =
|
|
111
|
-
head += '<link href="/modules/drag/drag.css" rel="stylesheet">'
|
|
112
|
-
end += '<script src="/modules/drag/jquery-sortable.js"></script>'
|
|
111
|
+
let script = "";
|
|
112
|
+
let head = ``;
|
|
113
|
+
let end = ``;
|
|
114
|
+
head += '<link href="/modules/drag/drag.css" rel="stylesheet">';
|
|
115
|
+
end += '<script src="/modules/drag/jquery-sortable.js"></script>';
|
|
113
116
|
script += `$(function () {
|
|
114
117
|
$("ol.mydragable${elem}").sortable({
|
|
115
118
|
group: 'mydragable${elem}',
|
|
@@ -131,20 +134,20 @@ m.dragdrop = function (req, res, elem) {
|
|
|
131
134
|
});
|
|
132
135
|
});
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
`;
|
|
135
138
|
return {
|
|
136
139
|
head: head,
|
|
137
140
|
end: end,
|
|
138
141
|
script: script,
|
|
139
|
-
}
|
|
140
|
-
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
141
144
|
|
|
142
145
|
//module for google map
|
|
143
146
|
m.location = function (req, res, key) {
|
|
144
|
-
let script =
|
|
145
|
-
let head =
|
|
146
|
-
let end =
|
|
147
|
-
end += `<script src="https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_KEY}&callback=initAutocompleteZmap&libraries=places&language=ID" defer></script
|
|
147
|
+
let script = ``;
|
|
148
|
+
let head = ``;
|
|
149
|
+
let end = ``;
|
|
150
|
+
end += `<script src="https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_KEY}&callback=initAutocompleteZmap&libraries=places&language=ID" defer></script>`;
|
|
148
151
|
script += `let searchAddressMap;
|
|
149
152
|
let autocompleteMap;
|
|
150
153
|
function initAutocompleteZmap() {
|
|
@@ -229,221 +232,254 @@ m.location = function (req, res, key) {
|
|
|
229
232
|
}
|
|
230
233
|
);
|
|
231
234
|
}
|
|
232
|
-
}
|
|
235
|
+
}`;
|
|
233
236
|
return {
|
|
234
237
|
head: head,
|
|
235
238
|
end: end,
|
|
236
239
|
script: script,
|
|
237
|
-
}
|
|
238
|
-
}
|
|
240
|
+
};
|
|
241
|
+
};
|
|
239
242
|
|
|
240
243
|
//module for datepicker
|
|
241
244
|
m.datetimepicker = function (req, res, elem) {
|
|
242
|
-
let script =
|
|
243
|
-
let head =
|
|
244
|
-
let end =
|
|
245
|
-
elem = elem ||
|
|
246
|
-
head +=
|
|
247
|
-
|
|
248
|
-
end +=
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
let script = "";
|
|
246
|
+
let head = ``;
|
|
247
|
+
let end = ``;
|
|
248
|
+
elem = elem || ".datetimepicker";
|
|
249
|
+
head +=
|
|
250
|
+
'<link href="/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />';
|
|
251
|
+
end +=
|
|
252
|
+
'<script type="text/javascript" src="/js/moment-with-locales.min.js" ></script>';
|
|
253
|
+
end +=
|
|
254
|
+
'<script type="text/javascript" src="/js/bootstrap-datetimepicker.min.js" ></script>';
|
|
255
|
+
script += `$(function () { $("${elem}").datetimepicker({format:'YYYY-MM-DD hh:mm:ss'}); });`;
|
|
256
|
+
script += `setTimeout(function () { $("body").click();},1000);`;
|
|
257
|
+
script += `$("body").on("click", function(){$("${elem}").datetimepicker({format:'YYYY-MM-DD hh:mm:ss'});});`;
|
|
252
258
|
|
|
253
259
|
return {
|
|
254
260
|
head: head,
|
|
255
261
|
end: end,
|
|
256
262
|
script: script,
|
|
257
|
-
}
|
|
258
|
-
}
|
|
263
|
+
};
|
|
264
|
+
};
|
|
259
265
|
|
|
260
266
|
//using ckeditor
|
|
261
267
|
m.ckeditor = function (req, res, elem) {
|
|
262
|
-
let script =
|
|
263
|
-
let head =
|
|
264
|
-
let end =
|
|
265
|
-
elem = elem ||
|
|
266
|
-
end +=
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
end +=
|
|
268
|
+
let script = "";
|
|
269
|
+
let head = ``;
|
|
270
|
+
let end = ``;
|
|
271
|
+
elem = elem || ".editor";
|
|
272
|
+
end +=
|
|
273
|
+
'<script src="/modules/ckeditor5-build-classic/ckeditor.js"></script>' +
|
|
274
|
+
newLine;
|
|
275
|
+
end += "<script>";
|
|
276
|
+
end +=
|
|
277
|
+
'ClassicEditor.create( document.querySelector( "' +
|
|
278
|
+
elem +
|
|
279
|
+
'" ) ).catch( error => {console.error( error );} );' +
|
|
280
|
+
newLine;
|
|
281
|
+
end += "</script>";
|
|
270
282
|
return {
|
|
271
283
|
head: head,
|
|
272
284
|
end: end,
|
|
273
285
|
script: script,
|
|
274
|
-
}
|
|
275
|
-
}
|
|
286
|
+
};
|
|
287
|
+
};
|
|
276
288
|
|
|
277
289
|
//using tinymce
|
|
278
290
|
m.tinymce = function (req, res, elem) {
|
|
279
|
-
let script =
|
|
280
|
-
let head =
|
|
281
|
-
let end =
|
|
282
|
-
elem = elem ||
|
|
283
|
-
end +=
|
|
291
|
+
let script = "";
|
|
292
|
+
let head = ``;
|
|
293
|
+
let end = ``;
|
|
294
|
+
elem = elem || ".tinymce";
|
|
295
|
+
end +=
|
|
296
|
+
'<script src="https://cdn.tiny.cloud/1/b7054u42l8lw67ch5oh9qutnvbyu8exzryg4edy0gg2snhtr/tinymce/6/tinymce.min.js" referrerpolicy="origin"></script>' +
|
|
297
|
+
newLine;
|
|
284
298
|
script += ` tinymce.init({
|
|
285
299
|
selector: '${elem}',
|
|
286
300
|
plugins: 'anchor autolink charmap codesample emoticons image link lists media searchreplace table visualblocks wordcount',
|
|
287
301
|
toolbar: 'undo redo | blocks fontfamily fontsize | bold italic underline strikethrough | link image media table | align lineheight | numlist bullist indent outdent | emoticons charmap | removeformat',
|
|
288
|
-
})
|
|
302
|
+
});`;
|
|
289
303
|
return {
|
|
290
304
|
head: head,
|
|
291
305
|
end: end,
|
|
292
306
|
script: script,
|
|
293
|
-
}
|
|
294
|
-
}
|
|
307
|
+
};
|
|
308
|
+
};
|
|
295
309
|
|
|
296
310
|
//using froala
|
|
297
311
|
m.froala = function (req, res, elem) {
|
|
298
|
-
let script =
|
|
299
|
-
let head =
|
|
300
|
-
let end =
|
|
301
|
-
elem = elem ||
|
|
302
|
-
|
|
303
|
-
head +=
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
312
|
+
let script = "";
|
|
313
|
+
let head = ``;
|
|
314
|
+
let end = ``;
|
|
315
|
+
elem = elem || ".editor";
|
|
316
|
+
|
|
317
|
+
head +=
|
|
318
|
+
'<link href="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/css/froala_editor.pkgd.min.css" rel="stylesheet" type="text/css" />';
|
|
319
|
+
head +=
|
|
320
|
+
'<link href="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/css/froala_style.min.css" rel="stylesheet" type="text/css" />';
|
|
321
|
+
end +=
|
|
322
|
+
'<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/js/froala_editor.pkgd.min.js"></script>';
|
|
323
|
+
script += `$(function() {$("${elem}").froalaEditor({height: 200})});`;
|
|
307
324
|
|
|
308
325
|
return {
|
|
309
326
|
head: head,
|
|
310
327
|
end: end,
|
|
311
328
|
script: script,
|
|
312
|
-
}
|
|
313
|
-
}
|
|
329
|
+
};
|
|
330
|
+
};
|
|
314
331
|
|
|
315
332
|
m.lexical = function (req, res, elem) {
|
|
316
|
-
let script =
|
|
317
|
-
let head =
|
|
318
|
-
let end =
|
|
319
|
-
elem = elem ||
|
|
320
|
-
head += `<link rel="stylesheet" href="/assets/main.143ecbc6.css"
|
|
321
|
-
end += `<script type="module" crossorigin src="/assets/main.3be493b7.js"></script
|
|
333
|
+
let script = "";
|
|
334
|
+
let head = ``;
|
|
335
|
+
let end = ``;
|
|
336
|
+
elem = elem || ".editor";
|
|
337
|
+
head += `<link rel="stylesheet" href="/assets/main.143ecbc6.css">`;
|
|
338
|
+
end += `<script type="module" crossorigin src="/assets/main.3be493b7.js"></script>`;
|
|
322
339
|
return {
|
|
323
340
|
head: head,
|
|
324
341
|
end: end,
|
|
325
342
|
script: script,
|
|
326
|
-
}
|
|
327
|
-
}
|
|
343
|
+
};
|
|
344
|
+
};
|
|
328
345
|
|
|
329
346
|
//Default editor is froala
|
|
330
|
-
m.editor = (req, res, elem =
|
|
331
|
-
elem = elem ||
|
|
347
|
+
m.editor = (req, res, elem = "") => {
|
|
348
|
+
elem = elem || ".editor";
|
|
332
349
|
//Default editor is froala
|
|
333
350
|
//return m.froala(req, res, elem);
|
|
334
351
|
//return m.tinymce(req, res, elem);
|
|
335
352
|
//return m.ckeditor(req, res, elem);
|
|
336
353
|
//return m.lexical(req,res,elem);
|
|
337
354
|
|
|
338
|
-
let script =
|
|
339
|
-
let head =
|
|
340
|
-
let end =
|
|
355
|
+
let script = "";
|
|
356
|
+
let head = ``;
|
|
357
|
+
let end = ``;
|
|
341
358
|
|
|
342
|
-
head +=
|
|
343
|
-
|
|
344
|
-
head +=
|
|
345
|
-
|
|
346
|
-
|
|
359
|
+
head +=
|
|
360
|
+
'<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.4.2/css/all.min.css" integrity="sha512-NicFTMUg/LwBeG8C7VG+gC4YiiRtQACl98QdkmfsLy37RzXdkaUAuPyVMND0olPP4Jn8M/ctesGSB2pgUBDRIw==" crossorigin="anonymous" referrerpolicy="no-referrer" />';
|
|
361
|
+
head +=
|
|
362
|
+
'<link href="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/css/froala_editor.pkgd.min.css" rel="stylesheet" type="text/css" />';
|
|
363
|
+
head +=
|
|
364
|
+
'<link href="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/css/froala_style.min.css" rel="stylesheet" type="text/css" />';
|
|
365
|
+
end +=
|
|
366
|
+
'<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/froala-editor@2.9.0/js/froala_editor.pkgd.min.js"></script>';
|
|
367
|
+
script += `$(function() {$("${elem}").froalaEditor({height: 200})});`;
|
|
347
368
|
|
|
348
369
|
return {
|
|
349
370
|
head: head,
|
|
350
371
|
end: end,
|
|
351
372
|
script: script,
|
|
352
|
-
}
|
|
353
|
-
}
|
|
373
|
+
};
|
|
374
|
+
};
|
|
354
375
|
|
|
355
376
|
m.switch = function (req, res, elem, array) {
|
|
356
|
-
elem = elem ||
|
|
357
|
-
let script =
|
|
358
|
-
let head =
|
|
359
|
-
let end =
|
|
360
|
-
|
|
361
|
-
head +=
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
377
|
+
elem = elem || ".switch";
|
|
378
|
+
let script = "";
|
|
379
|
+
let head = ``;
|
|
380
|
+
let end = ``;
|
|
381
|
+
|
|
382
|
+
head +=
|
|
383
|
+
'<link href="/modules/bootstrap-switch/bootstrap-switch.css" rel="stylesheet" type="text/css" />' +
|
|
384
|
+
newLine;
|
|
385
|
+
end +=
|
|
386
|
+
'<script type="text/javascript" src="/modules/bootstrap-switch/bootstrap-switch.js"></script>' +
|
|
387
|
+
newLine;
|
|
388
|
+
|
|
389
|
+
let labels = "";
|
|
365
390
|
if (Array.isArray(array)) {
|
|
366
|
-
labels = '{offText:"' + array[0] + '", onText:"' + array[1] + '"}'
|
|
391
|
+
labels = '{offText:"' + array[0] + '", onText:"' + array[1] + '"}';
|
|
367
392
|
}
|
|
368
|
-
script += '$("' + elem + '").bootstrapSwitch(' + labels +
|
|
393
|
+
script += '$("' + elem + '").bootstrapSwitch(' + labels + ");" + newLine;
|
|
369
394
|
return {
|
|
370
395
|
head: head,
|
|
371
396
|
end: end,
|
|
372
397
|
script: script,
|
|
373
|
-
}
|
|
374
|
-
}
|
|
398
|
+
};
|
|
399
|
+
};
|
|
375
400
|
|
|
376
401
|
m.switchOld = function (req, res, elem, array) {
|
|
377
|
-
let script =
|
|
378
|
-
let head =
|
|
379
|
-
let end =
|
|
380
|
-
elem = elem ||
|
|
381
|
-
head +=
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
402
|
+
let script = "";
|
|
403
|
+
let head = ``;
|
|
404
|
+
let end = ``;
|
|
405
|
+
elem = elem || ".switch";
|
|
406
|
+
head +=
|
|
407
|
+
'<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">' +
|
|
408
|
+
newLine;
|
|
409
|
+
end +=
|
|
410
|
+
'<script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>' +
|
|
411
|
+
newLine;
|
|
412
|
+
|
|
413
|
+
let labels = "";
|
|
385
414
|
if (Array.isArray(array)) {
|
|
386
|
-
labels = '{off:"' + array[0] + '", on:"' + array[1] + '"}'
|
|
415
|
+
labels = '{off:"' + array[0] + '", on:"' + array[1] + '"}';
|
|
387
416
|
}
|
|
388
|
-
script += `$(function(){$('${elem}').bootstrapToggle(${labels});});${Util.newLine}
|
|
417
|
+
script += `$(function(){$('${elem}').bootstrapToggle(${labels});});${Util.newLine}`;
|
|
389
418
|
|
|
390
419
|
return {
|
|
391
420
|
head: head,
|
|
392
421
|
end: end,
|
|
393
422
|
script: script,
|
|
394
|
-
}
|
|
395
|
-
}
|
|
423
|
+
};
|
|
424
|
+
};
|
|
396
425
|
|
|
397
426
|
m.clockpicker = function (req, res, elem) {
|
|
398
|
-
let script =
|
|
399
|
-
let head =
|
|
400
|
-
let end =
|
|
401
|
-
elem = elem ||
|
|
402
|
-
head +=
|
|
403
|
-
|
|
404
|
-
|
|
427
|
+
let script = "";
|
|
428
|
+
let head = ``;
|
|
429
|
+
let end = ``;
|
|
430
|
+
elem = elem || ".clockpicker";
|
|
431
|
+
head +=
|
|
432
|
+
'<link href="/modules/jquery-clockpicker.min.css" rel="stylesheet" type="text/css" />' +
|
|
433
|
+
newLine;
|
|
434
|
+
end +=
|
|
435
|
+
'<script type="text/javascript" src="/modules/bootstrap-clockpicker.min.js"></script>' +
|
|
436
|
+
newLine;
|
|
437
|
+
script += `$("body").on("click", "${elem}", function(){$(this).clockpicker({donetext: "Done"});});`;
|
|
405
438
|
//end += '$("' + elem + '").clockpicker({donetext: "Done"});' + newLine;
|
|
406
439
|
return {
|
|
407
440
|
head: head,
|
|
408
441
|
end: end,
|
|
409
442
|
script: script,
|
|
410
|
-
}
|
|
411
|
-
}
|
|
443
|
+
};
|
|
444
|
+
};
|
|
412
445
|
|
|
413
446
|
m.number = (req, res, elem) => {
|
|
414
|
-
let script =
|
|
415
|
-
let head =
|
|
416
|
-
let end =
|
|
417
|
-
elem = elem ||
|
|
447
|
+
let script = "";
|
|
448
|
+
let head = ``;
|
|
449
|
+
let end = ``;
|
|
450
|
+
elem = elem || ".number";
|
|
418
451
|
|
|
419
|
-
end +=
|
|
420
|
-
|
|
421
|
-
script +=
|
|
422
|
-
script +=
|
|
452
|
+
end +=
|
|
453
|
+
'<script type="text/javascript" src="/js/jquery-currency.js"></script>';
|
|
454
|
+
script += `$(function () { $(".number").formatCurrencyLive({symbol:"",roundToDecimalPlace :0,digitGroupSymbol :"."}); });`;
|
|
455
|
+
script += `setTimeout(function () { $("body").click();},1000);`;
|
|
456
|
+
script += `$("body").on("click", function(){$(".number").formatCurrencyLive({symbol:"",roundToDecimalPlace :0,digitGroupSymbol :"."});});`;
|
|
423
457
|
|
|
424
458
|
return {
|
|
425
459
|
head: head,
|
|
426
460
|
end: end,
|
|
427
461
|
script: script,
|
|
428
|
-
}
|
|
429
|
-
}
|
|
462
|
+
};
|
|
463
|
+
};
|
|
430
464
|
|
|
431
465
|
m.typeahead = (req, res, table, elem) => {
|
|
432
|
-
let script =
|
|
433
|
-
let head =
|
|
434
|
-
let end =
|
|
435
|
-
elem = elem ||
|
|
436
|
-
end +=
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
let
|
|
466
|
+
let script = "";
|
|
467
|
+
let head = ``;
|
|
468
|
+
let end = ``;
|
|
469
|
+
elem = elem || ".typeahead";
|
|
470
|
+
end +=
|
|
471
|
+
'<script type="text/javascript" src="/modules/typeahead/typeahead.js"></script>' +
|
|
472
|
+
newLine;
|
|
473
|
+
|
|
474
|
+
let elemData = elem.replace(".", "").replace("#", "");
|
|
475
|
+
let element = elem.replace("Typeahead", "");
|
|
476
|
+
let key = element.replace("#", "").replace(".", "");
|
|
441
477
|
// var script using existing cache
|
|
442
478
|
script += `$("body").on("click", "${element}Clear", function(){
|
|
443
479
|
$("${elem}").val("");
|
|
444
480
|
$("${element}").val("");
|
|
445
481
|
$("${element}").change();
|
|
446
|
-
});${Util.newLine}
|
|
482
|
+
});${Util.newLine}`;
|
|
447
483
|
script += `$("${elem}").typeahead({highlight:true,minLength:2,source: function (query, asyncprocess) {
|
|
448
484
|
jQuery.ajax({
|
|
449
485
|
url : "/ztypeahead/${table}/${key}",
|
|
@@ -464,31 +500,33 @@ m.typeahead = (req, res, table, elem) => {
|
|
|
464
500
|
$("${element}").change();
|
|
465
501
|
return item;
|
|
466
502
|
}
|
|
467
|
-
}); ${Util.newLine}
|
|
503
|
+
}); ${Util.newLine}`;
|
|
468
504
|
return {
|
|
469
505
|
head: head,
|
|
470
506
|
end: end,
|
|
471
507
|
script: script,
|
|
472
|
-
}
|
|
473
|
-
}
|
|
508
|
+
};
|
|
509
|
+
};
|
|
474
510
|
|
|
475
511
|
m.typeaheadFile = (req, res, elem, data) => {
|
|
476
|
-
let script =
|
|
477
|
-
let head =
|
|
478
|
-
let end =
|
|
479
|
-
data = data || []
|
|
480
|
-
elem = elem ||
|
|
481
|
-
end +=
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
let
|
|
512
|
+
let script = "";
|
|
513
|
+
let head = ``;
|
|
514
|
+
let end = ``;
|
|
515
|
+
data = data || [];
|
|
516
|
+
elem = elem || ".typeahead";
|
|
517
|
+
end +=
|
|
518
|
+
'<script type="text/javascript" src="/modules/typeahead/typeahead.js"></script>' +
|
|
519
|
+
newLine;
|
|
520
|
+
|
|
521
|
+
let elemData = elem.replace(".", "");
|
|
522
|
+
elemData = elemData.replace("#", "");
|
|
523
|
+
let element = elem.replace("Typeahead", "");
|
|
486
524
|
// var script using existing cache
|
|
487
525
|
script += `$("body").on("click", "${element}Clear", function(){
|
|
488
526
|
$("${elem}").val("");
|
|
489
527
|
$("${element}").val("");
|
|
490
528
|
$("${element}").change();
|
|
491
|
-
});${Util.newLine}
|
|
529
|
+
});${Util.newLine}`;
|
|
492
530
|
script += `$("${elem}").typeahead({highlight: true,minLength:2,source:${elemData}Data, items: 50, displayText: function (item) {
|
|
493
531
|
return item.zname.toString();
|
|
494
532
|
},
|
|
@@ -497,35 +535,83 @@ m.typeaheadFile = (req, res, elem, data) => {
|
|
|
497
535
|
$("${element}").change();
|
|
498
536
|
return item;
|
|
499
537
|
}
|
|
500
|
-
}); ${Util.newLine}
|
|
538
|
+
}); ${Util.newLine}`;
|
|
501
539
|
return {
|
|
502
540
|
head: head,
|
|
503
541
|
end: end,
|
|
504
542
|
script: script,
|
|
505
|
-
}
|
|
506
|
-
}
|
|
543
|
+
};
|
|
544
|
+
};
|
|
507
545
|
|
|
508
546
|
m.custom = (req, res, script, css, src) => {
|
|
509
|
-
src = src ||
|
|
510
|
-
css = css ||
|
|
511
|
-
let head = res.locals.moduleHead
|
|
512
|
-
let end = res.locals.moduleEnd
|
|
547
|
+
src = src || "";
|
|
548
|
+
css = css || "";
|
|
549
|
+
let head = res.locals.moduleHead;
|
|
550
|
+
let end = res.locals.moduleEnd;
|
|
513
551
|
if (script) {
|
|
514
|
-
end +=
|
|
515
|
-
end += script + newLine
|
|
516
|
-
end +=
|
|
552
|
+
end += "<script>" + newLine;
|
|
553
|
+
end += script + newLine;
|
|
554
|
+
end += "</script>" + newLine;
|
|
517
555
|
}
|
|
518
556
|
if (css) {
|
|
519
|
-
head += css
|
|
557
|
+
head += css;
|
|
520
558
|
}
|
|
521
559
|
if (src) {
|
|
522
|
-
end += `<script src="${src}"> ${newLine}
|
|
523
|
-
}
|
|
524
|
-
res.locals.moduleHead = head
|
|
525
|
-
res.locals.moduleEnd = end
|
|
526
|
-
}
|
|
560
|
+
end += `<script src="${src}"> ${newLine}`;
|
|
561
|
+
}
|
|
562
|
+
res.locals.moduleHead = head;
|
|
563
|
+
res.locals.moduleEnd = end;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
//dropbox view
|
|
567
|
+
m.dropboxview = (req, res) => {
|
|
568
|
+
let script = ``;
|
|
569
|
+
let head = ``;
|
|
570
|
+
let end = ``;
|
|
571
|
+
script +=
|
|
572
|
+
`$(()=>{
|
|
573
|
+
$(".zdropbox-view").each(function (index, item) {
|
|
574
|
+
let dropboxLength = $(".zdropbox-view").length || 0;
|
|
575
|
+
ajaxPost('/zdropbox-file/' + index, {
|
|
576
|
+
fileName: $(this).attr('data-name'),
|
|
577
|
+
table: $(this).attr('data-table'),
|
|
578
|
+
field: $(this).attr('data-field'),
|
|
579
|
+
}, function (result) {
|
|
580
|
+
$(item).attr("src", result.link)
|
|
581
|
+
$(item).attr('data-link', result.link);
|
|
582
|
+
if (+result.index == (+dropboxLength - 1)) {
|
|
583
|
+
setTimeout(() => modaldropbox(),1000);
|
|
584
|
+
}
|
|
585
|
+
})
|
|
586
|
+
})
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
function modaldropbox() {
|
|
590
|
+
$(".zdropbox-view").each(function () {
|
|
591
|
+
let ext = $(this).attr('data-ext');
|
|
592
|
+
if (ext == "gif" || ext == "png" || ext == "jpeg" || ext == "jpg" || ext == "bmp" || ext == "webp" || ext == "jiff" || ext == "svg" || ext == "avif") {
|
|
593
|
+
$(this).on("click", function () {
|
|
594
|
+
$(".zimage-modal").attr('src', $(this).attr('data-link')).attr('data-name', $(this).attr('data-name'));
|
|
595
|
+
$("#zmodal-image").modal("show");
|
|
596
|
+
})
|
|
597
|
+
} else {
|
|
598
|
+
let file = nonImagesTypeObject[ext] || 'file.png';
|
|
599
|
+
$(this).attr("src", "/img/" + file);
|
|
600
|
+
$(this).on("click", function () {
|
|
601
|
+
window.open($(this).attr('data-link'), '_blank');
|
|
602
|
+
})
|
|
603
|
+
}
|
|
604
|
+
})
|
|
605
|
+
}` + newLine;
|
|
527
606
|
|
|
528
|
-
|
|
607
|
+
return {
|
|
608
|
+
head: head,
|
|
609
|
+
end: end,
|
|
610
|
+
script: script,
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
m.script = (req, res, table) => {};
|
|
529
615
|
|
|
530
616
|
/*
|
|
531
617
|
add scrip code in the body html
|
|
@@ -534,128 +620,146 @@ m.script = (req, res, table) => {}
|
|
|
534
620
|
|
|
535
621
|
type : script / css
|
|
536
622
|
*/
|
|
537
|
-
m.addScript = (req, res, contentScript, at =
|
|
623
|
+
m.addScript = (req, res, contentScript, at = "end", type = "script") => {
|
|
538
624
|
if (contentScript) {
|
|
539
|
-
let generateId =
|
|
540
|
-
let tagOpen =
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
content
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
625
|
+
let generateId = "app_" + Util.generate(6);
|
|
626
|
+
let tagOpen =
|
|
627
|
+
type == "script"
|
|
628
|
+
? `<script id="${generateId}">`
|
|
629
|
+
: '<style type="text/css">';
|
|
630
|
+
let tagClose = type == "script" ? "</script>" : "</style>";
|
|
631
|
+
let content = at == "end" ? res.locals.moduleEnd : res.locals.moduleHead;
|
|
632
|
+
content += tagOpen + newLine;
|
|
633
|
+
content += contentScript + newLine;
|
|
634
|
+
content += tagClose + newLine;
|
|
635
|
+
|
|
636
|
+
if (at == "end") {
|
|
637
|
+
res.locals.moduleEnd = content;
|
|
638
|
+
} else res.locals.moduleHead = content;
|
|
639
|
+
}
|
|
640
|
+
};
|
|
552
641
|
|
|
553
642
|
m.addModule = (req, res, content, isModuleHead = false) => {
|
|
554
|
-
let moduleContent = isModuleHead
|
|
555
|
-
|
|
643
|
+
let moduleContent = isModuleHead
|
|
644
|
+
? res.locals.moduleHead
|
|
645
|
+
: res.locals.moduleEnd;
|
|
646
|
+
moduleContent += content;
|
|
556
647
|
if (isModuleHead) {
|
|
557
|
-
res.locals.moduleHead = moduleContent
|
|
648
|
+
res.locals.moduleHead = moduleContent;
|
|
558
649
|
} else {
|
|
559
|
-
res.locals.moduleEnd = moduleContent
|
|
650
|
+
res.locals.moduleEnd = moduleContent;
|
|
560
651
|
}
|
|
561
|
-
}
|
|
652
|
+
};
|
|
562
653
|
|
|
563
654
|
m.highchart = async (req, res, obj) => {
|
|
564
|
-
obj = obj || {}
|
|
565
|
-
let head = res.locals.moduleHead
|
|
566
|
-
let end = res.locals.moduleEnd
|
|
567
|
-
if (end.indexOf(
|
|
568
|
-
end +=
|
|
655
|
+
obj = obj || {};
|
|
656
|
+
let head = res.locals.moduleHead;
|
|
657
|
+
let end = res.locals.moduleEnd;
|
|
658
|
+
if (end.indexOf("highcharts") < 0) {
|
|
659
|
+
end +=
|
|
660
|
+
'<script src="https://code.highcharts.com/highcharts.js"></script>' +
|
|
661
|
+
newLine;
|
|
569
662
|
}
|
|
570
663
|
|
|
571
664
|
if (!Util.isEmptyObject(obj)) {
|
|
572
|
-
const highcharts = require(
|
|
573
|
-
end +=
|
|
574
|
-
end += await highcharts.build(obj)
|
|
575
|
-
end +=
|
|
665
|
+
const highcharts = require("./highcharts");
|
|
666
|
+
end += "<script>" + newLine;
|
|
667
|
+
end += await highcharts.build(obj);
|
|
668
|
+
end += "</script>" + newLine;
|
|
576
669
|
}
|
|
577
670
|
|
|
578
|
-
res.locals.moduleHead = head
|
|
579
|
-
res.locals.moduleEnd = end
|
|
580
|
-
}
|
|
671
|
+
res.locals.moduleHead = head;
|
|
672
|
+
res.locals.moduleEnd = end;
|
|
673
|
+
};
|
|
581
674
|
|
|
582
675
|
//build auto js and css based on function type
|
|
583
676
|
m.build = (req, res, objData) => {
|
|
584
|
-
let head = res.locals.moduleHead
|
|
585
|
-
let end = res.locals.moduleEnd
|
|
677
|
+
let head = res.locals.moduleHead;
|
|
678
|
+
let end = res.locals.moduleEnd;
|
|
586
679
|
|
|
587
|
-
head += objData.head
|
|
588
|
-
end += objData.end
|
|
680
|
+
head += objData.head;
|
|
681
|
+
end += objData.end;
|
|
589
682
|
if (objData.script) {
|
|
590
|
-
end += `<script>${objData.script}</script
|
|
683
|
+
end += `<script>${objData.script}</script>`;
|
|
591
684
|
}
|
|
592
|
-
res.locals.moduleHead = head
|
|
593
|
-
res.locals.moduleEnd = end
|
|
594
|
-
}
|
|
685
|
+
res.locals.moduleHead = head;
|
|
686
|
+
res.locals.moduleEnd = end;
|
|
687
|
+
};
|
|
595
688
|
|
|
596
689
|
m.tableForm = (req, res, name, table) => {
|
|
597
|
-
let head = res.locals.moduleHead
|
|
598
|
-
let end = res.locals.moduleEnd
|
|
599
|
-
res.locals.moduleHead = head
|
|
600
|
-
res.locals.moduleEnd = end
|
|
601
|
-
}
|
|
690
|
+
let head = res.locals.moduleHead;
|
|
691
|
+
let end = res.locals.moduleEnd;
|
|
692
|
+
res.locals.moduleHead = head;
|
|
693
|
+
res.locals.moduleEnd = end;
|
|
694
|
+
};
|
|
602
695
|
|
|
603
696
|
m.selectYear = (req, res, elem, val, startYear, endYear) => {
|
|
604
|
-
let dt = new Date()
|
|
605
|
-
endYear = endYear || dt.getFullYear()
|
|
606
|
-
val = val ||
|
|
607
|
-
var options =
|
|
697
|
+
let dt = new Date();
|
|
698
|
+
endYear = endYear || dt.getFullYear();
|
|
699
|
+
val = val || "";
|
|
700
|
+
var options = "";
|
|
608
701
|
for (var i = endYear; i >= startYear; i--) {
|
|
609
|
-
var selected = i == val ?
|
|
610
|
-
options += `<option value="${i}" ${selected}>${i}</option
|
|
702
|
+
var selected = i == val ? " selected " : "";
|
|
703
|
+
options += `<option value="${i}" ${selected}>${i}</option>`;
|
|
611
704
|
}
|
|
612
|
-
let end = res.locals.moduleEnd
|
|
613
|
-
end +=
|
|
614
|
-
end += `$("${elem}").html('${options}')
|
|
615
|
-
end +=
|
|
616
|
-
res.locals.moduleEnd = end
|
|
617
|
-
}
|
|
705
|
+
let end = res.locals.moduleEnd;
|
|
706
|
+
end += "<script>" + newLine;
|
|
707
|
+
end += `$("${elem}").html('${options}')`;
|
|
708
|
+
end += "</script>" + newLine;
|
|
709
|
+
res.locals.moduleEnd = end;
|
|
710
|
+
};
|
|
618
711
|
|
|
619
712
|
//https://highlightjs.org/usage/
|
|
620
713
|
m.highlight = (req, res, elem) => {
|
|
621
|
-
elem = elem ||
|
|
622
|
-
let head = res.locals.moduleHead
|
|
623
|
-
let end = res.locals.moduleEnd
|
|
624
|
-
if (head.indexOf(
|
|
625
|
-
head +=
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
714
|
+
elem = elem || ".codes";
|
|
715
|
+
let head = res.locals.moduleHead;
|
|
716
|
+
let end = res.locals.moduleEnd;
|
|
717
|
+
if (head.indexOf("highlight") < 0) {
|
|
718
|
+
head +=
|
|
719
|
+
'<link rel="stylesheet" href="/modules/highlight/default.min.css"> ' +
|
|
720
|
+
newLine;
|
|
721
|
+
end +=
|
|
722
|
+
'<script src="/modules/highlight/highlight.min.js"></script>' + newLine;
|
|
723
|
+
}
|
|
724
|
+
end +=
|
|
725
|
+
'<script>$(function(){ document.querySelectorAll("' +
|
|
726
|
+
elem +
|
|
727
|
+
'").forEach((block) => {hljs.highlightBlock(block);}); })</script>' +
|
|
728
|
+
newLine;
|
|
729
|
+
res.locals.moduleHead = head;
|
|
730
|
+
res.locals.moduleEnd = end;
|
|
731
|
+
};
|
|
632
732
|
|
|
633
733
|
//https://developer.snapappointments.com/bootstrap-select/
|
|
634
734
|
m.selectpicker = function (req, res, elem) {
|
|
635
|
-
elem = elem ||
|
|
636
|
-
let head = res.locals.moduleHead
|
|
637
|
-
let end = res.locals.moduleEnd
|
|
638
|
-
if (head.indexOf(
|
|
639
|
-
head +=
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
735
|
+
elem = elem || ".selectpicker";
|
|
736
|
+
let head = res.locals.moduleHead;
|
|
737
|
+
let end = res.locals.moduleEnd;
|
|
738
|
+
if (head.indexOf("bootstrap-select") < 0) {
|
|
739
|
+
head +=
|
|
740
|
+
'<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">' +
|
|
741
|
+
newLine;
|
|
742
|
+
end +=
|
|
743
|
+
'<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>' +
|
|
744
|
+
newLine;
|
|
745
|
+
end += `<script>$(function () {$('${elem}').selectpicker();});</script>${newLine}`;
|
|
746
|
+
}
|
|
747
|
+
res.locals.moduleHead = head;
|
|
748
|
+
res.locals.moduleEnd = end;
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
m.slugHTML = (req, res, content, at = "end") => {
|
|
648
752
|
if (content) {
|
|
649
|
-
let head = res.locals.moduleHead
|
|
650
|
-
let end = res.locals.moduleEnd
|
|
651
|
-
if (at ==
|
|
652
|
-
end += content
|
|
653
|
-
res.locals.moduleEnd = end
|
|
753
|
+
let head = res.locals.moduleHead;
|
|
754
|
+
let end = res.locals.moduleEnd;
|
|
755
|
+
if (at == "end") {
|
|
756
|
+
end += content;
|
|
757
|
+
res.locals.moduleEnd = end;
|
|
654
758
|
} else {
|
|
655
|
-
head += content
|
|
656
|
-
res.locals.moduleHead = head
|
|
759
|
+
head += content;
|
|
760
|
+
res.locals.moduleHead = head;
|
|
657
761
|
}
|
|
658
762
|
}
|
|
659
|
-
}
|
|
763
|
+
};
|
|
660
764
|
|
|
661
|
-
module.exports = m
|
|
765
|
+
module.exports = m;
|
package/lib/zAppRouter.js
CHANGED
|
@@ -2113,12 +2113,12 @@ router.post("/zdropbox-file/:index", handleTokenRefresh, async (req, res) => {
|
|
|
2113
2113
|
router.post("/zdropbox-remove/", handleTokenRefresh, async (req, res) => {
|
|
2114
2114
|
try {
|
|
2115
2115
|
let body = req.body;
|
|
2116
|
-
console.log(body);
|
|
2116
|
+
//console.log(body);
|
|
2117
2117
|
const userId = res.locals.userId;
|
|
2118
2118
|
const fileName = body.file;
|
|
2119
2119
|
let cname = body.cname.replace("ZUSER___ID", userId);
|
|
2120
2120
|
let cacheName = cname;
|
|
2121
|
-
console.log(cacheName);
|
|
2121
|
+
//console.log(cacheName);
|
|
2122
2122
|
let splits = cname.split("__");
|
|
2123
2123
|
let table = splits[2];
|
|
2124
2124
|
let field = splits[3];
|
|
@@ -2127,19 +2127,27 @@ router.post("/zdropbox-remove/", handleTokenRefresh, async (req, res) => {
|
|
|
2127
2127
|
await ensureFolder(dir);
|
|
2128
2128
|
const filePath = `${dir}/${fileName}`;
|
|
2129
2129
|
let arr = [];
|
|
2130
|
+
if (type != "create") {
|
|
2131
|
+
cacheName = cacheName + "__remove";
|
|
2132
|
+
}
|
|
2130
2133
|
if (myCache.has(cacheName)) {
|
|
2131
2134
|
arr = myCache.get(cacheName);
|
|
2132
2135
|
}
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2136
|
+
//console.log(cacheName)
|
|
2137
|
+
if (type == "create") {
|
|
2138
|
+
try {
|
|
2139
|
+
await dbx.filesDeleteV2({
|
|
2140
|
+
path: filePath,
|
|
2141
|
+
});
|
|
2142
|
+
arr = Util.arrayDelete(arr, body.file);
|
|
2143
|
+
myCache.set(cacheName, arr);
|
|
2144
|
+
} catch (e) {
|
|
2145
|
+
console.log(e);
|
|
2146
|
+
}
|
|
2147
|
+
} else {
|
|
2148
|
+
arr.push(body.file);
|
|
2138
2149
|
myCache.set(cacheName, arr);
|
|
2139
|
-
} catch (e) {
|
|
2140
|
-
console.log(e);
|
|
2141
2150
|
}
|
|
2142
|
-
|
|
2143
2151
|
res.json({ success: true });
|
|
2144
2152
|
} catch (error) {
|
|
2145
2153
|
console.error("Error deleting file:", error);
|
package/lib/zRoute.js
CHANGED
|
@@ -3344,6 +3344,7 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
|
|
|
3344
3344
|
let forms = zRoute.viewForm(req, res, MYMODEL, relations, data);
|
|
3345
3345
|
let hasEditors = false;
|
|
3346
3346
|
let hasLocation = false;
|
|
3347
|
+
let hasDropbox = false;
|
|
3347
3348
|
let mapKey = "";
|
|
3348
3349
|
for (let key in MYMODEL.widgets) {
|
|
3349
3350
|
if (MYMODEL.widgets[key].name == "editor") {
|
|
@@ -3353,6 +3354,9 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
|
|
|
3353
3354
|
hasLocation = true;
|
|
3354
3355
|
mapKey = key;
|
|
3355
3356
|
}
|
|
3357
|
+
if (MYMODEL.widgets[key].name == "dropbox") {
|
|
3358
|
+
hasDropbox = true;
|
|
3359
|
+
}
|
|
3356
3360
|
}
|
|
3357
3361
|
if (hasEditors) {
|
|
3358
3362
|
moduleLib.build(req, res, moduleLib.editor(req, res));
|
|
@@ -3360,6 +3364,9 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
|
|
|
3360
3364
|
if (hasLocation) {
|
|
3361
3365
|
moduleLib.build(req, res, moduleLib.location(req, res, mapKey));
|
|
3362
3366
|
}
|
|
3367
|
+
if (hasDropbox) {
|
|
3368
|
+
moduleLib.build(req, res, moduleLib.dropboxview(req, res));
|
|
3369
|
+
}
|
|
3363
3370
|
//add tabs role
|
|
3364
3371
|
if (MYMODEL.hasOwnProperty("hasTabs") && MYMODEL.hasTabs) {
|
|
3365
3372
|
let script = "";
|
|
@@ -3635,6 +3642,14 @@ zRoute.viewForm = (
|
|
|
3635
3642
|
obj[key].key = key;
|
|
3636
3643
|
obj[key].dataId = data.id || "";
|
|
3637
3644
|
break;
|
|
3645
|
+
|
|
3646
|
+
case "dropbox":
|
|
3647
|
+
obj[key].type = "dropboxview";
|
|
3648
|
+
obj[key].value = data[key] || [];
|
|
3649
|
+
obj[key].table = MYMODEL.table;
|
|
3650
|
+
obj[key].key = key;
|
|
3651
|
+
obj[key].dataId = data.id || "";
|
|
3652
|
+
break;
|
|
3638
3653
|
}
|
|
3639
3654
|
}
|
|
3640
3655
|
//forms.build[key] = cForm.build(obj[key]);
|
|
@@ -4335,8 +4350,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4335
4350
|
imageElement.setAttribute('data-link', result.link);
|
|
4336
4351
|
$(imageElement).attr('id', result.id.content_hash);
|
|
4337
4352
|
$(imageElement).find("img").attr("src", result.link);
|
|
4338
|
-
if(+result.index == (dropbox_${item}_data.length - 1)
|
|
4339
|
-
modaldropbox();
|
|
4353
|
+
if(+result.index == (dropbox_${item}_data.length - 1)) {
|
|
4354
|
+
setTimeout(() => modaldropbox(),1000);
|
|
4340
4355
|
}
|
|
4341
4356
|
})
|
|
4342
4357
|
})
|
|
@@ -4816,6 +4831,7 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4816
4831
|
let hasImages = false;
|
|
4817
4832
|
let tables = [];
|
|
4818
4833
|
let tableFields = {};
|
|
4834
|
+
let movDropboxArr = [];
|
|
4819
4835
|
for (let key in MYMODEL.widgets) {
|
|
4820
4836
|
if (MYMODEL.widgets[key].name == "table") {
|
|
4821
4837
|
tableFields[key] = [];
|
|
@@ -4858,10 +4874,6 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4858
4874
|
data[key] = Util.array_to_jsonb(newArr);
|
|
4859
4875
|
}
|
|
4860
4876
|
} else if (MYMODEL.widgets[key].name === "dropbox") {
|
|
4861
|
-
//console.log('has dropbox')
|
|
4862
|
-
let path_src = `/temps/${MYMODEL.table}/${key}/${userId}`;
|
|
4863
|
-
let path_dest = `/${MYMODEL.table}/${key}`;
|
|
4864
|
-
|
|
4865
4877
|
// Initialize Dropbox client
|
|
4866
4878
|
let dbx = new Dropbox({
|
|
4867
4879
|
accessToken: process.env.DROPBOX_ACCESS_TOKEN,
|
|
@@ -4870,16 +4882,18 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4870
4882
|
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
|
|
4871
4883
|
fetch: fetch,
|
|
4872
4884
|
});
|
|
4873
|
-
|
|
4885
|
+
//console.log('has dropbox')
|
|
4886
|
+
let dir1 = `/${MYMODEL.table}/${key}`;
|
|
4887
|
+
let dir2 = `/temps/${MYMODEL.table}/${key}/${userId}`;
|
|
4874
4888
|
try {
|
|
4875
4889
|
await dbx.filesCreateFolderV2({
|
|
4876
|
-
path:
|
|
4890
|
+
path: dir1,
|
|
4877
4891
|
autorename: false,
|
|
4878
4892
|
});
|
|
4879
4893
|
} catch (error) {
|
|
4880
4894
|
if (error.status !== 409) {
|
|
4881
4895
|
// 409 means folder already exists
|
|
4882
|
-
throw error;
|
|
4896
|
+
//throw error;
|
|
4883
4897
|
}
|
|
4884
4898
|
}
|
|
4885
4899
|
let name = `dropbox__${userId}__${MYMODEL.table}__${key}__${whereData.id}`;
|
|
@@ -4887,49 +4901,75 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
|
|
|
4887
4901
|
let arr = myCache.get(name) || [];
|
|
4888
4902
|
let newArr = [];
|
|
4889
4903
|
let time = new Date().getTime();
|
|
4890
|
-
|
|
4891
|
-
//todo
|
|
4892
|
-
//jika item tidak ada di dropbox
|
|
4904
|
+
for (const item of arr) {
|
|
4893
4905
|
try {
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4906
|
+
//check in dir1
|
|
4907
|
+
let filepath1 = `${dir1}/${item}`;
|
|
4908
|
+
// Get the file metadata to ensure we have the correct path
|
|
4909
|
+
const metadata = await dbx.filesGetMetadata({
|
|
4910
|
+
path: filepath1,
|
|
4911
|
+
});
|
|
4912
|
+
const finalPath = metadata.result.path_display;
|
|
4913
|
+
if (finalPath) {
|
|
4914
|
+
newArr.push(item);
|
|
4915
|
+
}
|
|
4916
|
+
} catch (e) {
|
|
4917
|
+
//check in dir2 temp folder
|
|
4918
|
+
try {
|
|
4919
|
+
let filepath2 = `${dir2}/${item}`;
|
|
4920
|
+
const metadata = await dbx.filesGetMetadata({
|
|
4921
|
+
path: filepath2,
|
|
4922
|
+
});
|
|
4923
|
+
const finalPath = metadata.result.path_display;
|
|
4924
|
+
if (finalPath) {
|
|
4925
|
+
let newItem = Util.cleanString(time + item);
|
|
4926
|
+
newArr.push(newItem);
|
|
4927
|
+
movDropboxArr.push({
|
|
4928
|
+
from_path: `${dir2}/${item}`,
|
|
4929
|
+
to_path: `${dir1}/${newItem}`,
|
|
4930
|
+
});
|
|
4931
|
+
}
|
|
4932
|
+
} catch (e) {
|
|
4933
|
+
console.log(e);
|
|
4900
4934
|
}
|
|
4901
|
-
} else {
|
|
4902
|
-
newArr.push(item);
|
|
4903
4935
|
}
|
|
4904
|
-
}
|
|
4936
|
+
}
|
|
4905
4937
|
data[key] = Util.array_to_jsonb(newArr);
|
|
4906
4938
|
}
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
let
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4939
|
+
myCache.del(name);
|
|
4940
|
+
|
|
4941
|
+
let removeName = name + "__remove";
|
|
4942
|
+
if (myCache.has(removeName)) {
|
|
4943
|
+
let removesArr = myCache.get(removeName) || [];
|
|
4944
|
+
for (const item of removesArr) {
|
|
4945
|
+
//hapus item di folder dir1 atau dir2
|
|
4946
|
+
try {
|
|
4947
|
+
await dbx.filesDeleteV2({
|
|
4948
|
+
path: `${dir1}/${item}`,
|
|
4949
|
+
});
|
|
4950
|
+
} catch (e) {
|
|
4951
|
+
console.log(e);
|
|
4916
4952
|
try {
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
from_path: `${path_src}/${item}`,
|
|
4920
|
-
to_path: `${path_dest}/${newItem}`,
|
|
4953
|
+
await dbx.filesDeleteV2({
|
|
4954
|
+
path: `${dir2}/${item}`,
|
|
4921
4955
|
});
|
|
4922
|
-
newArr.push(newItem);
|
|
4923
4956
|
} catch (e) {
|
|
4924
4957
|
console.log(e);
|
|
4925
4958
|
}
|
|
4926
|
-
}
|
|
4927
|
-
data[key] = Util.array_to_jsonb(newArr);
|
|
4959
|
+
}
|
|
4928
4960
|
}
|
|
4929
|
-
}
|
|
4930
|
-
myCache.del(
|
|
4961
|
+
}
|
|
4962
|
+
myCache.del(removeName);
|
|
4931
4963
|
}
|
|
4932
4964
|
}
|
|
4965
|
+
|
|
4966
|
+
//dropbox
|
|
4967
|
+
if (movDropboxArr.length > 0) {
|
|
4968
|
+
setTimeout(function () {
|
|
4969
|
+
zRoute.moveDropbox(movDropboxArr);
|
|
4970
|
+
}, 3000);
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4933
4973
|
let result = await connection.result({
|
|
4934
4974
|
table: MYMODEL.table,
|
|
4935
4975
|
where: whereData,
|