@ntlab/ntjs-repo 3.0.0

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.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2023-2025 Toha <tohenk@yahoo.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ * of the Software, and to permit persons to whom the Software is furnished to do
11
+ * so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const { ScriptRepository, ScriptManager } = require('@ntlab/ntjs');
26
+ const JQuery = ScriptManager.require('JQuery');
27
+
28
+ /**
29
+ * Bootstrap/Dialog/Confirm script repository.
30
+ */
31
+ class Confirm extends JQuery {
32
+
33
+ initialize() {
34
+ this.name = 'Confirm';
35
+ this.position = ScriptRepository.POSITION_FIRST;
36
+ this.addDependencies(['JQuery/Define', 'Bootstrap/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ const yes = this.translate('Yes');
41
+ const no = this.translate('No');
42
+
43
+ return `
44
+ $.define('ntdlg', {
45
+ confirm(id, title, message, icon, cb_yes, cb_no) {
46
+ if (typeof icon === 'function') {
47
+ cb_no = cb_yes;
48
+ cb_yes = icon;
49
+ icon = undefined;
50
+ }
51
+ icon = icon || $.ntdlg.ICON_QUESTION;
52
+ $.ntdlg.dialog(id, title, message, icon, {
53
+ '${yes}': {
54
+ icon: $.ntdlg.BTN_ICON_OK,
55
+ handler() {
56
+ $.ntdlg.close($(this));
57
+ if (typeof cb_yes === 'function') {
58
+ cb_yes();
59
+ }
60
+ }
61
+ },
62
+ '${no}': {
63
+ icon: $.ntdlg.BTN_ICON_CANCEL,
64
+ handler() {
65
+ $.ntdlg.close($(this));
66
+ if (typeof cb_no === 'function') {
67
+ cb_no();
68
+ }
69
+ }
70
+ }
71
+ });
72
+ }
73
+ }, true);
74
+ `;
75
+ }
76
+
77
+ static instance() {
78
+ return new this();
79
+ }
80
+ }
81
+
82
+ module.exports = Confirm;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2023-2025 Toha <tohenk@yahoo.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ * of the Software, and to permit persons to whom the Software is furnished to do
11
+ * so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const { ScriptRepository, ScriptManager } = require('@ntlab/ntjs');
26
+ const JQuery = ScriptManager.require('JQuery');
27
+
28
+ /**
29
+ * Bootstrap/Dialog/Input script repository.
30
+ */
31
+ class Input extends JQuery {
32
+
33
+ initialize() {
34
+ this.name = 'Input';
35
+ this.position = ScriptRepository.POSITION_FIRST;
36
+ this.addDependencies(['JQuery/Define', 'Bootstrap/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ const ok = this.translate('OK');
41
+ const cancel = this.translate('Cancel');
42
+
43
+ return `
44
+ $.define('ntdlg', {
45
+ input(id, title, message, value, size, icon, callback) {
46
+ if (typeof size === 'function') {
47
+ callback = size;
48
+ size = null;
49
+ } else if (typeof icon === 'function') {
50
+ callback = icon;
51
+ icon = null;
52
+ }
53
+ size = size || 50;
54
+ icon = icon || $.ntdlg.ICON_INPUT;
55
+ message = '<p class="mb-1">' + message + '</p><input class="form-control focused" type="text" value="' + value + '" size="' + size + '">'
56
+ $.ntdlg.dialog(id, title, message, icon, {
57
+ '${ok}': {
58
+ icon: $.ntdlg.BTN_ICON_OK,
59
+ handler() {
60
+ const dlg = $(this);
61
+ $.ntdlg.close(dlg);
62
+ if (typeof callback === 'function') {
63
+ const v = dlg.find('input[type=text]').val();
64
+ callback(v);
65
+ }
66
+ }
67
+ },
68
+ '${cancel}': {
69
+ icon: $.ntdlg.BTN_ICON_CANCEL,
70
+ handler() {
71
+ $.ntdlg.close($(this));
72
+ }
73
+ }
74
+ });
75
+ }
76
+ }, true);
77
+ `;
78
+ }
79
+
80
+ static instance() {
81
+ return new this();
82
+ }
83
+ }
84
+
85
+ module.exports = Input;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2023-2025 Toha <tohenk@yahoo.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ * of the Software, and to permit persons to whom the Software is furnished to do
11
+ * so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const { ScriptRepository, ScriptManager } = require('@ntlab/ntjs');
26
+ const JQuery = ScriptManager.require('JQuery');
27
+
28
+ /**
29
+ * Bootstrap/Dialog/Message script repository.
30
+ */
31
+ class Message extends JQuery {
32
+
33
+ initialize() {
34
+ this.name = 'Message';
35
+ this.position = ScriptRepository.POSITION_FIRST;
36
+ this.addDependencies(['JQuery/Define', 'Bootstrap/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ const ok = this.translate('OK');
41
+
42
+ return `
43
+ $.define('ntdlg', {
44
+ message(id, title, message, icon) {
45
+ $.ntdlg.dialog(id, title, message, icon, {
46
+ '${ok}': {
47
+ icon: $.ntdlg.BTN_ICON_OK,
48
+ handler() {
49
+ $.ntdlg.close($(this));
50
+ }
51
+ }
52
+ });
53
+ }
54
+ }, true);
55
+ `;
56
+ }
57
+
58
+ static instance() {
59
+ return new this();
60
+ }
61
+ }
62
+
63
+ module.exports = Message;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2023-2025 Toha <tohenk@yahoo.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ * this software and associated documentation files (the "Software"), to deal in
8
+ * the Software without restriction, including without limitation the rights to
9
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ * of the Software, and to permit persons to whom the Software is furnished to do
11
+ * so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ const { ScriptRepository, ScriptManager } = require('@ntlab/ntjs');
26
+ const JQuery = ScriptManager.require('JQuery');
27
+
28
+ /**
29
+ * Bootstrap/Dialog/Wait script repository.
30
+ */
31
+ class Wait extends JQuery {
32
+
33
+ initialize() {
34
+ this.name = 'Wait';
35
+ this.position = ScriptRepository.POSITION_FIRST;
36
+ this.addDependencies(['JQuery/Define', 'Bootstrap/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ const message = this.translate('Loading...');
41
+ const title = this.translate('Please wait');
42
+
43
+ return `
44
+ $.define('ntdlg', {
45
+ waitdlg: {
46
+ id: 'wdialog',
47
+ getDlg(create) {
48
+ const self = this;
49
+ let dlg = $('#' + self.id);
50
+ if (dlg.length) {
51
+ self.dlg = dlg;
52
+ } else {
53
+ if (create) {
54
+ const spinner = $.ntdlg.spinnerTmpl;
55
+ const content =
56
+ '<div id="' + self.id + '" class="modal fade" tabindex="-1">' +
57
+ ' <div class="modal-dialog modal-dialog-centered">' +
58
+ ' <div class="modal-content">' +
59
+ ' <div class="modal-header">${title}</div>' +
60
+ ' <div class="modal-body">' +
61
+ ' <div class="d-flex">' +
62
+ ' <div class="flex-shrink-0 icon">' + spinner + '</div>' +
63
+ ' <div class="flex-grow-1 ms-3">' +
64
+ ' <div class="msg">${message}</div>' +
65
+ ' </div>' +
66
+ ' </div>' +
67
+ ' </div>' +
68
+ ' </div>' +
69
+ ' </div>' +
70
+ '</div>';
71
+ $(document.body).append(content);
72
+ dlg = $('#' + self.id);
73
+ dlg.on('shown.bs.modal', function(e) {
74
+ const dlg = $(this);
75
+ dlg.addClass('active');
76
+ if (dlg.hasClass('dismiss')) {
77
+ setTimeout(function() {
78
+ $.ntdlg.close(dlg);
79
+ }, 500);
80
+ }
81
+ });
82
+ dlg.on('hidden.bs.modal', function(e) {
83
+ const dlg = $(this);
84
+ dlg.removeClass('active');
85
+ });
86
+ $.ntdlg._create(dlg[0], {keyboard: false});
87
+ self.dlg = dlg;
88
+ }
89
+ }
90
+ },
91
+ isActive() {
92
+ const self = this;
93
+ self.getDlg();
94
+ if (self.dlg) {
95
+ return self.dlg.hasClass('show') ? true : false;
96
+ }
97
+ },
98
+ show(msg) {
99
+ const self = this;
100
+ self.close();
101
+ self.getDlg(true);
102
+ if (msg) {
103
+ self.dlg.find('.modal-body .msg').html(msg);
104
+ }
105
+ self.dlg.removeClass('dismiss');
106
+ $.ntdlg.show(self.dlg);
107
+ },
108
+ close() {
109
+ const self = this;
110
+ self.getDlg();
111
+ if (self.dlg) {
112
+ if (self.dlg.hasClass('active')) {
113
+ $.ntdlg.close(self.dlg);
114
+ } else {
115
+ self.dlg.addClass('dismiss');
116
+ }
117
+ }
118
+ }
119
+ },
120
+ wait(message) {
121
+ if (message) {
122
+ $.ntdlg.waitdlg.show(message);
123
+ } else {
124
+ $.ntdlg.waitdlg.close();
125
+ }
126
+ }
127
+ }, true);
128
+ `;
129
+ }
130
+
131
+ static instance() {
132
+ return new this();
133
+ }
134
+ }
135
+
136
+ module.exports = Wait;