UNPKG

11.1 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.DataTable = undefined;
7
8var _extend = require('tinper-sparrow/src/extend');
9
10var _indexEvents = require('./indexEvents');
11
12var _copyRow = require('./copyRow');
13
14var _data = require('./data');
15
16var _enable = require('./enable');
17
18var _getCurrent = require('./getCurrent');
19
20var _getData = require('./getData');
21
22var _getFocus = require('./getFocus');
23
24var _getMeta = require('./getMeta');
25
26var _getPage = require('./getPage');
27
28var _getParam = require('./getParam');
29
30var _getSelect = require('./getSelect');
31
32var _getSimpleData = require('./getSimpleData');
33
34var _meta = require('./meta');
35
36var _page = require('./page');
37
38var _param = require('./param');
39
40var _ref = require('./ref');
41
42var _removeRow = require('./removeRow');
43
44var _row = require('./row');
45
46var _rowCurrent = require('./rowCurrent');
47
48var _rowDelete = require('./rowDelete');
49
50var _rowSelect = require('./rowSelect');
51
52var _rowFocus = require('./rowFocus');
53
54var _simpleData = require('./simpleData');
55
56var _util = require('./util');
57
58var _events = require('./events');
59
60function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /**
61 * Module : Kero webpack entry dataTable index
62 * Author : liuyk(liuyuekai@yonyou.com)
63 * Date : 2016-08-09 15:24:46
64 */
65
66var DataTable =
67// class DataTable extends Events{
68function DataTable(options) {
69 _classCallCheck(this, DataTable);
70
71 // IE9下转化之后的代码有问题,无法获得superClass方法
72 // super();
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 = {}; //ko.observable(1);
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 //dateNoconvert:true时,时间不转化,按真实走,false是,时间转换成long型
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
110DataTable.prototype.on = _events.on;
111DataTable.prototype.off = _events.off;
112DataTable.prototype.one = _events.one;
113DataTable.prototype.trigger = _events.trigger;
114DataTable.prototype.triggerReturn = _events.triggerReturn;
115DataTable.prototype.getEvent = _events.getEvent;
116//copyRow
117DataTable.prototype.copyRow = _copyRow.copyRow;
118DataTable.prototype.copyRows = _copyRow.copyRows;
119
120//data
121DataTable.prototype.setData = _data.setData;
122DataTable.prototype.setValue = _data.setValue;
123
124//enable
125DataTable.prototype.isEnable = _enable.isEnable;
126DataTable.prototype.setEnable = _enable.setEnable;
127
128//getData
129DataTable.prototype.getData = _getData.getData;
130DataTable.prototype.getDataByRule = _getData.getDataByRule;
131DataTable.prototype.getRow = _getData.getRow;
132DataTable.prototype.getChildRow = _getData.getChildRow;
133DataTable.prototype.getRowByRowId = _getData.getRowByRowId;
134DataTable.prototype.getRowIndex = _getData.getRowIndex;
135DataTable.prototype.getRowsByField = _getData.getRowsByField;
136DataTable.prototype.getRowByField = _getData.getRowByField;
137DataTable.prototype.getAllRows = _getData.getAllRows;
138DataTable.prototype.getAllPageRows = _getData.getAllPageRows;
139DataTable.prototype.getChangedDatas = _getData.getChangedDatas;
140DataTable.prototype.getChangedRows = _getData.getChangedRows;
141DataTable.prototype.getValue = _getData.getValue;
142DataTable.prototype.getIndexByRowId = _getData.getIndexByRowId;
143DataTable.prototype.getAllDatas = _getData.getAllDatas;
144DataTable.prototype.getRowIdsByIndices = _getData.getRowIdsByIndices;
145
146//getCurrent
147DataTable.prototype.getCurrentRow = _getCurrent.getCurrentRow;
148DataTable.prototype.getCurrentIndex = _getCurrent.getCurrentIndex;
149
150//getFocus
151DataTable.prototype.getFocusRow = _getFocus.getFocusRow;
152DataTable.prototype.getFocusIndex = _getFocus.getFocusIndex;
153
154//getMeta
155DataTable.prototype.getMeta = _getMeta.getMeta;
156DataTable.prototype.getRowMeta = _getMeta.getRowMeta;
157
158//getPage
159DataTable.prototype.getPage = _getPage.getPage;
160DataTable.prototype.getPages = _getPage.getPages;
161
162//getParam
163DataTable.prototype.getParam = _getParam.getParam;
164
165//getSelect
166DataTable.prototype.getSelectedIndex = _getSelect.getSelectedIndex;
167DataTable.prototype.getSelectedIndices = _getSelect.getSelectedIndices;
168DataTable.prototype.getSelectedIndexs = _getSelect.getSelectedIndexs;
169DataTable.prototype.getSelectedDatas = _getSelect.getSelectedDatas;
170DataTable.prototype.getSelectedRows = _getSelect.getSelectedRows;
171
172//getSimpleData
173DataTable.prototype.getSimpleData = _getSimpleData.getSimpleData;
174
175//meta
176DataTable.prototype.setMeta = _meta.setMeta;
177DataTable.prototype.updateMeta = _meta.updateMeta;
178DataTable.prototype.createField = _meta.createField;
179
180//page
181DataTable.prototype.setCurrentPage = _page.setCurrentPage;
182DataTable.prototype.updatePages = _page.updatePages;
183DataTable.prototype.setPages = _page.setPages;
184DataTable.prototype.hasPage = _page.hasPage;
185DataTable.prototype.clearCache = _page.clearCache;
186DataTable.prototype.cacheCurrentPage = _page.cacheCurrentPage;
187DataTable.prototype.updatePagesSelect = _page.updatePagesSelect;
188DataTable.prototype.updatePageRows = _page.updatePageRows;
189DataTable.prototype.updatePageSelect = _page.updatePageSelect;
190DataTable.prototype.updatePageFocus = _page.updatePageFocus;
191DataTable.prototype.updatePageAll = _page.updatePageAll;
192
193//param
194DataTable.prototype.addParam = _param.addParam;
195DataTable.prototype.addParams = _param.addParams;
196
197//ref
198DataTable.prototype.refSelectedRows = _ref.refSelectedRows;
199DataTable.prototype.ref = _ref.ref;
200DataTable.prototype.refMeta = _ref.refMeta;
201DataTable.prototype.refRowMeta = _ref.refRowMeta;
202DataTable.prototype.refEnable = _ref.refEnable;
203DataTable.prototype.refByRow = _ref.refByRow;
204
205//row
206DataTable.prototype.setRows = _row.setRows;
207DataTable.prototype.addRow = _row.addRow;
208DataTable.prototype.addRows = _row.addRows;
209DataTable.prototype.insertRow = _row.insertRow;
210DataTable.prototype.insertRows = _row.insertRows;
211DataTable.prototype.createEmptyRow = _row.createEmptyRow;
212
213//removeRow
214DataTable.prototype.removeRowByRowId = _removeRow.removeRowByRowId;
215DataTable.prototype.removeRow = _removeRow.removeRow;
216DataTable.prototype.removeAllRows = _removeRow.removeAllRows;
217DataTable.prototype.removeRows = _removeRow.removeRows;
218DataTable.prototype.clear = _removeRow.clear;
219
220//rowCurrent
221DataTable.prototype.updateCurrIndex = _rowCurrent.updateCurrIndex;
222
223//rowDelete
224DataTable.prototype.setRowDelete = _rowDelete.setRowDelete;
225DataTable.prototype.setAllRowsDelete = _rowDelete.setAllRowsDelete;
226DataTable.prototype.setRowsDelete = _rowDelete.setRowsDelete;
227
228//rowFocus
229DataTable.prototype.setRowFocus = _rowFocus.setRowFocus;
230DataTable.prototype.setRowUnFocus = _rowFocus.setRowUnFocus;
231DataTable.prototype.updateFocusIndex = _rowFocus.updateFocusIndex;
232
233//rowSelect
234DataTable.prototype.setAllRowsSelect = _rowSelect.setAllRowsSelect;
235DataTable.prototype.setRowSelect = _rowSelect.setRowSelect;
236DataTable.prototype.setRowsSelect = _rowSelect.setRowsSelect;
237DataTable.prototype.addRowSelect = _rowSelect.addRowSelect;
238DataTable.prototype.addRowsSelect = _rowSelect.addRowsSelect;
239DataTable.prototype.setAllRowsUnSelect = _rowSelect.setAllRowsUnSelect;
240DataTable.prototype.setRowUnSelect = _rowSelect.setRowUnSelect;
241DataTable.prototype.setRowsUnSelect = _rowSelect.setRowsUnSelect;
242DataTable.prototype.toggleAllSelect = _rowSelect.toggleAllSelect;
243DataTable.prototype.updateSelectedIndices = _rowSelect.updateSelectedIndices;
244
245//simpleData
246DataTable.prototype.setSimpleData = _simpleData.setSimpleData;
247DataTable.prototype.addSimpleData = _simpleData.addSimpleData;
248
249//util
250DataTable.prototype.isChanged = _util.isChanged;
251
252DataTable.DEFAULTS = {
253 pageSize: 20,
254 pageIndex: 0,
255 totalPages: 0,
256 pageCache: false,
257 enable: true
258};
259
260DataTable.META_DEFAULTS = {
261 enable: true,
262 required: false,
263 descs: {}
264};
265
266//事件类型
267DataTable.ON_ROW_SELECT = 'select';
268DataTable.ON_ROW_UNSELECT = 'unSelect';
269DataTable.ON_ROW_ALLSELECT = 'allSelect';
270DataTable.ON_ROW_ALLUNSELECT = 'allUnselect';
271DataTable.ON_VALUE_CHANGE = 'valueChange';
272DataTable.ON_BEFORE_VALUE_CHANGE = 'beforeValueCHange';
273DataTable.ON_CURRENT_VALUE_CHANGE = 'currentValueChange'; //当前行变化
274// DataTable.ON_AFTER_VALUE_CHANGE = 'afterValueChange'
275// DataTable.ON_ADD_ROW = 'addRow'
276DataTable.ON_INSERT = 'insert';
277DataTable.ON_UPDATE = 'update';
278DataTable.ON_CURRENT_UPDATE = 'currentUpdate';
279DataTable.ON_DELETE = 'delete';
280DataTable.ON_DELETE_ALL = 'deleteAll';
281DataTable.ON_ROW_FOCUS = 'focus';
282DataTable.ON_ROW_UNFOCUS = 'unFocus';
283DataTable.ON_LOAD = 'load';
284DataTable.ON_ENABLE_CHANGE = 'enableChange';
285DataTable.ON_META_CHANGE = 'metaChange';
286DataTable.ON_ROW_META_CHANGE = 'rowMetaChange';
287DataTable.ON_CURRENT_META_CHANGE = 'currentMetaChange';
288DataTable.ON_CURRENT_ROW_CHANGE = 'currentRowChange';
289
290DataTable.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
301DataTable.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
311exports.DataTable = DataTable;
\No newline at end of file