jsxgrid 2.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.
Files changed (83) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +2329 -0
  3. package/dist/fields/jsgrid.field.XDateTimeField.min.js +6 -0
  4. package/dist/fields/jsgrid.field.XRowSelectField.min.js +6 -0
  5. package/dist/fields/jsgrid.field.Xcheckbox.min.js +6 -0
  6. package/dist/fields/jsgrid.field.XimgField.min.js +6 -0
  7. package/dist/fields/jsgrid.field.Xjsoneditor.min.js +6 -0
  8. package/dist/fields/jsgrid.field.Xselect.min.js +6 -0
  9. package/dist/fields/jsgrid.field.Xtextarea.min.js +6 -0
  10. package/dist/fields/lib/jsGridSummaryPlugin.min.js +6 -0
  11. package/dist/fields/lib/jsgrid.popup.basic.min.js +6 -0
  12. package/dist/i18n/jsgrid-Ko.js +46 -0
  13. package/dist/i18n/jsgrid-cs.js +46 -0
  14. package/dist/i18n/jsgrid-de.js +46 -0
  15. package/dist/i18n/jsgrid-el.js +46 -0
  16. package/dist/i18n/jsgrid-es.js +46 -0
  17. package/dist/i18n/jsgrid-fa.js +46 -0
  18. package/dist/i18n/jsgrid-fr.js +47 -0
  19. package/dist/i18n/jsgrid-he.js +46 -0
  20. package/dist/i18n/jsgrid-it.js +47 -0
  21. package/dist/i18n/jsgrid-ja.js +46 -0
  22. package/dist/i18n/jsgrid-ka.js +46 -0
  23. package/dist/i18n/jsgrid-lt.js +47 -0
  24. package/dist/i18n/jsgrid-pl.js +62 -0
  25. package/dist/i18n/jsgrid-pt-br.js +46 -0
  26. package/dist/i18n/jsgrid-pt.js +46 -0
  27. package/dist/i18n/jsgrid-ru.js +47 -0
  28. package/dist/i18n/jsgrid-tr.js +47 -0
  29. package/dist/i18n/jsgrid-zh-cn.js +46 -0
  30. package/dist/i18n/jsgrid-zh-tw.js +46 -0
  31. package/dist/icons-2x.png +0 -0
  32. package/dist/icons.png +0 -0
  33. package/dist/jsxgrid-fields.js +606 -0
  34. package/dist/jsxgrid-fields.min.js +6 -0
  35. package/dist/jsxgrid-theme.css +258 -0
  36. package/dist/jsxgrid-theme.min.css +1 -0
  37. package/dist/jsxgrid-xfields.js +979 -0
  38. package/dist/jsxgrid-xfields.min.js +6 -0
  39. package/dist/jsxgrid.css +126 -0
  40. package/dist/jsxgrid.js +2137 -0
  41. package/dist/jsxgrid.min.css +1 -0
  42. package/dist/jsxgrid.min.js +6 -0
  43. package/package.json +57 -0
  44. package/src/fields/jsgrid.field.XDateTimeField.js +122 -0
  45. package/src/fields/jsgrid.field.XRowSelectField.js +62 -0
  46. package/src/fields/jsgrid.field.Xcheckbox.js +108 -0
  47. package/src/fields/jsgrid.field.XimgField.js +99 -0
  48. package/src/fields/jsgrid.field.Xjsoneditor.js +165 -0
  49. package/src/fields/jsgrid.field.Xselect.js +176 -0
  50. package/src/fields/jsgrid.field.Xtextarea.js +97 -0
  51. package/src/fields/jsgrid.field.checkbox.js +97 -0
  52. package/src/fields/jsgrid.field.control.js +224 -0
  53. package/src/fields/jsgrid.field.number.js +41 -0
  54. package/src/fields/jsgrid.field.select.js +130 -0
  55. package/src/fields/jsgrid.field.text.js +69 -0
  56. package/src/fields/jsgrid.field.textarea.js +34 -0
  57. package/src/i18n/Ko.js +46 -0
  58. package/src/i18n/cs.js +46 -0
  59. package/src/i18n/de.js +46 -0
  60. package/src/i18n/el.js +46 -0
  61. package/src/i18n/es.js +46 -0
  62. package/src/i18n/fa.js +46 -0
  63. package/src/i18n/fr.js +47 -0
  64. package/src/i18n/he.js +46 -0
  65. package/src/i18n/it.js +47 -0
  66. package/src/i18n/ja.js +46 -0
  67. package/src/i18n/ka.js +46 -0
  68. package/src/i18n/lt.js +47 -0
  69. package/src/i18n/pl.js +62 -0
  70. package/src/i18n/pt-br.js +46 -0
  71. package/src/i18n/pt.js +46 -0
  72. package/src/i18n/ru.js +47 -0
  73. package/src/i18n/tr.js +47 -0
  74. package/src/i18n/zh-cn.js +46 -0
  75. package/src/i18n/zh-tw.js +46 -0
  76. package/src/jsgrid.core.js +1655 -0
  77. package/src/jsgrid.field.js +74 -0
  78. package/src/jsgrid.load-indicator.js +82 -0
  79. package/src/jsgrid.load-strategies.js +131 -0
  80. package/src/jsgrid.sort-strategies.js +49 -0
  81. package/src/jsgrid.validation.js +135 -0
  82. package/src/lib/jsGridSummaryPlugin.js +37 -0
  83. package/src/lib/jsgrid.popup.basic.js +107 -0
@@ -0,0 +1,979 @@
1
+ /*
2
+ * jsxgrid v2.0.0 (https://github.com/rok9ru/jsxgrid#readme)
3
+ * (c) 2026 Mikhail Kremza
4
+ * Licensed under MIT
5
+ */
6
+
7
+ (function(jsGrid, $, undefined) {
8
+ if (!jsGrid) {
9
+ console.log("jsGrid is not defined!");
10
+ return;
11
+ }
12
+ jsGrid.popup = jsGrid.popupBasic = function (formContent, options) {
13
+ this.idcounter = this.idcounter || 0;
14
+ this.idcounter++;
15
+
16
+
17
+ options = options || {};
18
+
19
+ options.closeText = options.closeText || 'Close';
20
+ options.heading = options.heading || '';
21
+
22
+ options.styles = options.styles || '.jsGridpopupBasicOverlay {' +
23
+ ' position: fixed;' +
24
+ ' top: 0;' +
25
+ ' bottom: 0;' +
26
+ ' left: 0;' +
27
+ ' right: 0;' +
28
+ ' background: rgba(0, 0, 0, 0.7);' +
29
+ ' transition: opacity 500ms;' +
30
+ ' opacity: 1;' +
31
+ '}' +
32
+ '' +
33
+ '.jsGridpopupBasicPopup {' +
34
+ ' margin: 70px auto;' +
35
+ ' padding: 20px;' +
36
+ ' min-height: 60%;'+
37
+ ' background: #fff;' +
38
+ ' border-radius: 5px;' +
39
+ ' width: 60%;' +
40
+ ' position: relative;' +
41
+ ' transition: all 300ms ease-in-out;' +
42
+ '}' +
43
+ '' +
44
+ '.jsGridpopupBasicPopup h2 {' +
45
+ ' margin-top: 0;' +
46
+ ' color: #333;' +
47
+ ' font-family: Tahoma, Arial, sans-serif;' +
48
+ '}' +
49
+ '.jsGridpopupBasicPopup .close {' +
50
+ ' position: absolute;' +
51
+ ' top: 10px;' +
52
+ ' right: 30px;' +
53
+ ' transition: all 200ms;' +
54
+ ' font-size: 30px;' +
55
+ ' font-weight: bold;' +
56
+ ' text-decoration: none;' +
57
+ ' color: #333;' +
58
+ '}' +
59
+ '.jsGridpopupBasicPopup .close:hover {' +
60
+ ' color: #06D85F;' +
61
+ '}' +
62
+ '.jsGridpopupBasicPopup .jsGridpopupBasicContent {' +
63
+ ' max-height: 30%;' +
64
+ ' overflow: auto;' +
65
+ '}' +
66
+ '' +
67
+ '@media screen and (max-width: 700px){' +
68
+ ' .jsGridpopupBasicPopup{' +
69
+ ' width: 70%;' +
70
+ ' }' +
71
+ '}';
72
+
73
+ if(!$('#jsGridpopupBasicStyles').length){
74
+ var $head = $("head");
75
+ var $headlinklast = $head.find("link[rel='stylesheet']:last");
76
+ var linkElement = "<style id='jsGridpopupBasicStyles'>" + options.styles + "</style>";
77
+ if ($headlinklast.length) {
78
+ $headlinklast.after(linkElement);
79
+ } else {
80
+ $head.append(linkElement);
81
+ }
82
+
83
+ }
84
+ var id = "jsGridpopupBasic" + this.idcounter;
85
+ var popup = $(
86
+ '<div id="' + id + '" class="jsGridpopupBasicOverlay">' +
87
+ '<div class="jsGridpopupBasicPopup">' +
88
+ '<h2></h2>'+
89
+ '<a class="close" href="#">&times;</a>' +
90
+ '<div class="jsGridpopupBasicContent">' +
91
+ '' +
92
+ '</div>' +
93
+ '</div>' +
94
+ '</div>');
95
+
96
+ popup.find('h2').text(options.heading);
97
+ popup.find('.jsGridpopupBasicContent').append(formContent);
98
+ popup.find('.close').click(function () {
99
+ if (options.onClose instanceof Function) {
100
+ options.onClose(popup);
101
+ }
102
+ popup.remove();
103
+ });
104
+ $('body').append(popup);
105
+ return {
106
+ 'id': id,
107
+ '$popup': popup,
108
+ 'hide':function () {
109
+ popup.remove();
110
+ }
111
+ };
112
+ }
113
+ }(jsGrid, jQuery));
114
+ (function($, undefined) {
115
+ var baseJsGrid = $.fn.jsGrid;
116
+ if (!baseJsGrid) return;
117
+
118
+ $.fn.jsGrid = function (options) {
119
+ if (typeof options === "object") {
120
+ var originalOnRefreshed = options.onRefreshed;
121
+
122
+ options.onRefreshed = function (args) {
123
+ if (originalOnRefreshed) originalOnRefreshed.apply(this, arguments);
124
+
125
+ var grid = args.grid;
126
+ var data = grid.option("data") || [];
127
+ var fields = grid.option("fields") || [];
128
+
129
+ var $table = grid._container.find(".jsgrid-table").last();
130
+ $table.find(".jsgrid-summary-footer").remove();
131
+
132
+ var $tfoot = $("<tfoot class='jsgrid-summary-footer'>").appendTo($table);
133
+ var $tr = $("<tr>").addClass("jsgrid-row").css({
134
+ "background": "#e1e1e1",
135
+ "font-weight": "bold"
136
+ }).appendTo($tfoot);
137
+
138
+ fields.forEach(function (field) {
139
+ var $td = $("<td>").addClass("jsgrid-cell").appendTo($tr);
140
+ if (typeof field.summary === "function") {
141
+ var result = field.summary.call(field, data);
142
+ $td.html(result);
143
+ }
144
+ });
145
+ };
146
+ }
147
+
148
+ return baseJsGrid.apply(this, arguments);
149
+ };
150
+ }(jQuery));
151
+ (function(jsGrid, $, undefined) {
152
+
153
+ // Standalone: does not extend jsGrid.CheckboxField, only jsGrid.Field.
154
+ // Same tri-state (checked/unchecked/indeterminate) filter behavior as
155
+ // CheckboxField, reimplemented here directly instead of inherited.
156
+
157
+ var Field = jsGrid.Field;
158
+
159
+ var Xcheckbox = function (config) {
160
+ Field.call(this, config);
161
+ };
162
+
163
+ Xcheckbox.prototype = new Field({
164
+ sorter: "number",
165
+ align: "center",
166
+ autosearch: true,
167
+ defaultSelected: null,//value (0/1/true/false) to preset the filter checkbox with, applied once on first filter render then reset
168
+
169
+ filterTemplate: function () {
170
+ if (!this.filtering)
171
+ return "";
172
+
173
+ var grid = this._grid,
174
+ $result = this.filterControl = this._createCheckbox();
175
+
176
+ $result.prop({
177
+ readOnly: true,
178
+ indeterminate: true
179
+ });
180
+
181
+ $result.on("click", function () {
182
+ var $cb = $(this);
183
+
184
+ if ($cb.prop("readOnly")) {
185
+ $cb.prop({
186
+ checked: false,
187
+ readOnly: false
188
+ });
189
+ } else if (!$cb.prop("checked")) {
190
+ $cb.prop({
191
+ readOnly: true,
192
+ indeterminate: true
193
+ });
194
+ }
195
+ });
196
+
197
+ if (this.autosearch) {
198
+ $result.on("click", function () {
199
+ grid.search();
200
+ });
201
+ }
202
+
203
+ if (this.defaultSelected !== null) {
204
+ $result.prop({
205
+ checked: !!this.defaultSelected,
206
+ indeterminate: false,
207
+ readOnly: false
208
+ });
209
+ this.defaultSelected = null;
210
+ }
211
+
212
+ return $result;
213
+ },
214
+
215
+ filterValue: function () {
216
+ return this.filterControl.get(0).indeterminate
217
+ ? undefined
218
+ : (this.filterControl.is(":checked") ? 1 : 0);
219
+ },
220
+
221
+ insertTemplate: function () {
222
+ if (!this.inserting)
223
+ return "";
224
+
225
+ return this.insertControl = this._createCheckbox();
226
+ },
227
+
228
+ insertValue: function () {
229
+ return +(this.insertControl.is(":checked"));
230
+ },
231
+
232
+ editValue: function () {
233
+ return +(this.editControl.is(":checked"));
234
+ },
235
+ itemTemplate: function (value) {
236
+ return this._createCheckbox().prop({
237
+ checked: +value,
238
+ disabled: true
239
+ });
240
+ },
241
+ editTemplate: function (value) {
242
+ if (!this.editing)
243
+ return this.itemTemplate.apply(this, arguments);
244
+
245
+ var $result = this.editControl = this._createCheckbox();
246
+ $result.prop("checked", +value);
247
+ return $result;
248
+ },
249
+
250
+ _createCheckbox: function () {
251
+ return $("<input>").attr("type", "checkbox");
252
+ }
253
+
254
+ });
255
+
256
+ jsGrid.fields.Xcheckbox = Xcheckbox;
257
+
258
+ }(jsGrid, jQuery));
259
+ (function(jsGrid, $, undefined) {
260
+
261
+ // Standalone: does not extend jsGrid.TextField, only jsGrid.Field.
262
+
263
+ var Field = jsGrid.Field;
264
+
265
+ var XimgField = function (config) {
266
+ Field.call(this, config);
267
+ };
268
+
269
+ XimgField.prototype = new Field({
270
+ autosearch: true,
271
+ readOnly: false,
272
+ fm_callback: null,
273
+ editButtonText: 'Open FM',
274
+ defaultSelected: null,//value to preset the filter input with, applied once on first filter render then reset
275
+
276
+ filterTemplate: function () {
277
+ if (!this.filtering)
278
+ return "";
279
+
280
+ var grid = this._grid,
281
+ $result = this.filterControl = this._createTextBox();
282
+
283
+ if (this.autosearch) {
284
+ $result.on("keypress", function (e) {
285
+ if (e.which === 13) {
286
+ grid.search();
287
+ e.preventDefault();
288
+ }
289
+ });
290
+ }
291
+
292
+ if (this.defaultSelected !== null) {
293
+ $result.val(this.defaultSelected);
294
+ this.defaultSelected = null;
295
+ }
296
+
297
+ return $result;
298
+ },
299
+
300
+ filterValue: function () {
301
+ return this.filterControl.val();
302
+ },
303
+
304
+ itemTemplate: function (value) {
305
+ var img = $('<img class="jsgrid-img" src="">');
306
+ img.attr("src", value || '');
307
+ img.css('max-height', '50px');
308
+ img.css('max-width', '50px');
309
+
310
+ return img;
311
+ }
312
+ , editTemplate: function (value) {
313
+ if (!this.editing)
314
+ return this.itemTemplate.apply(this, arguments);
315
+ var fm = this.fm_callback;
316
+
317
+ var editControl = this.editControl = $('<input type="text">').val(value || '');
318
+ if (fm) {
319
+ return $('<button class="jsgrid-imgField-button">' + this.editButtonText + '</button>').click(function () {
320
+ fm(editControl);
321
+ });
322
+ }
323
+ return editControl;
324
+
325
+ },
326
+ insertTemplate: function () {
327
+ if (!this.inserting)
328
+ return "";
329
+ var fm = this.fm_callback;
330
+
331
+ var insertControl = this.insertControl = $('<input type="text">');
332
+ if (typeof fm == 'function') {
333
+ return $('<button class="jsgrid-imgField-button">'+this.editButtonText+'</button>').click(function () {
334
+ fm(insertControl);
335
+ });
336
+ }
337
+ return insertControl;
338
+ },
339
+
340
+ insertValue: function () {
341
+ return this.insertControl.val();
342
+ },
343
+
344
+ editValue: function () {
345
+ return this.editControl.val();
346
+ },
347
+
348
+ _createTextBox: function () {
349
+ return $("<input>").attr("type", "text")
350
+ .prop("readonly", !!this.readOnly);
351
+ }
352
+
353
+ });
354
+
355
+ jsGrid.fields.XimgField = XimgField;
356
+
357
+ }(jsGrid, jQuery));
358
+ (function(jsGrid, $, undefined) {
359
+
360
+ // Standalone: does not extend jsGrid.SelectField, only jsGrid.Field.
361
+
362
+ var Field = jsGrid.Field;
363
+ var NUMBER_VALUE_TYPE = "number";
364
+
365
+ var Xselect = function (config) {
366
+ this.items = [];
367
+ this.selectedIndex = -1;
368
+ this.valueField = "";
369
+ this.textField = "";
370
+
371
+ if (config.valueField && config.items && config.items.length) {
372
+ var firstItemValue = config.items[0][config.valueField];
373
+ this.valueType = (typeof firstItemValue) === NUMBER_VALUE_TYPE ? NUMBER_VALUE_TYPE : "string";
374
+ }
375
+
376
+ this.sorter = this.valueType;
377
+
378
+ Field.call(this, config);
379
+ };
380
+
381
+ Xselect.prototype = new Field({
382
+ align: "center",
383
+ autosearch: true,
384
+ valueType: NUMBER_VALUE_TYPE,
385
+ pseudoElement: null,//pseudoElement that will be unsifted to start of select data in filters
386
+ select2: null,
387
+ defaultSelected: null,
388
+
389
+ itemTemplate: function (value) {
390
+ var items = this.items,
391
+ valueField = this.valueField,
392
+ textField = this.textField,
393
+ resultItem;
394
+
395
+ if (valueField) {
396
+ if (typeof(value) === "object") {
397
+ resultItem = value;
398
+ } else {
399
+ resultItem = $.grep(items, function (item) {
400
+ return item[valueField] === value;
401
+ })[0] || {};
402
+ }
403
+ } else {
404
+ resultItem = items[value];
405
+ }
406
+
407
+ var result = (textField ? resultItem[textField] : resultItem);
408
+
409
+ return (result === undefined || result === null) ? "" : result;
410
+ },
411
+
412
+ insertTemplate: function () {
413
+ if (!this.inserting)
414
+ return "";
415
+
416
+ return this.insertControl = this._createSelect();
417
+ },
418
+
419
+ editTemplate: function (value) {
420
+ if (!this.editing)
421
+ return this.itemTemplate.apply(this, arguments);
422
+
423
+ var $result = this.editControl = this._createSelect();
424
+ var editValue = value;
425
+ if (typeof(value) === "object") {
426
+ editValue = value[this.valueField];
427
+ }
428
+ (editValue !== undefined) && $result.val(editValue);
429
+ return $result;
430
+ },
431
+
432
+ insertValue: function () {
433
+ var val = this.insertControl.val();
434
+ return this.valueType === NUMBER_VALUE_TYPE ? parseInt(val || 0, 10) : val;
435
+ },
436
+
437
+ editValue: function () {
438
+ var val = this.editControl.val();
439
+ return this.valueType === NUMBER_VALUE_TYPE ? parseInt(val || 0, 10) : val;
440
+ },
441
+
442
+ filterTemplate: function () {
443
+ if (!this.filtering)
444
+ return "";
445
+ var data;
446
+ if (Array.isArray(this.items)) {
447
+ data = this.items.slice(0);
448
+ if (this.pseudoElement) {
449
+ data.unshift(this.pseudoElement);
450
+ } else {
451
+ var d = {};
452
+ d[this.textField] = '';
453
+ d[this.valueField] = null;
454
+ data.unshift(d);
455
+ }
456
+ } else if (typeof this.items === 'object') {
457
+ data = Object.assign({}, this.items);
458
+ if ((typeof this.pseudoElement === 'object') && this.pseudoElement) {
459
+ data = Object.assign({}, data, this.pseudoElement);
460
+ } else {
461
+ data = Object.assign({}, {'': null}, data);
462
+ }
463
+ }
464
+ if (this.defaultSelected !== null) {
465
+ var valueField = this.valueField;
466
+ var targetValue = this.defaultSelected;
467
+ var foundIndex = -1;
468
+
469
+ $.each(data, function (index, item) {
470
+ var value = valueField ? item[valueField] : index;
471
+ if (value == targetValue) {
472
+ foundIndex = index;
473
+ return false;
474
+ }
475
+ });
476
+ if (foundIndex !== -1) {
477
+ this.selectedIndex = foundIndex;
478
+ }
479
+ this.defaultSelected = null;
480
+ }
481
+
482
+ var grid = this._grid,
483
+ $result = this.filterControl = this._createSelect(data);
484
+
485
+ if (this.autosearch) {
486
+ $result.on("change", function (e) {
487
+ grid.search();
488
+ });
489
+ }
490
+
491
+ return $result;
492
+ },
493
+
494
+ filterValue: function () {
495
+ var val = this.filterControl.val();
496
+ return this.valueType === NUMBER_VALUE_TYPE ? parseInt(val || 0, 10) : val;
497
+ },
498
+
499
+ _createSelect: function (data) {
500
+ var $result = $("<select>"),
501
+ valueField = this.valueField,
502
+ textField = this.textField,
503
+ selectedIndex = this.selectedIndex;
504
+
505
+ $.each((data || this.items), function (index, item) {
506
+ var value = valueField ? item[valueField] : index,
507
+ text = textField ? item[textField] : item;
508
+
509
+ var $option = $("<option>")
510
+ .attr("value", value)
511
+ .text(text)
512
+ .appendTo($result);
513
+
514
+ $option.prop("selected", (selectedIndex === index));
515
+ });
516
+
517
+ $result.prop("disabled", !!this.readOnly);
518
+
519
+ if(this.select2){
520
+ var s2 = Object.assign({}, this.select2, {width: '100%'});
521
+ setTimeout(function() {
522
+ $result.select2(s2);
523
+ }, 0);
524
+ }
525
+
526
+ return $result;
527
+ }
528
+
529
+ });
530
+
531
+ jsGrid.fields.Xselect = Xselect;
532
+
533
+ }(jsGrid, jQuery));
534
+ (function(jsGrid, $, undefined) {
535
+
536
+ // Standalone: does not extend jsGrid.TextAreaField, only jsGrid.Field.
537
+
538
+ var Field = jsGrid.Field;
539
+
540
+ var Xtextarea = function (config) {
541
+ Field.call(this, config);
542
+ };
543
+
544
+ Xtextarea.prototype = new Field({
545
+ autosearch: true,
546
+ readOnly: false,
547
+ maxShowSymbols: 50,
548
+ defaultSelected: null,//value to preset the filter input with, applied once on first filter render then reset
549
+
550
+ filterTemplate: function () {
551
+ if (!this.filtering)
552
+ return "";
553
+
554
+ var grid = this._grid,
555
+ $result = this.filterControl = this._createTextBox();
556
+
557
+ if (this.autosearch) {
558
+ $result.on("keypress", function (e) {
559
+ if (e.which === 13) {
560
+ grid.search();
561
+ e.preventDefault();
562
+ }
563
+ });
564
+ }
565
+
566
+ if (this.defaultSelected !== null) {
567
+ $result.val(this.defaultSelected);
568
+ this.defaultSelected = null;
569
+ }
570
+
571
+ return $result;
572
+ },
573
+
574
+ filterValue: function () {
575
+ return this.filterControl.val();
576
+ },
577
+
578
+ insertTemplate: function () {
579
+ if (!this.inserting)
580
+ return "";
581
+
582
+ return this.insertControl = this._createTextArea();
583
+ },
584
+
585
+ editTemplate: function (value) {
586
+ if (!this.editing)
587
+ return this.itemTemplate.apply(this, arguments);
588
+
589
+ var $result = this.editControl = this._createTextArea();
590
+ $result.val(value);
591
+ return $result;
592
+ },
593
+
594
+ insertValue: function () {
595
+ return this.insertControl.val();
596
+ },
597
+
598
+ editValue: function () {
599
+ return this.editControl.val();
600
+ },
601
+
602
+ _createTextBox: function () {
603
+ return $("<input>").attr("type", "text")
604
+ .prop("readonly", !!this.readOnly);
605
+ },
606
+
607
+ _createTextArea: function () {
608
+ return $("<textarea>").prop("readonly", !!this.readOnly);
609
+ },
610
+
611
+ itemTemplate: function (value, item) {
612
+ value = value == null ? '' : String(value);
613
+
614
+ if (value.length <= this.maxShowSymbols) {
615
+ return $("<div>").text(value);
616
+ }
617
+ var str = value.slice(0, this.maxShowSymbols);
618
+ var div = $("<div>").text(str + ' ...').one("click",function () {
619
+ div.text(value);
620
+ return false;
621
+ });
622
+
623
+ return div;
624
+ }
625
+
626
+ });
627
+
628
+ jsGrid.fields.Xtextarea = Xtextarea;
629
+
630
+ }(jsGrid, jQuery));
631
+ (function(jsGrid, $, undefined) {
632
+
633
+ // Standalone: does not extend jsGrid.TextAreaField, only jsGrid.Field.
634
+
635
+ var Field = jsGrid.Field;
636
+
637
+ var Xjsoneditor = function (config) {
638
+ Field.call(this, config);
639
+ };
640
+
641
+ Xjsoneditor.prototype = new Field({
642
+ autosearch: true,
643
+ readOnly: false,
644
+ templates: [],
645
+ closeText: 'Save',
646
+ editText: "Editor",
647
+ defaultSelected: null,//value to preset the filter input with, applied once on first filter render then reset
648
+
649
+ filterTemplate: function () {
650
+ if (!this.filtering)
651
+ return "";
652
+
653
+ var grid = this._grid,
654
+ $result = this.filterControl = this._createTextBox();
655
+
656
+ if (this.autosearch) {
657
+ $result.on("keypress", function (e) {
658
+ if (e.which === 13) {
659
+ grid.search();
660
+ e.preventDefault();
661
+ }
662
+ });
663
+ }
664
+
665
+ if (this.defaultSelected !== null) {
666
+ $result.val(this.defaultSelected);
667
+ this.defaultSelected = null;
668
+ }
669
+
670
+ return $result;
671
+ },
672
+
673
+ filterValue: function () {
674
+ return this.filterControl.val();
675
+ },
676
+
677
+ insertValue: function () {
678
+ return this.insertControl.val();
679
+ },
680
+
681
+ editValue: function () {
682
+ return this.editControl.val();
683
+ },
684
+
685
+ _createTextBox: function () {
686
+ return $("<input>").attr("type", "text")
687
+ .prop("readonly", !!this.readOnly);
688
+ },
689
+
690
+ _doModal: function (formContent, options, resultControl) {
691
+ return jsGrid.popup(formContent, options);
692
+ },
693
+
694
+ _createJsonEditor: function (json, mode) {
695
+ if (typeof JSONEditor === 'undefined') {
696
+ throw new Error("Xjsoneditor requires the 'jsoneditor' package to be loaded on the page.");
697
+ }
698
+
699
+ json = json || {};
700
+ if (typeof json !== 'object') {
701
+ json = JSON.parse(json);
702
+ }
703
+
704
+ var container = $('<div style="height: 500px;">');
705
+ $('body').append(container);
706
+ container = container[0];
707
+ var options = {
708
+ templates: this.templates,
709
+ modes: ['code', 'text', 'tree'], // allowed modes
710
+ onError: function (err) {
711
+ alert(err.toString());
712
+ },
713
+ mode: mode || 'view'
714
+ };
715
+
716
+ return new JSONEditor(container, options, json);
717
+ },
718
+
719
+ itemTemplate: function (value, item) {
720
+ var f = this;
721
+
722
+ return $("<button>" + f.editText + "</button>").click(function () {
723
+ var editor = f._createJsonEditor(value);
724
+ f._doModal(editor.container, {
725
+ onClose: function () {
726
+ $(editor.container).remove();
727
+ editor.destroy();
728
+ }
729
+ });
730
+ return false;
731
+ });
732
+ },
733
+ insertTemplate: function () {
734
+ if (!this.inserting)
735
+ return "";
736
+
737
+ var f = this;
738
+
739
+ return this.insertControl = $("<textarea>").click(function () {
740
+ var editor = f._createJsonEditor({}, 'tree');
741
+ var ta = $(this);
742
+
743
+ f._doModal(editor.container, {
744
+ closeText: f.closeText,
745
+ onClose: function () {
746
+
747
+ var json = editor.get();
748
+ if (!$.isEmptyObject(json)) {
749
+ ta.val(JSON.stringify(json));
750
+ } else {
751
+ ta.val({});
752
+ }
753
+ editor.destroy();
754
+
755
+ }
756
+ });
757
+ return false;
758
+ });
759
+
760
+ },
761
+ editTemplate: function (value) {
762
+ if (!this.editing)
763
+ return this.itemTemplate.apply(this, arguments);
764
+
765
+
766
+ var f = this;
767
+
768
+ return this.editControl = $("<textarea>").val(value).click(function () {
769
+ var ta = $(this);
770
+ var editor = f._createJsonEditor(ta.val(), 'tree');
771
+
772
+
773
+ f._doModal(editor.container, {
774
+ closeText: f.closeText,
775
+ onClose: function () {
776
+
777
+ var json = editor.get();
778
+ if (!$.isEmptyObject(json)) {
779
+ ta.val(JSON.stringify(json));
780
+ } else {
781
+ ta.val({});
782
+ }
783
+ editor.destroy();
784
+
785
+ }
786
+ });
787
+ return false;
788
+ });
789
+ }
790
+
791
+ });
792
+
793
+ jsGrid.fields.Xjsoneditor = Xjsoneditor;
794
+
795
+ }(jsGrid, jQuery));
796
+ (function(jsGrid, $, undefined) {
797
+
798
+ var XRowSelectField = function (config) {
799
+ this.selectedItems = [];
800
+ // Must be generated per instance: the prototype literal is shared by
801
+ // every XRowSelectField, so a uid set there would be identical for
802
+ // all of them, letting unselectAll() clobber checkboxes from other
803
+ // grids/fields sharing the page.
804
+ this.uid = Date.now().toString(36) + Math.random().toString(36).substring(2);
805
+ jsGrid.Field.call(this, config);
806
+ };
807
+
808
+ XRowSelectField.prototype = new jsGrid.Field({
809
+ filtering: false,
810
+ deleteItemByItem: false,
811
+ buttonText: "",
812
+ selectedItemsAction: function (selectedItems) {
813
+
814
+ },
815
+ unselectAll: function () {
816
+ this.selectedItems = [];
817
+ this._grid._container.find('[data-uid=\'' + this.uid + '\'] ').prop('checked', false);
818
+ },
819
+ headerTemplate: function () {
820
+ if (!this.buttonText) {
821
+ return '';
822
+ }
823
+ var that = this;
824
+ return $("<button>").attr("type", "button").text(that.buttonText)
825
+ .on("click", function (event) {
826
+ that.selectedItemsAction(that.selectedItems);
827
+ event.stopPropagation();
828
+ });
829
+ },
830
+ itemTemplate: function (_, item) {
831
+ var that = this;
832
+ return $("<input data-uid='" + that.uid + "' type='checkbox'>")
833
+ .prop("checked", $.inArray(item, that.selectedItems) > -1)
834
+ .on("change", function () {
835
+ $(this).is(":checked") ? that.selectItem(item) : that.unselectItem(item);
836
+ }).click(function (event) {
837
+ event.stopPropagation();
838
+ });
839
+ },
840
+ editTemplate: function () {
841
+ return '';
842
+ },
843
+ align: "center",
844
+
845
+ selectItem: function (item) {
846
+ this.selectedItems.push(item);
847
+ },
848
+ unselectItem: function (item) {
849
+ this.selectedItems = $.grep(this.selectedItems, function (i) {
850
+ return i !== item;
851
+ });
852
+ }
853
+ });
854
+
855
+ jsGrid.fields.XRowSelectField = XRowSelectField;
856
+
857
+ }(jsGrid, jQuery));
858
+ (function(jsGrid, $, undefined) {
859
+ var XDateTimeField = function (config) {
860
+ jsGrid.Field.call(this, config);
861
+ };
862
+ XDateTimeField.prototype = new jsGrid.Field({
863
+
864
+ css: "date-field", // redefine general property 'css'
865
+ align: "center", // redefine general property 'align'
866
+ datePickerType: "datetime-local",
867
+ dateRange: false,
868
+ defaultSelected: null,//value (or {from, to} when dateRange is true) to preset the filter with, applied once on first filter render then reset
869
+ sorter: function (date1, date2) {
870
+ return new Date(date1) - new Date(date2);
871
+ },
872
+
873
+ filterTemplate: function () {
874
+ if (!this.filtering)
875
+ return "";
876
+
877
+
878
+ var grid = this._grid;
879
+ var $result = $();
880
+ if(this.dateRange){
881
+ var $container = $("<div class='jsgrid-date-range-wrapper'>");
882
+
883
+ var $startInput = $("<input>", {
884
+ "class": "jsgrid-date-picker jsgrid-date-start",
885
+ "type": this.datePickerType,
886
+ "title": "Period date start"
887
+ });
888
+
889
+ var $endInput = $("<input>", {
890
+ "class": "jsgrid-date-picker jsgrid-date-end",
891
+ "type": this.datePickerType,
892
+ "title": "Period date end"
893
+ });
894
+
895
+ $container.val = function () {
896
+ var fromVal = $startInput.val();
897
+ var toVal = $endInput.val();
898
+
899
+ return {
900
+ from: fromVal,
901
+ to: toVal
902
+ };
903
+ };
904
+
905
+ $result = this.filterControl = $container.append($startInput).append($endInput);
906
+
907
+ if (this.defaultSelected !== null) {
908
+ var range = this.defaultSelected || {};
909
+ $startInput.val(range.from || '');
910
+ $endInput.val(range.to || '');
911
+ this.defaultSelected = null;
912
+ }
913
+
914
+ if (this.autosearch) {
915
+ $result.on("change", ".jsgrid-date-picker", function (e) {
916
+ grid.search();
917
+ });
918
+ }
919
+ }else{
920
+ $result = this.filterControl = this._createPicker();
921
+
922
+ if (this.defaultSelected !== null) {
923
+ $result.val(this.defaultSelected);
924
+ this.defaultSelected = null;
925
+ }
926
+
927
+ if (this.autosearch) {
928
+ $result.on("change", function (e) {
929
+ grid.search();
930
+ });
931
+ }
932
+ }
933
+
934
+ return $result;
935
+ },
936
+
937
+ filterValue: function () {
938
+ return this.filterControl.val();
939
+ },
940
+
941
+ itemTemplate: function (value) {
942
+ if (!value) {
943
+ return '';
944
+ }
945
+ var options = this.options || {
946
+ weekday: 'short',
947
+ year: 'numeric',
948
+ month: 'short',
949
+ day: 'numeric',
950
+ hour: '2-digit',
951
+ minute: '2-digit',
952
+ second: '2-digit'
953
+ };
954
+ return new Date(value.replace(' ', 'T')).toLocaleDateString(undefined, options);
955
+ },
956
+
957
+ insertTemplate: function () {
958
+ return this._insertPicker = this._createPicker();
959
+ },
960
+
961
+ editTemplate: function (value) {
962
+ return this._editPicker = this._createPicker().val(value);
963
+ },
964
+
965
+ insertValue: function () {
966
+ return this._insertPicker.val();
967
+ },
968
+
969
+ editValue: function () {
970
+ return this._editPicker.val();
971
+ },
972
+ _createPicker: function () {
973
+ return $("<input class='date-picker'>").attr("type", this.datePickerType);
974
+ }
975
+ });
976
+
977
+
978
+ jsGrid.fields.XDateTimeField = XDateTimeField;
979
+ }(jsGrid, jQuery));