1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createEmptyRow = exports.insertRows = exports.insertRow = exports.addRows = exports.addRow = exports.setRows = undefined;
|
7 |
|
8 | var _util = require('tinper-sparrow/src/util');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var setRows = function setRows(rows, options) {
|
15 | var insertRows = [],
|
16 | _id;
|
17 | for (var i = 0; i < rows.length; i++) {
|
18 | var r = rows[i];
|
19 | _id = r.rowId || r.id;
|
20 | if (!_id) _id = Row.getRandomRowId();
|
21 | if (r.status == Row.STATUS.DELETE) {
|
22 | this.removeRowByRowId(_id);
|
23 | } else {
|
24 | var row = this.getRowByRowId(_id);
|
25 | if (row) {
|
26 | row.updateRow(r);
|
27 | if (!(0, _util.isEmptyObject)(r.data)) {
|
28 | this.trigger(DataTable.ON_UPDATE, {
|
29 | index: i,
|
30 | rows: [row]
|
31 | });
|
32 | if (row == this.getCurrentRow()) {
|
33 | this.currentRowChange(-this.currentRowChange());
|
34 | row.currentRowChange(-row.currentRowChange());
|
35 | this.trigger(DataTable.ON_CURRENT_UPDATE, {
|
36 | index: i,
|
37 | rows: [row]
|
38 | });
|
39 | } else {
|
40 | row.currentRowChange(-row.currentRowChange());
|
41 | }
|
42 | }
|
43 | } else {
|
44 | row = new Row({ parent: this, id: _id });
|
45 | row.setData(rows[i], null, options);
|
46 | insertRows.push(row);
|
47 | }
|
48 |
|
49 | if (r.status) {
|
50 | row.status = r.status;
|
51 | }
|
52 | }
|
53 | }
|
54 | if (insertRows.length > 0) this.addRows(insertRows);
|
55 | return insertRows;
|
56 | };
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | var addRow = function addRow(row) {
|
67 | this.insertRow(this.rows().length, row);
|
68 | };
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | var addRows = function addRows(rows) {
|
74 | this.insertRows(this.rows().length, rows);
|
75 | };
|
76 |
|
77 | var insertRow = function insertRow(index, row) {
|
78 | if (!row) {
|
79 | row = new Row({ parent: this });
|
80 | }
|
81 | this.insertRows(index, [row]);
|
82 | };
|
83 |
|
84 | var insertRows = function insertRows(index, rows) {
|
85 | var args = [index, 0];
|
86 | for (var i = 0; i < rows.length; i++) {
|
87 | args.push(rows[i]);
|
88 | }
|
89 | this.rows.splice.apply(this.rows, args);
|
90 |
|
91 | this.updateSelectedIndices(index, '+', rows.length);
|
92 | this.updateFocusIndex(index, '+', rows.length);
|
93 | this.updatePageAll();
|
94 | this.trigger(DataTable.ON_INSERT, {
|
95 | index: index,
|
96 | rows: rows
|
97 | });
|
98 | if (this.ns) {
|
99 | if (this.root.valueChange[this.ns]) this.root.valueChange[this.ns](-this.root.valueChange[this.ns]());
|
100 | }
|
101 | };
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | var createEmptyRow = function createEmptyRow() {
|
107 | var r = new Row({ parent: this });
|
108 | this.addRow(r);
|
109 | if (!this.getCurrentRow()) this.setRowSelect(r);
|
110 | return r;
|
111 | };
|
112 |
|
113 | exports.setRows = setRows;
|
114 | exports.addRow = addRow;
|
115 | exports.addRows = addRows;
|
116 | exports.insertRow = insertRow;
|
117 | exports.insertRows = insertRows;
|
118 | exports.createEmptyRow = createEmptyRow; |
\ | No newline at end of file |