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,74 @@
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ function Field(config) {
4
+ $.extend(true, this, config);
5
+ this.sortingFunc = this._getSortingFunc();
6
+ }
7
+
8
+ Field.prototype = {
9
+ name: "",
10
+ title: null,
11
+ css: "",
12
+ align: "",
13
+ width: 100,
14
+
15
+ visible: true,
16
+ filtering: true,
17
+ inserting: true,
18
+ editing: true,
19
+ sorting: true,
20
+ sorter: "string", // name of SortStrategy or function to compare elements
21
+
22
+ includeInDataExport: true,
23
+
24
+ headerTemplate: function() {
25
+ return (this.title === undefined || this.title === null) ? this.name : this.title;
26
+ },
27
+
28
+ itemTemplate: function(value, item) {
29
+ return value;
30
+ },
31
+
32
+ filterTemplate: function() {
33
+ return "";
34
+ },
35
+
36
+ insertTemplate: function() {
37
+ return "";
38
+ },
39
+
40
+ editTemplate: function(value, item) {
41
+ this._value = value;
42
+ return this.itemTemplate(value, item);
43
+ },
44
+
45
+ filterValue: function() {
46
+ return "";
47
+ },
48
+
49
+ insertValue: function() {
50
+ return "";
51
+ },
52
+
53
+ editValue: function() {
54
+ return this._value;
55
+ },
56
+
57
+ _getSortingFunc: function() {
58
+ var sorter = this.sorter;
59
+
60
+ if($.isFunction(sorter)) {
61
+ return sorter;
62
+ }
63
+
64
+ if(typeof sorter === "string") {
65
+ return jsGrid.sortStrategies[sorter];
66
+ }
67
+
68
+ throw Error("wrong sorter for the field \"" + this.name + "\"!");
69
+ }
70
+ };
71
+
72
+ jsGrid.Field = Field;
73
+
74
+ }(jsGrid, jQuery));
@@ -0,0 +1,82 @@
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ function LoadIndicator(config) {
4
+ this._init(config);
5
+ }
6
+
7
+ LoadIndicator.prototype = {
8
+
9
+ container: "body",
10
+ message: "Loading...",
11
+ shading: true,
12
+
13
+ zIndex: 1000,
14
+ shaderClass: "jsgrid-load-shader",
15
+ loadPanelClass: "jsgrid-load-panel",
16
+
17
+ _init: function(config) {
18
+ $.extend(true, this, config);
19
+
20
+ this._initContainer();
21
+ this._initShader();
22
+ this._initLoadPanel();
23
+ },
24
+
25
+ _initContainer: function() {
26
+ this._container = $(this.container);
27
+ },
28
+
29
+ _initShader: function() {
30
+ if(!this.shading)
31
+ return;
32
+
33
+ this._shader = $("<div>").addClass(this.shaderClass)
34
+ .hide()
35
+ .css({
36
+ position: "absolute",
37
+ top: 0,
38
+ right: 0,
39
+ bottom: 0,
40
+ left: 0,
41
+ zIndex: this.zIndex
42
+ })
43
+ .appendTo(this._container);
44
+ },
45
+
46
+ _initLoadPanel: function() {
47
+ this._loadPanel = $("<div>").addClass(this.loadPanelClass)
48
+ .text(this.message)
49
+ .hide()
50
+ .css({
51
+ position: "absolute",
52
+ top: "50%",
53
+ left: "50%",
54
+ zIndex: this.zIndex
55
+ })
56
+ .appendTo(this._container);
57
+ },
58
+
59
+ show: function() {
60
+ var $loadPanel = this._loadPanel.show();
61
+
62
+ var actualWidth = $loadPanel.outerWidth();
63
+ var actualHeight = $loadPanel.outerHeight();
64
+
65
+ $loadPanel.css({
66
+ marginTop: -actualHeight / 2,
67
+ marginLeft: -actualWidth / 2
68
+ });
69
+
70
+ this._shader.show();
71
+ },
72
+
73
+ hide: function() {
74
+ this._loadPanel.hide();
75
+ this._shader.hide();
76
+ }
77
+
78
+ };
79
+
80
+ jsGrid.LoadIndicator = LoadIndicator;
81
+
82
+ }(jsGrid, jQuery));
@@ -0,0 +1,131 @@
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ function DirectLoadingStrategy(grid) {
4
+ this._grid = grid;
5
+ }
6
+
7
+ DirectLoadingStrategy.prototype = {
8
+
9
+ firstDisplayIndex: function() {
10
+ var grid = this._grid;
11
+ return grid.option("paging") ? (grid.option("pageIndex") - 1) * grid.option("pageSize") : 0;
12
+ },
13
+
14
+ lastDisplayIndex: function() {
15
+ var grid = this._grid;
16
+ var itemsCount = grid.option("data").length;
17
+
18
+ return grid.option("paging")
19
+ ? Math.min(grid.option("pageIndex") * grid.option("pageSize"), itemsCount)
20
+ : itemsCount;
21
+ },
22
+
23
+ itemsCount: function() {
24
+ return this._grid.option("data").length;
25
+ },
26
+
27
+ openPage: function(index) {
28
+ this._grid.refresh();
29
+ },
30
+
31
+ loadParams: function() {
32
+ return {};
33
+ },
34
+
35
+ sort: function() {
36
+ this._grid._sortData();
37
+ this._grid.refresh();
38
+ return $.Deferred().resolve().promise();
39
+ },
40
+
41
+ reset: function() {
42
+ this._grid.refresh();
43
+ return $.Deferred().resolve().promise();
44
+ },
45
+
46
+ finishLoad: function(loadedData) {
47
+ this._grid.option("data", loadedData);
48
+ },
49
+
50
+ finishInsert: function(insertedItem, location) {
51
+ var grid = this._grid;
52
+
53
+ switch(location){
54
+ case "top":
55
+ grid.option("data").unshift(insertedItem);
56
+ break;
57
+ case "bottom":
58
+ default:
59
+ grid.option("data").push(insertedItem);
60
+ }
61
+
62
+ grid.refresh();
63
+ },
64
+
65
+ finishDelete: function(deletedItem, deletedItemIndex) {
66
+ var grid = this._grid;
67
+ grid.option("data").splice(deletedItemIndex, 1);
68
+ grid.reset();
69
+ }
70
+ };
71
+
72
+
73
+ function PageLoadingStrategy(grid) {
74
+ this._grid = grid;
75
+ this._itemsCount = 0;
76
+ }
77
+
78
+ PageLoadingStrategy.prototype = {
79
+
80
+ firstDisplayIndex: function() {
81
+ return 0;
82
+ },
83
+
84
+ lastDisplayIndex: function() {
85
+ return this._grid.option("data").length;
86
+ },
87
+
88
+ itemsCount: function() {
89
+ return this._itemsCount;
90
+ },
91
+
92
+ openPage: function(index) {
93
+ this._grid.loadData();
94
+ },
95
+
96
+ loadParams: function() {
97
+ var grid = this._grid;
98
+ return {
99
+ pageIndex: grid.option("pageIndex"),
100
+ pageSize: grid.option("pageSize")
101
+ };
102
+ },
103
+
104
+ reset: function() {
105
+ return this._grid.loadData();
106
+ },
107
+
108
+ sort: function() {
109
+ return this._grid.loadData();
110
+ },
111
+
112
+ finishLoad: function(loadedData) {
113
+ this._itemsCount = loadedData.itemsCount;
114
+ this._grid.option("data", loadedData.data);
115
+ },
116
+
117
+ finishInsert: function(insertedItem) {
118
+ this._grid.search();
119
+ },
120
+
121
+ finishDelete: function(deletedItem, deletedItemIndex) {
122
+ this._grid.search();
123
+ }
124
+ };
125
+
126
+ jsGrid.loadStrategies = {
127
+ DirectLoadingStrategy: DirectLoadingStrategy,
128
+ PageLoadingStrategy: PageLoadingStrategy
129
+ };
130
+
131
+ }(jsGrid, jQuery));
@@ -0,0 +1,49 @@
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ var isDefined = function(val) {
4
+ return typeof(val) !== "undefined" && val !== null;
5
+ };
6
+
7
+ var sortStrategies = {
8
+ string: function(str1, str2) {
9
+ if(!isDefined(str1) && !isDefined(str2))
10
+ return 0;
11
+
12
+ if(!isDefined(str1))
13
+ return -1;
14
+
15
+ if(!isDefined(str2))
16
+ return 1;
17
+
18
+ return ("" + str1).localeCompare("" + str2);
19
+ },
20
+
21
+ stringNaturalSort: function(str1, str2) {
22
+ if(!isDefined(str1) && !isDefined(str2))
23
+ return 0;
24
+
25
+ if(!isDefined(str1))
26
+ return -1;
27
+
28
+ if(!isDefined(str2))
29
+ return 1;
30
+
31
+ return ("" + str1).localeCompare("" + str2, undefined, { numeric: true, sensitivity: 'base' });
32
+ },
33
+
34
+ number: function(n1, n2) {
35
+ return n1 - n2;
36
+ },
37
+
38
+ date: function(dt1, dt2) {
39
+ return dt1 - dt2;
40
+ },
41
+
42
+ numberAsString: function(n1, n2) {
43
+ return parseFloat(n1) - parseFloat(n2);
44
+ }
45
+ };
46
+
47
+ jsGrid.sortStrategies = sortStrategies;
48
+
49
+ }(jsGrid, jQuery));
@@ -0,0 +1,135 @@
1
+ (function(jsGrid, $, undefined) {
2
+
3
+ function Validation(config) {
4
+ this._init(config);
5
+ }
6
+
7
+ Validation.prototype = {
8
+
9
+ _init: function(config) {
10
+ $.extend(true, this, config);
11
+ },
12
+
13
+ validate: function(args) {
14
+ var errors = [];
15
+
16
+ $.each(this._normalizeRules(args.rules), function(_, rule) {
17
+ if(rule.validator(args.value, args.item, rule.param))
18
+ return;
19
+
20
+ var errorMessage = $.isFunction(rule.message) ? rule.message(args.value, args.item) : rule.message;
21
+ errors.push(errorMessage);
22
+ });
23
+
24
+ return errors;
25
+ },
26
+
27
+ _normalizeRules: function(rules) {
28
+ if(!$.isArray(rules))
29
+ rules = [rules];
30
+
31
+ return $.map(rules, $.proxy(function(rule) {
32
+ return this._normalizeRule(rule);
33
+ }, this));
34
+ },
35
+
36
+ _normalizeRule: function(rule) {
37
+ if(typeof rule === "string")
38
+ rule = { validator: rule };
39
+
40
+ if($.isFunction(rule))
41
+ rule = { validator: rule };
42
+
43
+ if($.isPlainObject(rule))
44
+ rule = $.extend({}, rule);
45
+ else
46
+ throw Error("wrong validation config specified");
47
+
48
+ if($.isFunction(rule.validator))
49
+ return rule;
50
+
51
+ return this._applyNamedValidator(rule, rule.validator);
52
+ },
53
+
54
+ _applyNamedValidator: function(rule, validatorName) {
55
+ delete rule.validator;
56
+
57
+ var validator = validators[validatorName];
58
+ if(!validator)
59
+ throw Error("unknown validator \"" + validatorName + "\"");
60
+
61
+ if($.isFunction(validator)) {
62
+ validator = { validator: validator };
63
+ }
64
+
65
+ return $.extend({}, validator, rule);
66
+ }
67
+ };
68
+
69
+ jsGrid.Validation = Validation;
70
+
71
+
72
+ var validators = {
73
+ required: {
74
+ message: "Field is required",
75
+ validator: function(value) {
76
+ return value !== undefined && value !== null && value !== "";
77
+ }
78
+ },
79
+
80
+ rangeLength: {
81
+ message: "Field value length is out of the defined range",
82
+ validator: function(value, _, param) {
83
+ return value.length >= param[0] && value.length <= param[1];
84
+ }
85
+ },
86
+
87
+ minLength: {
88
+ message: "Field value is too short",
89
+ validator: function(value, _, param) {
90
+ return value.length >= param;
91
+ }
92
+ },
93
+
94
+ maxLength: {
95
+ message: "Field value is too long",
96
+ validator: function(value, _, param) {
97
+ return value.length <= param;
98
+ }
99
+ },
100
+
101
+ pattern: {
102
+ message: "Field value is not matching the defined pattern",
103
+ validator: function(value, _, param) {
104
+ if(typeof param === "string") {
105
+ param = new RegExp("^(?:" + param + ")$");
106
+ }
107
+ return param.test(value);
108
+ }
109
+ },
110
+
111
+ range: {
112
+ message: "Field value is out of the defined range",
113
+ validator: function(value, _, param) {
114
+ return value >= param[0] && value <= param[1];
115
+ }
116
+ },
117
+
118
+ min: {
119
+ message: "Field value is too small",
120
+ validator: function(value, _, param) {
121
+ return value >= param;
122
+ }
123
+ },
124
+
125
+ max: {
126
+ message: "Field value is too large",
127
+ validator: function(value, _, param) {
128
+ return value <= param;
129
+ }
130
+ }
131
+ };
132
+
133
+ jsGrid.validators = validators;
134
+
135
+ }(jsGrid, jQuery));
@@ -0,0 +1,37 @@
1
+ (function($, undefined) {
2
+ var baseJsGrid = $.fn.jsGrid;
3
+ if (!baseJsGrid) return;
4
+
5
+ $.fn.jsGrid = function (options) {
6
+ if (typeof options === "object") {
7
+ var originalOnRefreshed = options.onRefreshed;
8
+
9
+ options.onRefreshed = function (args) {
10
+ if (originalOnRefreshed) originalOnRefreshed.apply(this, arguments);
11
+
12
+ var grid = args.grid;
13
+ var data = grid.option("data") || [];
14
+ var fields = grid.option("fields") || [];
15
+
16
+ var $table = grid._container.find(".jsgrid-table").last();
17
+ $table.find(".jsgrid-summary-footer").remove();
18
+
19
+ var $tfoot = $("<tfoot class='jsgrid-summary-footer'>").appendTo($table);
20
+ var $tr = $("<tr>").addClass("jsgrid-row").css({
21
+ "background": "#e1e1e1",
22
+ "font-weight": "bold"
23
+ }).appendTo($tfoot);
24
+
25
+ fields.forEach(function (field) {
26
+ var $td = $("<td>").addClass("jsgrid-cell").appendTo($tr);
27
+ if (typeof field.summary === "function") {
28
+ var result = field.summary.call(field, data);
29
+ $td.html(result);
30
+ }
31
+ });
32
+ };
33
+ }
34
+
35
+ return baseJsGrid.apply(this, arguments);
36
+ };
37
+ }(jQuery));
@@ -0,0 +1,107 @@
1
+ (function(jsGrid, $, undefined) {
2
+ if (!jsGrid) {
3
+ console.log("jsGrid is not defined!");
4
+ return;
5
+ }
6
+ jsGrid.popup = jsGrid.popupBasic = function (formContent, options) {
7
+ this.idcounter = this.idcounter || 0;
8
+ this.idcounter++;
9
+
10
+
11
+ options = options || {};
12
+
13
+ options.closeText = options.closeText || 'Close';
14
+ options.heading = options.heading || '';
15
+
16
+ options.styles = options.styles || '.jsGridpopupBasicOverlay {' +
17
+ ' position: fixed;' +
18
+ ' top: 0;' +
19
+ ' bottom: 0;' +
20
+ ' left: 0;' +
21
+ ' right: 0;' +
22
+ ' background: rgba(0, 0, 0, 0.7);' +
23
+ ' transition: opacity 500ms;' +
24
+ ' opacity: 1;' +
25
+ '}' +
26
+ '' +
27
+ '.jsGridpopupBasicPopup {' +
28
+ ' margin: 70px auto;' +
29
+ ' padding: 20px;' +
30
+ ' min-height: 60%;'+
31
+ ' background: #fff;' +
32
+ ' border-radius: 5px;' +
33
+ ' width: 60%;' +
34
+ ' position: relative;' +
35
+ ' transition: all 300ms ease-in-out;' +
36
+ '}' +
37
+ '' +
38
+ '.jsGridpopupBasicPopup h2 {' +
39
+ ' margin-top: 0;' +
40
+ ' color: #333;' +
41
+ ' font-family: Tahoma, Arial, sans-serif;' +
42
+ '}' +
43
+ '.jsGridpopupBasicPopup .close {' +
44
+ ' position: absolute;' +
45
+ ' top: 10px;' +
46
+ ' right: 30px;' +
47
+ ' transition: all 200ms;' +
48
+ ' font-size: 30px;' +
49
+ ' font-weight: bold;' +
50
+ ' text-decoration: none;' +
51
+ ' color: #333;' +
52
+ '}' +
53
+ '.jsGridpopupBasicPopup .close:hover {' +
54
+ ' color: #06D85F;' +
55
+ '}' +
56
+ '.jsGridpopupBasicPopup .jsGridpopupBasicContent {' +
57
+ ' max-height: 30%;' +
58
+ ' overflow: auto;' +
59
+ '}' +
60
+ '' +
61
+ '@media screen and (max-width: 700px){' +
62
+ ' .jsGridpopupBasicPopup{' +
63
+ ' width: 70%;' +
64
+ ' }' +
65
+ '}';
66
+
67
+ if(!$('#jsGridpopupBasicStyles').length){
68
+ var $head = $("head");
69
+ var $headlinklast = $head.find("link[rel='stylesheet']:last");
70
+ var linkElement = "<style id='jsGridpopupBasicStyles'>" + options.styles + "</style>";
71
+ if ($headlinklast.length) {
72
+ $headlinklast.after(linkElement);
73
+ } else {
74
+ $head.append(linkElement);
75
+ }
76
+
77
+ }
78
+ var id = "jsGridpopupBasic" + this.idcounter;
79
+ var popup = $(
80
+ '<div id="' + id + '" class="jsGridpopupBasicOverlay">' +
81
+ '<div class="jsGridpopupBasicPopup">' +
82
+ '<h2></h2>'+
83
+ '<a class="close" href="#">&times;</a>' +
84
+ '<div class="jsGridpopupBasicContent">' +
85
+ '' +
86
+ '</div>' +
87
+ '</div>' +
88
+ '</div>');
89
+
90
+ popup.find('h2').text(options.heading);
91
+ popup.find('.jsGridpopupBasicContent').append(formContent);
92
+ popup.find('.close').click(function () {
93
+ if (options.onClose instanceof Function) {
94
+ options.onClose(popup);
95
+ }
96
+ popup.remove();
97
+ });
98
+ $('body').append(popup);
99
+ return {
100
+ 'id': id,
101
+ '$popup': popup,
102
+ 'hide':function () {
103
+ popup.remove();
104
+ }
105
+ };
106
+ }
107
+ }(jsGrid, jQuery));