1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.updateSelectedIndices = exports.toggleAllSelect = exports.setRowsUnSelect = exports.setRowUnSelect = exports.setAllRowsUnSelect = exports.addRowsSelect = exports.addRowSelect = exports.setRowsSelect = exports.setRowSelect = exports.setAllRowsSelect = undefined;
|
7 |
|
8 | var _util = require('tinper-sparrow/src/util');
|
9 |
|
10 | var _util2 = require('./util');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var setAllRowsSelect = function setAllRowsSelect() {
|
18 | var indices = new Array(this.rows().length);
|
19 | for (var i = 0; i < indices.length; i++) {
|
20 | indices[i] = i;
|
21 | }
|
22 | this.setRowsSelect(indices);
|
23 | this.allSelected(true);
|
24 | this.trigger(DataTable.ON_ROW_ALLSELECT, {});
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | var setRowSelect = function setRowSelect(index) {
|
31 | if (index instanceof Row) {
|
32 | index = this.getIndexByRowId(index.rowId);
|
33 | }
|
34 | this.setRowsSelect([index]);
|
35 | this.setRowFocus(this.getSelectedIndex());
|
36 | };
|
37 |
|
38 | var setRowsSelect = function setRowsSelect(indices) {
|
39 | indices = indices || -1;
|
40 | if (indices == -1) {
|
41 | this.setAllRowsUnSelect({ quiet: true });
|
42 | return;
|
43 | }
|
44 | indices = (0, _util2._formatToIndicesArray)(this, indices);
|
45 | var sIns = this.selectedIndices();
|
46 | if ((0, _util.isArray)(indices) && (0, _util.isArray)(sIns) && indices.join() == sIns.join()) {
|
47 |
|
48 | return;
|
49 | }
|
50 |
|
51 | if (u.isArray(indices)) {
|
52 | var rowNum = this.rows().length;
|
53 | for (var i = 0; i < indices.length; i++) {
|
54 | if (indices[i] < 0 || indices[i] >= rowNum) indices.splice(i, 1);
|
55 | }
|
56 | }
|
57 |
|
58 | this.setAllRowsUnSelect({ quiet: true });
|
59 | try {
|
60 | this.selectedIndices(indices);
|
61 | } catch (e) {}
|
62 | this.updatePageSelect();
|
63 | var rowIds = this.getRowIdsByIndices(indices);
|
64 | this.currentRowChange(-this.currentRowChange());
|
65 | this.trigger(DataTable.ON_ROW_SELECT, {
|
66 | indices: indices,
|
67 | rowIds: rowIds
|
68 | });
|
69 | this.updateCurrIndex();
|
70 | };
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | var addRowSelect = function addRowSelect(index) {
|
76 | if (index instanceof Row) {
|
77 | index = this.getIndexByRowId(index.rowId);
|
78 | }
|
79 | this.addRowsSelect([index]);
|
80 | };
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | var addRowsSelect = function addRowsSelect(indices) {
|
86 | indices = (0, _util2._formatToIndicesArray)(this, indices);
|
87 | var selectedIndices = this.selectedIndices().slice();
|
88 | var needTrigger = false;
|
89 | for (var i = 0; i < indices.length; i++) {
|
90 | var ind = indices[i],
|
91 | toAdd = true;
|
92 | for (var j = 0; j < selectedIndices.length; j++) {
|
93 | if (selectedIndices[j] == ind) {
|
94 | toAdd = false;
|
95 | }
|
96 | }
|
97 |
|
98 | if (toAdd && indices[i] > -1) {
|
99 | needTrigger = true;
|
100 | selectedIndices.push(indices[i]);
|
101 | }
|
102 | }
|
103 | this.selectedIndices(selectedIndices);
|
104 | this.updatePageSelect();
|
105 | var rowIds = this.getRowIdsByIndices(selectedIndices);
|
106 | if (needTrigger) {
|
107 | this.trigger(DataTable.ON_ROW_SELECT, {
|
108 | indices: selectedIndices,
|
109 | rowIds: rowIds
|
110 | });
|
111 | }
|
112 | this.updateCurrIndex();
|
113 | };
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | var setAllRowsUnSelect = function setAllRowsUnSelect(options) {
|
119 | this.selectedIndices([]);
|
120 | this.updatePageSelect();
|
121 | if (!(options && options.quiet)) {
|
122 | this.trigger(DataTable.ON_ROW_ALLUNSELECT);
|
123 | }
|
124 | this.updateCurrIndex();
|
125 | this.allSelected(false);
|
126 | };
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | var setRowUnSelect = function setRowUnSelect(index) {
|
132 | if (index instanceof Row) {
|
133 | index = this.getIndexByRowId(index.rowId);
|
134 | }
|
135 | this.setRowsUnSelect([index]);
|
136 | };
|
137 |
|
138 | var setRowsUnSelect = function setRowsUnSelect(indices) {
|
139 | indices = (0, _util2._formatToIndicesArray)(this, indices);
|
140 | var selectedIndices = this.selectedIndices().slice();
|
141 |
|
142 |
|
143 | if (selectedIndices.indexOf(indices[0]) == -1) return;
|
144 |
|
145 | for (var i = 0; i < indices.length; i++) {
|
146 | var index = indices[i];
|
147 | var pos = selectedIndices.indexOf(index);
|
148 | if (pos != -1) selectedIndices.splice(pos, 1);
|
149 | }
|
150 | this.selectedIndices(selectedIndices);
|
151 | this.updatePageSelect();
|
152 | var rowIds = this.getRowIdsByIndices(indices);
|
153 | this.trigger(DataTable.ON_ROW_UNSELECT, {
|
154 | indices: indices,
|
155 | rowIds: rowIds
|
156 | });
|
157 | this.updateCurrIndex();
|
158 | this.allSelected(false);
|
159 | };
|
160 |
|
161 | var toggleAllSelect = function toggleAllSelect() {
|
162 | if (this.allSelected()) {
|
163 | this.setAllRowsUnSelect();
|
164 | } else {
|
165 | this.setAllRowsSelect();
|
166 | }
|
167 | };
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | var updateSelectedIndices = function updateSelectedIndices(index, type, num) {
|
175 | if (!(0, _util.isNumber)(num)) {
|
176 | num = 1;
|
177 | }
|
178 | var selectedIndices = this.selectedIndices().slice();
|
179 | if (selectedIndices == null || selectedIndices.length == 0) return;
|
180 | for (var i = 0, count = selectedIndices.length; i < count; i++) {
|
181 | if (type == '+') {
|
182 | if (selectedIndices[i] >= index) selectedIndices[i] = parseInt(selectedIndices[i]) + num;
|
183 | } else if (type == '-') {
|
184 | if (selectedIndices[i] >= index && selectedIndices[i] <= index + num - 1) {
|
185 | selectedIndices.splice(i, 1);
|
186 | } else if (selectedIndices[i] > index + num - 1) selectedIndices[i] = selectedIndices[i] - num;
|
187 | }
|
188 | }
|
189 | this.selectedIndices(selectedIndices);
|
190 | this.updatePageSelect();
|
191 | };
|
192 | exports.setAllRowsSelect = setAllRowsSelect;
|
193 | exports.setRowSelect = setRowSelect;
|
194 | exports.setRowsSelect = setRowsSelect;
|
195 | exports.addRowSelect = addRowSelect;
|
196 | exports.addRowsSelect = addRowsSelect;
|
197 | exports.setAllRowsUnSelect = setAllRowsUnSelect;
|
198 | exports.setRowUnSelect = setRowUnSelect;
|
199 | exports.setRowsUnSelect = setRowsUnSelect;
|
200 | exports.toggleAllSelect = toggleAllSelect;
|
201 | exports.updateSelectedIndices = updateSelectedIndices; |
\ | No newline at end of file |