x4js 1.4.2
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/application.d.ts +95 -0
- package/lib/application.js +137 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +135 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +77 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +235 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +236 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +354 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +152 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +126 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +584 -0
- package/lib/colorpicker.d.ts +98 -0
- package/lib/colorpicker.js +1457 -0
- package/lib/combobox.d.ts +97 -0
- package/lib/combobox.js +246 -0
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1712 -0
- package/lib/datastore.d.ts +392 -0
- package/lib/datastore.js +986 -0
- package/lib/dialog.d.ts +171 -0
- package/lib/dialog.js +468 -0
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +13 -0
- package/lib/drag_manager.d.ts +26 -0
- package/lib/drag_manager.js +118 -0
- package/lib/drawtext.d.ts +43 -0
- package/lib/drawtext.js +261 -0
- package/lib/fileupload.d.ts +60 -0
- package/lib/fileupload.js +158 -0
- package/lib/form.d.ts +122 -0
- package/lib/form.js +293 -0
- package/lib/formatters.d.ts +31 -0
- package/lib/formatters.js +75 -0
- package/lib/gridview.d.ts +171 -0
- package/lib/gridview.js +786 -0
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +69 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +169 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +173 -0
- package/lib/image.d.ts +51 -0
- package/lib/image.js +149 -0
- package/lib/index.js +1 -0
- package/lib/input.d.ts +86 -0
- package/lib/input.js +172 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +86 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +261 -0
- package/lib/link.d.ts +46 -0
- package/lib/link.js +55 -0
- package/lib/listview.d.ts +173 -0
- package/lib/listview.js +532 -0
- package/lib/md5.d.ts +56 -0
- package/lib/md5.js +397 -0
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +276 -0
- package/lib/messagebox.d.ts +64 -0
- package/lib/messagebox.js +141 -0
- package/lib/panel.d.ts +42 -0
- package/lib/panel.js +61 -0
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +373 -0
- package/lib/property_editor.d.ts +67 -0
- package/lib/property_editor.js +247 -0
- package/lib/radiobtn.d.ts +68 -0
- package/lib/radiobtn.js +131 -0
- package/lib/rating.d.ts +49 -0
- package/lib/rating.js +93 -0
- package/lib/request.d.ts +48 -0
- package/lib/request.js +220 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +27 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +63 -0
- package/lib/sidebarview.d.ts +44 -0
- package/lib/sidebarview.js +73 -0
- package/lib/smartedit.d.ts +103 -0
- package/lib/smartedit.js +381 -0
- package/lib/spreadsheet.d.ts +214 -0
- package/lib/spreadsheet.js +1073 -0
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +262 -0
- package/lib/svgcomponent.d.ts +165 -0
- package/lib/svgcomponent.js +350 -0
- package/lib/tabbar.d.ts +41 -0
- package/lib/tabbar.js +66 -0
- package/lib/tabview.d.ts +45 -0
- package/lib/tabview.js +79 -0
- package/lib/textarea.d.ts +59 -0
- package/lib/textarea.js +119 -0
- package/lib/textedit.d.ts +118 -0
- package/lib/textedit.js +406 -0
- package/lib/texthiliter.d.ts +56 -0
- package/lib/texthiliter.js +219 -0
- package/lib/toaster.d.ts +38 -0
- package/lib/toaster.js +58 -0
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1096 -0
- package/lib/tooltips.d.ts +42 -0
- package/lib/tooltips.js +148 -0
- package/lib/treeview.d.ts +128 -0
- package/lib/treeview.js +490 -0
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +363 -0
- package/package.json +21 -0
- package/src/README.md +2 -0
- package/src/application.ts +191 -0
- package/src/base64.ts +162 -0
- package/src/base_component.ts +118 -0
- package/src/button.ts +327 -0
- package/src/calendar.ts +312 -0
- package/src/canvas.ts +501 -0
- package/src/cardview.ts +220 -0
- package/src/checkbox.ts +178 -0
- package/src/color.ts +748 -0
- package/src/colorpicker.ts +1618 -0
- package/src/combobox.ts +348 -0
- package/src/component.ts +2330 -0
- package/src/datastore.ts +1318 -0
- package/src/dialog.ts +631 -0
- package/src/dom_events.ts +297 -0
- package/src/drag_manager.ts +168 -0
- package/src/drawtext.ts +342 -0
- package/src/fileupload.ts +208 -0
- package/src/form.ts +362 -0
- package/src/formatters.ts +96 -0
- package/src/gridview.ts +1051 -0
- package/src/hosts/electron.ts +161 -0
- package/src/hosts/host.ts +100 -0
- package/src/hosts/nwjs.ts +141 -0
- package/src/hosts/nwjs_types.ts +339 -0
- package/src/i18n.ts +205 -0
- package/src/icon.ts +237 -0
- package/src/image.ts +198 -0
- package/src/input.ts +236 -0
- package/src/label.ts +124 -0
- package/src/layout.ts +366 -0
- package/src/link.ts +82 -0
- package/src/listview.ts +749 -0
- package/src/md5.ts +432 -0
- package/src/menu.ts +394 -0
- package/src/messagebox.ts +199 -0
- package/src/panel.ts +81 -0
- package/src/popup.ts +488 -0
- package/src/property_editor.ts +333 -0
- package/src/radiobtn.ts +190 -0
- package/src/rating.ts +131 -0
- package/src/request.ts +296 -0
- package/src/router.ts +43 -0
- package/src/settings.ts +75 -0
- package/src/sidebarview.ts +97 -0
- package/src/smartedit.ts +532 -0
- package/src/spreadsheet.ts +1423 -0
- package/src/styles.ts +332 -0
- package/src/svgcomponent.ts +440 -0
- package/src/tabbar.ts +105 -0
- package/src/tabview.ts +106 -0
- package/src/textarea.ts +183 -0
- package/src/textedit.ts +535 -0
- package/src/texthiliter.ts +284 -0
- package/src/toaster.ts +76 -0
- package/src/tools.ts +1391 -0
- package/src/tooltips.ts +185 -0
- package/src/treeview.ts +670 -0
- package/src/x4.less +1940 -0
- package/src/x4_events.ts +558 -0
- package/tsconfig.json +14 -0
package/lib/form.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file form.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { Component, flyWrap } from './component';
|
|
26
|
+
import { HLayout, VLayout } from './layout';
|
|
27
|
+
import { Button } from './button';
|
|
28
|
+
import { TextEdit } from './textedit';
|
|
29
|
+
import { ajaxRequest } from './request';
|
|
30
|
+
import { EvBtnClick } from './dialog';
|
|
31
|
+
import { _tr } from './i18n';
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export class Form extends VLayout {
|
|
36
|
+
m_height;
|
|
37
|
+
m_container;
|
|
38
|
+
m_buttons;
|
|
39
|
+
m_dirty;
|
|
40
|
+
m_watchChanges;
|
|
41
|
+
constructor(props) {
|
|
42
|
+
let content = props.content;
|
|
43
|
+
props.content = null;
|
|
44
|
+
// save height, because real form height is 'height' PLUS button bar height
|
|
45
|
+
let height = props.height;
|
|
46
|
+
props.height = undefined;
|
|
47
|
+
super(props);
|
|
48
|
+
this.setProp('tag', props.disableSuggestions ? 'section' : 'form');
|
|
49
|
+
this.mapPropEvents(props, 'btnClick');
|
|
50
|
+
this.updateContent(content, props.buttons, height);
|
|
51
|
+
this.m_dirty = false;
|
|
52
|
+
this.m_watchChanges = false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* returns the container object
|
|
56
|
+
*/
|
|
57
|
+
get container() {
|
|
58
|
+
return this.m_container;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
componentCreated() {
|
|
64
|
+
super.componentCreated();
|
|
65
|
+
if (this.m_watchChanges) {
|
|
66
|
+
this.watchChanges();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
updateContent(items, buttons, height = 0) {
|
|
73
|
+
if (height) {
|
|
74
|
+
// keep height for next time
|
|
75
|
+
this.m_height = height;
|
|
76
|
+
}
|
|
77
|
+
this._makeButtons(buttons);
|
|
78
|
+
let content = [
|
|
79
|
+
this.m_container = new VLayout({
|
|
80
|
+
cls: 'container',
|
|
81
|
+
height: this.m_height,
|
|
82
|
+
content: items
|
|
83
|
+
}),
|
|
84
|
+
this.m_buttons,
|
|
85
|
+
];
|
|
86
|
+
super.setContent(content);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @param els
|
|
91
|
+
* @param refreshAll
|
|
92
|
+
*/
|
|
93
|
+
setContent(els, refreshAll = true) {
|
|
94
|
+
this.m_container.setContent(els, refreshAll);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @param buttons
|
|
99
|
+
*/
|
|
100
|
+
setButtons(buttons) {
|
|
101
|
+
this._makeButtons(buttons);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* enable a button by it's name
|
|
105
|
+
*/
|
|
106
|
+
enableButton(name, enable = true) {
|
|
107
|
+
let button = this.getButton(name);
|
|
108
|
+
if (button) {
|
|
109
|
+
button.enable(enable);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* return a button by it's name
|
|
114
|
+
* @param name
|
|
115
|
+
*/
|
|
116
|
+
getButton(name) {
|
|
117
|
+
let button = this.m_buttons?.itemWithRef('@' + name);
|
|
118
|
+
return button;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
*
|
|
122
|
+
*/
|
|
123
|
+
_makeButtons(buttons) {
|
|
124
|
+
if (!this.m_buttons) {
|
|
125
|
+
this.m_buttons = new HLayout({
|
|
126
|
+
cls: 'footer',
|
|
127
|
+
ref: 'buttons',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let btns = [];
|
|
131
|
+
if (buttons) {
|
|
132
|
+
for (let b of buttons) {
|
|
133
|
+
if (b instanceof Component) {
|
|
134
|
+
btns.push(b);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
switch (b) {
|
|
138
|
+
case 'ok': {
|
|
139
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.ok, click: () => { this._click(b); } }));
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case 'cancel': {
|
|
143
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.cancel, click: () => { this._click(b); } }));
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case 'ignore': {
|
|
147
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.ignore, click: () => { this._click(b); } }));
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'yes': {
|
|
151
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.yes, click: () => { this._click(b); } }));
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case 'no': {
|
|
155
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.no, click: () => { this._click(b); } }));
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'close': {
|
|
159
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.close, click: () => { this._click(b); } }));
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'save': {
|
|
163
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.save, click: () => { this._click(b); } }));
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'dontsave': {
|
|
167
|
+
btns.push(new Button({ ref: '@' + b, text: _tr.global.dontsave, click: () => { this._click(b); } }));
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (btns.length == 1) {
|
|
175
|
+
btns[0].setAttribute('autofocus', true);
|
|
176
|
+
}
|
|
177
|
+
this.m_buttons.setContent(btns);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
validate() {
|
|
183
|
+
let inputs = this.queryAll('input'), result = true;
|
|
184
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
185
|
+
let input = Component.getElement(inputs[i], TextEdit);
|
|
186
|
+
if (input && !input.validate()) {
|
|
187
|
+
result = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
_click(btn) {
|
|
196
|
+
this.emit('btnClick', EvBtnClick(btn));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* replacement for HTMLFormElement.elements
|
|
200
|
+
* as chrome shows suggestions on form elements even if we ask him (not to do that)
|
|
201
|
+
* we removed <form> element.
|
|
202
|
+
* so we have to get children by hand
|
|
203
|
+
*/
|
|
204
|
+
_getElements() {
|
|
205
|
+
console.assert(!!this.dom);
|
|
206
|
+
const els = this.queryAll('[name]');
|
|
207
|
+
return els;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
*/
|
|
212
|
+
setValues(values) {
|
|
213
|
+
let elements = this._getElements();
|
|
214
|
+
for (let e = 0; e < elements.length; e++) {
|
|
215
|
+
let input = elements[e];
|
|
216
|
+
let item = Component.getElement(input);
|
|
217
|
+
if (!item.hasAttribute("name")) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
let name = item.getAttribute('name'), type = item.getAttribute('type');
|
|
221
|
+
if (values[name] !== undefined) {
|
|
222
|
+
item.setStoreValue(values[name]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
this.setDirty(false);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* values are not escaped
|
|
229
|
+
* checkbox set true when checked
|
|
230
|
+
* radio set value when checked
|
|
231
|
+
*/
|
|
232
|
+
getValues() {
|
|
233
|
+
let elements = this._getElements();
|
|
234
|
+
let result = {};
|
|
235
|
+
for (let e = 0; e < elements.length; e++) {
|
|
236
|
+
let el = elements[e];
|
|
237
|
+
let item = Component.getElement(el);
|
|
238
|
+
if (!item.hasAttribute("name")) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
let name = item.getAttribute('name'), value = item.getStoreValue();
|
|
242
|
+
if (value !== undefined) {
|
|
243
|
+
result[name] = value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* send the query to the desired handler
|
|
250
|
+
*/
|
|
251
|
+
submit(cfg, cbvalidation) {
|
|
252
|
+
if (!this.validate()) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
let values = this.getValues();
|
|
256
|
+
if (cbvalidation) {
|
|
257
|
+
if (!cbvalidation(values)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
let form = new FormData();
|
|
262
|
+
for (let n in values) {
|
|
263
|
+
if (values.hasOwnProperty(n)) {
|
|
264
|
+
form.append(n, values[n] === undefined ? '' : values[n]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
cfg.params = form;
|
|
268
|
+
return ajaxRequest(cfg);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
*
|
|
272
|
+
*/
|
|
273
|
+
watchChanges() {
|
|
274
|
+
if (this.dom) {
|
|
275
|
+
const els = this.queryAll('input[name], textarea[name]');
|
|
276
|
+
els.forEach(el => {
|
|
277
|
+
flyWrap(el).setDomEvent('input', () => {
|
|
278
|
+
this.setDirty();
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
this.m_watchChanges = false;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
this.m_watchChanges = true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
setDirty(set = true) {
|
|
288
|
+
this.m_dirty = set;
|
|
289
|
+
}
|
|
290
|
+
isDirty() {
|
|
291
|
+
return this.m_dirty;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file formatters.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
export declare type FormatFunc = (input: any, rec: any) => string;
|
|
26
|
+
export declare function setCurrencySymbol(symbol: string | null): void;
|
|
27
|
+
export declare function sql_date_formatter(input: any): string;
|
|
28
|
+
export declare function date_formatter(input: any): string;
|
|
29
|
+
export declare function money_formatter(input: any): string;
|
|
30
|
+
export declare function money_formatter_nz(input: any): string;
|
|
31
|
+
export declare function bool_formatter(input: any): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file formatters.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { formatIntlDate, roundTo } from './tools';
|
|
26
|
+
let locale;
|
|
27
|
+
let moneyFmt;
|
|
28
|
+
export function setCurrencySymbol(symbol) {
|
|
29
|
+
if (symbol) {
|
|
30
|
+
moneyFmt = new Intl.NumberFormat(locale, { style: 'currency', currency: symbol /*, currencyDisplay: 'symbol'*/ });
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
moneyFmt = new Intl.NumberFormat(locale, { style: 'decimal', useGrouping: true, minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function sql_date_formatter(input) {
|
|
37
|
+
if (input === null || input === undefined || input === '') {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
let dte = new Date(Date.parse(input));
|
|
41
|
+
//todo: better implementation
|
|
42
|
+
const options = { /*weekday: 'short',*/ month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' };
|
|
43
|
+
return dte.toLocaleDateString(locale, options);
|
|
44
|
+
}
|
|
45
|
+
export function date_formatter(input) {
|
|
46
|
+
if (input === null || input === undefined || input === '') {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
let dte = typeof (input) == 'string' ? new Date(Date.parse(input)) : input;
|
|
50
|
+
return formatIntlDate(dte);
|
|
51
|
+
}
|
|
52
|
+
export function money_formatter(input) {
|
|
53
|
+
if (input === null || input === undefined || input === '') {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
let val = roundTo(typeof (input) == 'string' ? parseFloat(input) : input, 2);
|
|
57
|
+
if (val === -0.00)
|
|
58
|
+
val = 0.00;
|
|
59
|
+
let res = moneyFmt.format(val);
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
62
|
+
export function money_formatter_nz(input) {
|
|
63
|
+
if (input === null || input === undefined || input === '') {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
let val = roundTo(typeof (input) == 'string' ? parseFloat(input) : input, 2);
|
|
67
|
+
if (!val) { // do not show zeros
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
let res = moneyFmt.format(val);
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
export function bool_formatter(input) {
|
|
74
|
+
return input ? 'oui' : '-';
|
|
75
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file gridview.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
/**
|
|
26
|
+
* todo: sizable column
|
|
27
|
+
* todo: button in a column
|
|
28
|
+
*/
|
|
29
|
+
import { VLayout } from './layout';
|
|
30
|
+
import { Component, ContainerEventMap, EvDblClick, CProps, HtmlString } from './component';
|
|
31
|
+
import { Label } from './label';
|
|
32
|
+
import * as Formatters from './formatters';
|
|
33
|
+
import { DataView, DataStore, Record } from './datastore';
|
|
34
|
+
import { EvContextMenu, EvSelectionChange, BasicEvent, EventDisposer } from "./x4_events";
|
|
35
|
+
export interface EvGridCheck extends BasicEvent {
|
|
36
|
+
rec: Record;
|
|
37
|
+
chk: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function EvGridCheck(rec: Record, chk: boolean): EvGridCheck;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export interface GridColumn {
|
|
44
|
+
id: any;
|
|
45
|
+
title: string;
|
|
46
|
+
width: number;
|
|
47
|
+
flex?: number;
|
|
48
|
+
align?: 'left' | 'center' | 'right';
|
|
49
|
+
renderer?: CellRenderer;
|
|
50
|
+
formatter?: Formatters.FormatFunc;
|
|
51
|
+
cls?: string;
|
|
52
|
+
sortable?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export declare type CellRenderer = (rec: Record) => Component;
|
|
55
|
+
export declare type RowClassifier = (rec: Record, Row: Component) => void;
|
|
56
|
+
export declare type ContextMenuGridItem = (event: MouseEvent, item: Record, grid: GridView) => any;
|
|
57
|
+
declare type emptyFn = () => string;
|
|
58
|
+
interface GridViewEventMap extends ContainerEventMap {
|
|
59
|
+
dblClick?: EvDblClick;
|
|
60
|
+
selectionChange?: EvSelectionChange;
|
|
61
|
+
contextMenu?: EvContextMenu;
|
|
62
|
+
gridCheck?: EvGridCheck;
|
|
63
|
+
}
|
|
64
|
+
export interface GridViewProps extends CProps<GridViewEventMap> {
|
|
65
|
+
store: DataStore | DataView;
|
|
66
|
+
columns: GridColumn[];
|
|
67
|
+
calcRowClass?: RowClassifier;
|
|
68
|
+
empty_text?: string | emptyFn;
|
|
69
|
+
hasMarks?: boolean;
|
|
70
|
+
hasFooter?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* gridview class
|
|
74
|
+
*/
|
|
75
|
+
export declare class GridView extends VLayout<GridViewProps, GridViewEventMap> {
|
|
76
|
+
protected m_dataview: DataView;
|
|
77
|
+
protected m_data_cx: EventDisposer;
|
|
78
|
+
protected m_columns: GridColumn[];
|
|
79
|
+
protected m_view_el: Component;
|
|
80
|
+
protected m_container: Component;
|
|
81
|
+
protected m_header: Component;
|
|
82
|
+
protected m_footer: Component;
|
|
83
|
+
protected m_empty_msg: Label;
|
|
84
|
+
protected m_empty_text: string | emptyFn;
|
|
85
|
+
protected m_selection: any;
|
|
86
|
+
private m_itemHeight;
|
|
87
|
+
private m_topIndex;
|
|
88
|
+
protected m_visible_rows: Component[];
|
|
89
|
+
protected m_hasMarks: boolean;
|
|
90
|
+
protected m_marks: Set<any>;
|
|
91
|
+
private m_recycler;
|
|
92
|
+
private m_rowClassifier;
|
|
93
|
+
constructor(props: GridViewProps);
|
|
94
|
+
componentCreated(): void;
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
private _moveSel;
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
private _handleKey;
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
getNextSel(sens: number): any;
|
|
107
|
+
private _scrollIntoView;
|
|
108
|
+
/**
|
|
109
|
+
* change the list of item displayed
|
|
110
|
+
* @param items - new array of items
|
|
111
|
+
*/
|
|
112
|
+
setStore(store: DataStore | DataView): void;
|
|
113
|
+
getView(): DataView;
|
|
114
|
+
/**
|
|
115
|
+
* return the current selection (row id) or null
|
|
116
|
+
*/
|
|
117
|
+
getSelection(): any;
|
|
118
|
+
getSelRec(): Record;
|
|
119
|
+
setSelection(recId: any): void;
|
|
120
|
+
/** @ignore */
|
|
121
|
+
render(): void;
|
|
122
|
+
private _on_col_resize;
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
private _sortCol;
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
private _computeItemHeight;
|
|
131
|
+
private _createRow;
|
|
132
|
+
private _buildItems;
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
*/
|
|
136
|
+
private _updateScroll;
|
|
137
|
+
/** @ignore */
|
|
138
|
+
private _rowFromTarget;
|
|
139
|
+
private _itemClick;
|
|
140
|
+
private _itemDblClick;
|
|
141
|
+
/** @ignore */
|
|
142
|
+
private _itemMenu;
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
*/
|
|
146
|
+
private _findItem;
|
|
147
|
+
/**
|
|
148
|
+
* @ignore
|
|
149
|
+
* called when an item is selected by mouse
|
|
150
|
+
*/
|
|
151
|
+
protected _selectItem(item: any, dom_item: Component, scrollIntoView?: string): void;
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
*/
|
|
155
|
+
protected _showItemContextMenu(event: MouseEvent, item: Record): void;
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
clearSelection(): void;
|
|
160
|
+
/**
|
|
161
|
+
* todo: moveto datastore
|
|
162
|
+
*/
|
|
163
|
+
exportData(filename: any): void;
|
|
164
|
+
set empty_text(text: string | HtmlString);
|
|
165
|
+
private _renderCheck;
|
|
166
|
+
private _toggleMark;
|
|
167
|
+
getMarks(): any[];
|
|
168
|
+
clearMarks(): void;
|
|
169
|
+
setFooterData(rec: any): void;
|
|
170
|
+
}
|
|
171
|
+
export {};
|