@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,79 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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
+ * SemanticUI/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(['SemanticUI/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.define('ntdlg', {
42
+ confirm(id, title, message, icon, cb_yes, cb_no) {
43
+ if (typeof icon === 'function') {
44
+ cb_no = cb_yes;
45
+ cb_yes = icon;
46
+ icon = undefined;
47
+ }
48
+ icon = icon || $.ntdlg.ICON_QUESTION;
49
+ const dlg = $.ntdlg.dialog(id, title, message, icon, {
50
+ yes: {
51
+ type: 'green approve',
52
+ caption: '<i class="check icon"></i>${this.translate('Yes')}',
53
+ handler() {
54
+ if (typeof cb_yes === 'function') {
55
+ cb_yes();
56
+ }
57
+ }
58
+ },
59
+ no: {
60
+ type: 'red deny',
61
+ caption: '<i class="times icon"></i>${this.translate('No')}',
62
+ handler() {
63
+ if (typeof cb_no === 'function') {
64
+ cb_no();
65
+ }
66
+ }
67
+ }
68
+ });
69
+ }
70
+ }, true);
71
+ `;
72
+ }
73
+
74
+ static instance() {
75
+ return new this();
76
+ }
77
+ }
78
+
79
+ module.exports = Confirm;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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
+ * SemanticUI/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(['SemanticUI/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.define('ntdlg', {
42
+ input(id, title, message, value, icon, callback) {
43
+ if (typeof icon === 'function') {
44
+ callback = icon;
45
+ icon = null;
46
+ }
47
+ icon = icon || $.ntdlg.ICON_INPUT;
48
+ message =
49
+ '<form class="ui container form">' +
50
+ ' <div class="field">' +
51
+ ' <label>' + message + '</label>' +
52
+ ' <input type="text" value="' + value + '">' +
53
+ ' </div>' +
54
+ '</form>';
55
+ const dlg = $.ntdlg.dialog(id, title, message, icon, {
56
+ okay: {
57
+ type: 'green approve',
58
+ caption: '<i class="check icon"></i>${this.translate('Ok')}',
59
+ handler() {
60
+ const v = dlg.find('input[type=text]').val();
61
+ return callback(v);
62
+ }
63
+ },
64
+ cancel: {
65
+ type: 'red deny',
66
+ caption: '<i class="times icon"></i>${this.translate('Cancel')}'
67
+ }
68
+ });
69
+ }
70
+ }, true);
71
+ `;
72
+ }
73
+
74
+ static instance() {
75
+ return new this();
76
+ }
77
+ }
78
+
79
+ module.exports = Input;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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
+ * SemanticUI/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(['SemanticUI/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.define('ntdlg', {
42
+ message(id, title, message, icon, cb) {
43
+ return $.ntdlg.dialog(id, title, message, icon, {
44
+ okay: {
45
+ type: 'green approve',
46
+ caption: '<i class="check icon"></i>${this.translate('Ok')}',
47
+ }
48
+ }, cb);
49
+ }
50
+ }, true);
51
+ `;
52
+ }
53
+
54
+ static instance() {
55
+ return new this();
56
+ }
57
+ }
58
+
59
+ module.exports = Message;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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
+ * SemanticUI/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(['SemanticUI/Dialog']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.define('ntdlg', {
42
+ waitId: 'wdlg',
43
+ waitDlg: null,
44
+ wait(msg) {
45
+ const self = this;
46
+ if ('close' === msg) {
47
+ if (self.waitDlg) {
48
+ $.ntdlg.close(self.waitDlg);
49
+ }
50
+ } else {
51
+ if (null === self.waitDlg) {
52
+ const message = $.util.template($.ntdlg.messageTmpl, {
53
+ ICON: $.util.template($.ntdlg.iconTmpl, {ICON: 'big notched circle loading icon'}),
54
+ MESSAGE: msg
55
+ });
56
+ self.waitDlg = $.ntdlg.create(self.waitId, 'Please wait', message, {
57
+ closable: false,
58
+ size: 'tiny'
59
+ });
60
+ } else {
61
+ self.waitDlg.find('div.description p').html(msg);
62
+ }
63
+ $.ntdlg.show(self.waitDlg);
64
+ }
65
+ }
66
+ }, true);
67
+ `;
68
+ }
69
+
70
+ static instance() {
71
+ return new this();
72
+ }
73
+ }
74
+
75
+ module.exports = Wait;
@@ -0,0 +1,228 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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('SemanticUI');
27
+
28
+ /**
29
+ * SemanticUI/Dialog script repository.
30
+ */
31
+ class Dialog extends JQuery {
32
+
33
+ initialize() {
34
+ this.name = 'Dialog';
35
+ this.position = ScriptRepository.POSITION_FIRST;
36
+ this.addDependencies(['SemanticUI', 'JQuery/Define', 'JQuery/Util']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.define('ntdlg', {
42
+ ICON_INFO: 'info circle icon',
43
+ ICON_ALERT: 'yellow exclamation circle icon',
44
+ ICON_ERROR: 'red times circle icon',
45
+ ICON_SUCCESS: 'green check circle icon',
46
+ ICON_QUESTION: 'question circle icon',
47
+ ICON_INPUT: 'edit icon',
48
+ dialogTmpl:
49
+ '<div id="%ID%" class="ui %MODAL% modal">' +
50
+ ' <div class="header">%TITLE%</div>' +
51
+ ' <div class="image content">%CONTENT%</div>' +
52
+ ' <div class="actions">%BUTTONS%</div>' +
53
+ '</div>',
54
+ iconTmpl:
55
+ '<i class="big %ICON%"></i>',
56
+ messageTmpl:
57
+ '%ICON%' +
58
+ '<div class="description">%MESSAGE%</div>',
59
+ buttonTmpl:
60
+ '<div id="%ID%" class="ui %TYPE% button">%CAPTION%</div>',
61
+ create(id, title, message, options) {
62
+ const self = this;
63
+ const dlg_id = '#' + id;
64
+ $(dlg_id).remove();
65
+ if ($.ntdlg.moved && $.ntdlg.moved.refs[id] !== undefined) {
66
+ $('div.' + $.ntdlg.moved.refs[id]).remove();
67
+ delete $.ntdlg.moved.refs[id];
68
+ }
69
+ const modal = {
70
+ closable: options.closable !== undefined ? options.closable : true
71
+ }
72
+ const buttons = [];
73
+ const handlers = [];
74
+ const okay = ['approve', 'positive', 'ok'];
75
+ const nope = ['deny', 'negative', 'cancel'];
76
+ let cnt = 0;
77
+ if (options.buttons) {
78
+ Object.keys(options.buttons).forEach(k => {
79
+ const v = options.buttons[k];
80
+ let caption, btnType, handler;
81
+ if (typeof v === 'object') {
82
+ caption = v.caption ? v.caption : k;
83
+ btnType = v.type ? v.type : 'secondary';
84
+ handler = typeof v.handler === 'function' ? v.handler : null;
85
+ } else {
86
+ caption = k;
87
+ btnType = 0 === cnt ? 'primary' : 'secondary';
88
+ handler = typeof v === 'function' ? v : null;
89
+ }
90
+ const btnid = id + '_btn_' + k.replace(/\W+/g, "-").toLowerCase();
91
+ buttons.push($.util.template(self.buttonTmpl, {
92
+ ID: btnid,
93
+ TYPE: btnType,
94
+ CAPTION: caption
95
+ }));
96
+ if (handler) {
97
+ if (!modal.onApprove) {
98
+ okay.forEach(v => {
99
+ if (btnType.indexOf(v) >= 0) {
100
+ modal.onApprove = handler;
101
+ handler = null;
102
+ return true;
103
+ }
104
+ });
105
+ }
106
+ if (!modal.onDeny) {
107
+ nope.forEach(v => {
108
+ if (btnType.indexOf(v) >= 0) {
109
+ modal.onDeny = handler;
110
+ handler = null;
111
+ return true;
112
+ }
113
+ });
114
+ }
115
+ }
116
+ if (typeof handler === 'function') {
117
+ handlers.push({id: btnid, handler: handler});
118
+ }
119
+ cnt++;
120
+ });
121
+ }
122
+ if (typeof options.show === 'function') {
123
+ modal.onShow = options.show;
124
+ }
125
+ if (typeof options.hide === 'function') {
126
+ modal.onHidden = options.hide;
127
+ }
128
+ const content = $.util.template(self.dialogTmpl, {
129
+ ID: id,
130
+ TITLE: title,
131
+ MODAL: options.size ? options.size : 'tiny',
132
+ BUTTONS: buttons.join(''),
133
+ CONTENT: message
134
+ });
135
+ $(document.body).append(content);
136
+ const dlg = $(dlg_id);
137
+ // move embedded modal
138
+ const bd = dlg.find('.content');
139
+ const d = bd.find('.ui.modal');
140
+ if (d.length) {
141
+ if (!$.ntdlg.moved) {
142
+ $.ntdlg.moved = {count: 0, refs: {}}
143
+ }
144
+ $.ntdlg.moved.count++;
145
+ const movedDlg = id + '-moved-' + $.ntdlg.moved.count;
146
+ $.ntdlg.moved.refs[id] = movedDlg;
147
+ d.addClass(movedDlg);
148
+ d.appendTo($(document.body));
149
+ }
150
+ if (buttons.length === 0) {
151
+ dlg.find('.actions').hide();
152
+ }
153
+ Object.values(handlers).forEach(v => {
154
+ $('#' + v.id).on('click', function(e) {
155
+ e.preventDefault();
156
+ v.handler.apply(dlg);
157
+ });
158
+ });
159
+ dlg.modal(modal);
160
+ return dlg;
161
+ },
162
+ show(dlg) {
163
+ if (dlg && !this.isVisible(dlg)) {
164
+ if (typeof dlg === 'string') {
165
+ dlg = $('#' + dlg);
166
+ }
167
+ dlg.modal('show');
168
+ }
169
+ },
170
+ close(dlg) {
171
+ if (dlg) {
172
+ if (typeof dlg === 'string') {
173
+ dlg = $('#' + dlg);
174
+ }
175
+ dlg.modal('hide');
176
+ }
177
+ },
178
+ isVisible(dlg) {
179
+ if (dlg) {
180
+ if (typeof dlg === 'string') {
181
+ dlg = $('#' + dlg);
182
+ }
183
+ if (dlg.length) {
184
+ if (dlg.hasClass('modal') && dlg.is(':visible')) {
185
+ return true;
186
+ }
187
+ }
188
+ return false;
189
+ }
190
+ },
191
+ getBody(dlg) {
192
+ if (dlg) {
193
+ if (typeof dlg === 'string') {
194
+ dlg = $('#' + dlg);
195
+ }
196
+ return dlg.find('.content:first');
197
+ }
198
+ },
199
+ dialog(id, title, message, icon, buttons, close_cb) {
200
+ const self = this;
201
+ icon = icon || self.ICON_INFO;
202
+ buttons = buttons || [];
203
+ message = $.util.template(self.messageTmpl, {
204
+ ICON: $.util.template(self.iconTmpl, {ICON: icon}),
205
+ MESSAGE: message
206
+ });
207
+ const dlg = self.create(id, title, message, {
208
+ closable: false,
209
+ buttons: buttons,
210
+ hide() {
211
+ if (typeof close_cb === 'function') {
212
+ close_cb();
213
+ }
214
+ }
215
+ });
216
+ dlg.modal('show');
217
+ return dlg;
218
+ }
219
+ }, true);
220
+ `;
221
+ }
222
+
223
+ static instance() {
224
+ return new this();
225
+ }
226
+ }
227
+
228
+ module.exports = Dialog;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2018-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 SemanticUI = ScriptManager.require('SemanticUI');
27
+
28
+ /**
29
+ * SemanticUI/Loader script repository.
30
+ */
31
+ class Loader extends SemanticUI {
32
+
33
+ initialize() {
34
+ this.name = 'Loader';
35
+ this.position = ScriptRepository.POSITION_MIDDLE;
36
+ this.addDependencies(['SemanticUI', 'JQuery/Util']);
37
+ }
38
+
39
+ getScript() {
40
+ return `
41
+ $.loader = function(container, options) {
42
+ const loader = {
43
+ container: container,
44
+ url: options.url,
45
+ column: options.column || 0,
46
+ load(page) {
47
+ const self = this;
48
+ self.page = page || self.page || 1;
49
+ $.get(self.url.replace(/PAGE/, self.page))
50
+ .done(function(json) {
51
+ if (json.items) {
52
+ self.add(json.items);
53
+ if (json.count !== undefined) {
54
+ self.buildInfo(json.items, json.count);
55
+ }
56
+ }
57
+ if (json.pages && json.pages.length) {
58
+ self.buildNav(json.pages);
59
+ }
60
+ if (typeof options.loaded === 'function') {
61
+ options.loaded.call(self, json);
62
+ }
63
+ });
64
+ },
65
+ add(items) {
66
+ const self = this;
67
+ items = Array.isArray(items) ? items : [items];
68
+ let tbody = self.container.find('tbody');
69
+ if (tbody.length) {
70
+ tbody.remove();
71
+ }
72
+ $('<tbody></tbody>').appendTo(self.container);
73
+ tbody = self.container.find('tbody');
74
+ items.forEach(item => {
75
+ const row = options.formatRow.call(self, item);
76
+ row.appendTo(tbody);
77
+ });
78
+ },
79
+ buildInfo(items, count) {
80
+ const self = this;
81
+ const title = self.container.siblings('.x-title');
82
+ if (title.length) {
83
+ switch (count) {
84
+ case 0:
85
+ title.html('${this.translate('No result')}');
86
+ break;
87
+ case 1:
88
+ title.html('${this.translate('Showing one result')}');
89
+ break;
90
+ default:
91
+ title.html($.util.template('${this.translate('Showing result from %FIRST% to %LAST% of %COUNT%')}', {
92
+ FIRST: items[0].nr,
93
+ LAST: items[items.length - 1].nr,
94
+ COUNT: count
95
+ }));
96
+ break;
97
+ }
98
+ }
99
+ },
100
+ buildNav(items) {
101
+ const self = this;
102
+ let tfoot = self.container.find('tfoot');
103
+ if (tfoot.length) {
104
+ tfoot.remove();
105
+ }
106
+ $('<tfoot></tfoot>').appendTo(self.container);
107
+ tfoot = self.container.find('tfoot');
108
+ const menus = [];
109
+ items.forEach(item => {
110
+ if (item.icon) {
111
+ menus.push($.util.template('<a class="icon item" data-page="%PAGE%">' +
112
+ '<i class="%ICON%"></i></a>', {PAGE: item.page, ICON: item.icon}));
113
+ } else {
114
+ menus.push($.util.template('<a class="%CLASS%" data-page="%PAGE%">%PAGE%</a>', {
115
+ CLASS: 'item' + (item.page === self.page ? ' active' : ''),
116
+ PAGE: item.page
117
+ }));
118
+ }
119
+ });
120
+ if (self.column === 0) {
121
+ self.column = self.container.find('thead tr th').length;
122
+ }
123
+ $('<tr><th colspan="' + self.column + '">' +
124
+ '<div class="ui right floated pagination menu">' + menus.join('') +
125
+ '</div></th></tr>').appendTo(tfoot);
126
+ tfoot.find('a.item').on('click', function(e) {
127
+ e.preventDefault();
128
+ const page = parseInt($(this).attr('data-page'));
129
+ self.load(page);
130
+ });
131
+ },
132
+ iconOverlay(icon, overlay) {
133
+ icon = '<i class="' + icon + ' icon"></i>';
134
+ if (overlay) {
135
+ icon = '<i class="icons">' + icon + '<i class="corner ' + overlay + ' icon"></i></i>'
136
+ }
137
+ return icon;
138
+ },
139
+ icon(type) {
140
+ type = --type;
141
+ const icons = ['phone', 'voicemail', 'paper plane', 'envelope', 'bullhorn', 'bell'];
142
+ if (type >= 0 && type < icons.length) {
143
+ return this.iconOverlay(icons[type]);
144
+ }
145
+ }
146
+ }
147
+ return loader;
148
+ }
149
+ `;
150
+ }
151
+
152
+ static instance() {
153
+ return new this();
154
+ }
155
+ }
156
+
157
+ module.exports = Loader;