1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.DataTable = undefined;
|
7 |
|
8 | var _extend = require('tinper-sparrow/src/extend');
|
9 |
|
10 | var _indexEvents = require('./indexEvents');
|
11 |
|
12 | var _copyRow = require('./copyRow');
|
13 |
|
14 | var _data = require('./data');
|
15 |
|
16 | var _enable = require('./enable');
|
17 |
|
18 | var _getCurrent = require('./getCurrent');
|
19 |
|
20 | var _getData = require('./getData');
|
21 |
|
22 | var _getFocus = require('./getFocus');
|
23 |
|
24 | var _getMeta = require('./getMeta');
|
25 |
|
26 | var _getPage = require('./getPage');
|
27 |
|
28 | var _getParam = require('./getParam');
|
29 |
|
30 | var _getSelect = require('./getSelect');
|
31 |
|
32 | var _getSimpleData = require('./getSimpleData');
|
33 |
|
34 | var _meta = require('./meta');
|
35 |
|
36 | var _page = require('./page');
|
37 |
|
38 | var _param = require('./param');
|
39 |
|
40 | var _ref = require('./ref');
|
41 |
|
42 | var _removeRow = require('./removeRow');
|
43 |
|
44 | var _row = require('./row');
|
45 |
|
46 | var _rowCurrent = require('./rowCurrent');
|
47 |
|
48 | var _rowDelete = require('./rowDelete');
|
49 |
|
50 | var _rowSelect = require('./rowSelect');
|
51 |
|
52 | var _rowFocus = require('./rowFocus');
|
53 |
|
54 | var _simpleData = require('./simpleData');
|
55 |
|
56 | var _util = require('./util');
|
57 |
|
58 | var _events = require('./events');
|
59 |
|
60 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | var DataTable =
|
67 |
|
68 | function DataTable(options) {
|
69 | _classCallCheck(this, DataTable);
|
70 |
|
71 |
|
72 |
|
73 | options = options || {};
|
74 | this.id = options['id'];
|
75 | this.strict = options['strict'] || false;
|
76 | this.meta = DataTable.createMetaItems(options['meta']);
|
77 | this.enable = options['enable'] || DataTable.DEFAULTS.enable;
|
78 | this.pageSize = ko.observable(options['pageSize'] || DataTable.DEFAULTS.pageSize);
|
79 | this.pageIndex = ko.observable(options['pageIndex'] || DataTable.DEFAULTS.pageIndex);
|
80 | this.totalPages = ko.observable(options['totalPages'] || DataTable.DEFAULTS.totalPages);
|
81 | this.totalRow = ko.observable();
|
82 | this.pageCache = options['pageCache'] === undefined ? DataTable.DEFAULTS.pageCache : options['pageCache'];
|
83 | this.rows = ko.observableArray([]);
|
84 | this.selectedIndices = ko.observableArray([]);
|
85 | this._oldCurrentIndex = -1;
|
86 | this.focusIndex = ko.observable(-1);
|
87 | this.cachedPages = [];
|
88 | this.metaChange = {};
|
89 | this.valueChange = {};
|
90 | this.currentRowChange = ko.observable(1);
|
91 | this.enableChange = ko.observable(1);
|
92 | this.params = options['params'] || {};
|
93 | this.master = options['master'] || '';
|
94 | this.allSelected = ko.observable(false);
|
95 |
|
96 | this.dateNoConvert = options['dateNoConvert'];
|
97 | if (options['root']) {
|
98 | this.root = options['root'];
|
99 | } else {
|
100 | this.root = this;
|
101 | }
|
102 | if (options['ns']) {
|
103 | this.ns = options['ns'];
|
104 | } else {
|
105 | this.ns = '';
|
106 | }
|
107 | this.newCount = 0;
|
108 | };
|
109 |
|
110 | DataTable.prototype.on = _events.on;
|
111 | DataTable.prototype.off = _events.off;
|
112 | DataTable.prototype.one = _events.one;
|
113 | DataTable.prototype.trigger = _events.trigger;
|
114 | DataTable.prototype.triggerReturn = _events.triggerReturn;
|
115 | DataTable.prototype.getEvent = _events.getEvent;
|
116 |
|
117 | DataTable.prototype.copyRow = _copyRow.copyRow;
|
118 | DataTable.prototype.copyRows = _copyRow.copyRows;
|
119 |
|
120 |
|
121 | DataTable.prototype.setData = _data.setData;
|
122 | DataTable.prototype.setValue = _data.setValue;
|
123 |
|
124 |
|
125 | DataTable.prototype.isEnable = _enable.isEnable;
|
126 | DataTable.prototype.setEnable = _enable.setEnable;
|
127 |
|
128 |
|
129 | DataTable.prototype.getData = _getData.getData;
|
130 | DataTable.prototype.getDataByRule = _getData.getDataByRule;
|
131 | DataTable.prototype.getRow = _getData.getRow;
|
132 | DataTable.prototype.getChildRow = _getData.getChildRow;
|
133 | DataTable.prototype.getRowByRowId = _getData.getRowByRowId;
|
134 | DataTable.prototype.getRowIndex = _getData.getRowIndex;
|
135 | DataTable.prototype.getRowsByField = _getData.getRowsByField;
|
136 | DataTable.prototype.getRowByField = _getData.getRowByField;
|
137 | DataTable.prototype.getAllRows = _getData.getAllRows;
|
138 | DataTable.prototype.getAllPageRows = _getData.getAllPageRows;
|
139 | DataTable.prototype.getChangedDatas = _getData.getChangedDatas;
|
140 | DataTable.prototype.getChangedRows = _getData.getChangedRows;
|
141 | DataTable.prototype.getValue = _getData.getValue;
|
142 | DataTable.prototype.getIndexByRowId = _getData.getIndexByRowId;
|
143 | DataTable.prototype.getAllDatas = _getData.getAllDatas;
|
144 | DataTable.prototype.getRowIdsByIndices = _getData.getRowIdsByIndices;
|
145 |
|
146 |
|
147 | DataTable.prototype.getCurrentRow = _getCurrent.getCurrentRow;
|
148 | DataTable.prototype.getCurrentIndex = _getCurrent.getCurrentIndex;
|
149 |
|
150 |
|
151 | DataTable.prototype.getFocusRow = _getFocus.getFocusRow;
|
152 | DataTable.prototype.getFocusIndex = _getFocus.getFocusIndex;
|
153 |
|
154 |
|
155 | DataTable.prototype.getMeta = _getMeta.getMeta;
|
156 | DataTable.prototype.getRowMeta = _getMeta.getRowMeta;
|
157 |
|
158 |
|
159 | DataTable.prototype.getPage = _getPage.getPage;
|
160 | DataTable.prototype.getPages = _getPage.getPages;
|
161 |
|
162 |
|
163 | DataTable.prototype.getParam = _getParam.getParam;
|
164 |
|
165 |
|
166 | DataTable.prototype.getSelectedIndex = _getSelect.getSelectedIndex;
|
167 | DataTable.prototype.getSelectedIndices = _getSelect.getSelectedIndices;
|
168 | DataTable.prototype.getSelectedIndexs = _getSelect.getSelectedIndexs;
|
169 | DataTable.prototype.getSelectedDatas = _getSelect.getSelectedDatas;
|
170 | DataTable.prototype.getSelectedRows = _getSelect.getSelectedRows;
|
171 |
|
172 |
|
173 | DataTable.prototype.getSimpleData = _getSimpleData.getSimpleData;
|
174 |
|
175 |
|
176 | DataTable.prototype.setMeta = _meta.setMeta;
|
177 | DataTable.prototype.updateMeta = _meta.updateMeta;
|
178 | DataTable.prototype.createField = _meta.createField;
|
179 |
|
180 |
|
181 | DataTable.prototype.setCurrentPage = _page.setCurrentPage;
|
182 | DataTable.prototype.updatePages = _page.updatePages;
|
183 | DataTable.prototype.setPages = _page.setPages;
|
184 | DataTable.prototype.hasPage = _page.hasPage;
|
185 | DataTable.prototype.clearCache = _page.clearCache;
|
186 | DataTable.prototype.cacheCurrentPage = _page.cacheCurrentPage;
|
187 | DataTable.prototype.updatePagesSelect = _page.updatePagesSelect;
|
188 | DataTable.prototype.updatePageRows = _page.updatePageRows;
|
189 | DataTable.prototype.updatePageSelect = _page.updatePageSelect;
|
190 | DataTable.prototype.updatePageFocus = _page.updatePageFocus;
|
191 | DataTable.prototype.updatePageAll = _page.updatePageAll;
|
192 |
|
193 |
|
194 | DataTable.prototype.addParam = _param.addParam;
|
195 | DataTable.prototype.addParams = _param.addParams;
|
196 |
|
197 |
|
198 | DataTable.prototype.refSelectedRows = _ref.refSelectedRows;
|
199 | DataTable.prototype.ref = _ref.ref;
|
200 | DataTable.prototype.refMeta = _ref.refMeta;
|
201 | DataTable.prototype.refRowMeta = _ref.refRowMeta;
|
202 | DataTable.prototype.refEnable = _ref.refEnable;
|
203 | DataTable.prototype.refByRow = _ref.refByRow;
|
204 |
|
205 |
|
206 | DataTable.prototype.setRows = _row.setRows;
|
207 | DataTable.prototype.addRow = _row.addRow;
|
208 | DataTable.prototype.addRows = _row.addRows;
|
209 | DataTable.prototype.insertRow = _row.insertRow;
|
210 | DataTable.prototype.insertRows = _row.insertRows;
|
211 | DataTable.prototype.createEmptyRow = _row.createEmptyRow;
|
212 |
|
213 |
|
214 | DataTable.prototype.removeRowByRowId = _removeRow.removeRowByRowId;
|
215 | DataTable.prototype.removeRow = _removeRow.removeRow;
|
216 | DataTable.prototype.removeAllRows = _removeRow.removeAllRows;
|
217 | DataTable.prototype.removeRows = _removeRow.removeRows;
|
218 | DataTable.prototype.clear = _removeRow.clear;
|
219 |
|
220 |
|
221 | DataTable.prototype.updateCurrIndex = _rowCurrent.updateCurrIndex;
|
222 |
|
223 |
|
224 | DataTable.prototype.setRowDelete = _rowDelete.setRowDelete;
|
225 | DataTable.prototype.setAllRowsDelete = _rowDelete.setAllRowsDelete;
|
226 | DataTable.prototype.setRowsDelete = _rowDelete.setRowsDelete;
|
227 |
|
228 |
|
229 | DataTable.prototype.setRowFocus = _rowFocus.setRowFocus;
|
230 | DataTable.prototype.setRowUnFocus = _rowFocus.setRowUnFocus;
|
231 | DataTable.prototype.updateFocusIndex = _rowFocus.updateFocusIndex;
|
232 |
|
233 |
|
234 | DataTable.prototype.setAllRowsSelect = _rowSelect.setAllRowsSelect;
|
235 | DataTable.prototype.setRowSelect = _rowSelect.setRowSelect;
|
236 | DataTable.prototype.setRowsSelect = _rowSelect.setRowsSelect;
|
237 | DataTable.prototype.addRowSelect = _rowSelect.addRowSelect;
|
238 | DataTable.prototype.addRowsSelect = _rowSelect.addRowsSelect;
|
239 | DataTable.prototype.setAllRowsUnSelect = _rowSelect.setAllRowsUnSelect;
|
240 | DataTable.prototype.setRowUnSelect = _rowSelect.setRowUnSelect;
|
241 | DataTable.prototype.setRowsUnSelect = _rowSelect.setRowsUnSelect;
|
242 | DataTable.prototype.toggleAllSelect = _rowSelect.toggleAllSelect;
|
243 | DataTable.prototype.updateSelectedIndices = _rowSelect.updateSelectedIndices;
|
244 |
|
245 |
|
246 | DataTable.prototype.setSimpleData = _simpleData.setSimpleData;
|
247 | DataTable.prototype.addSimpleData = _simpleData.addSimpleData;
|
248 |
|
249 |
|
250 | DataTable.prototype.isChanged = _util.isChanged;
|
251 |
|
252 | DataTable.DEFAULTS = {
|
253 | pageSize: 20,
|
254 | pageIndex: 0,
|
255 | totalPages: 0,
|
256 | pageCache: false,
|
257 | enable: true
|
258 | };
|
259 |
|
260 | DataTable.META_DEFAULTS = {
|
261 | enable: true,
|
262 | required: false,
|
263 | descs: {}
|
264 | };
|
265 |
|
266 |
|
267 | DataTable.ON_ROW_SELECT = 'select';
|
268 | DataTable.ON_ROW_UNSELECT = 'unSelect';
|
269 | DataTable.ON_ROW_ALLSELECT = 'allSelect';
|
270 | DataTable.ON_ROW_ALLUNSELECT = 'allUnselect';
|
271 | DataTable.ON_VALUE_CHANGE = 'valueChange';
|
272 | DataTable.ON_BEFORE_VALUE_CHANGE = 'beforeValueCHange';
|
273 | DataTable.ON_CURRENT_VALUE_CHANGE = 'currentValueChange';
|
274 |
|
275 |
|
276 | DataTable.ON_INSERT = 'insert';
|
277 | DataTable.ON_UPDATE = 'update';
|
278 | DataTable.ON_CURRENT_UPDATE = 'currentUpdate';
|
279 | DataTable.ON_DELETE = 'delete';
|
280 | DataTable.ON_DELETE_ALL = 'deleteAll';
|
281 | DataTable.ON_ROW_FOCUS = 'focus';
|
282 | DataTable.ON_ROW_UNFOCUS = 'unFocus';
|
283 | DataTable.ON_LOAD = 'load';
|
284 | DataTable.ON_ENABLE_CHANGE = 'enableChange';
|
285 | DataTable.ON_META_CHANGE = 'metaChange';
|
286 | DataTable.ON_ROW_META_CHANGE = 'rowMetaChange';
|
287 | DataTable.ON_CURRENT_META_CHANGE = 'currentMetaChange';
|
288 | DataTable.ON_CURRENT_ROW_CHANGE = 'currentRowChange';
|
289 |
|
290 | DataTable.SUBMIT = {
|
291 | current: 'current',
|
292 | focus: 'focus',
|
293 | all: 'all',
|
294 | select: 'select',
|
295 | change: 'change',
|
296 | empty: 'empty',
|
297 | allSelect: 'allSelect',
|
298 | allPages: 'allPages'
|
299 | };
|
300 |
|
301 | DataTable.createMetaItems = function (metas) {
|
302 | var newMetas = {};
|
303 | for (var key in metas) {
|
304 | var meta = metas[key];
|
305 | if (typeof meta == 'string') meta = {};
|
306 | newMetas[key] = (0, _extend.extend)({}, DataTable.META_DEFAULTS, meta);
|
307 | }
|
308 | return newMetas;
|
309 | };
|
310 |
|
311 | exports.DataTable = DataTable; |
\ | No newline at end of file |