1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.updateFocusIndex = exports.updateSelectedIndices = exports.removeRowByRowId = undefined;
|
7 |
|
8 | var _util = require('tinper-sparrow/src/util');
|
9 |
|
10 | var removeRowByRowId = function removeRowByRowId(rowid) {
|
11 | for (var i = 0, count = this.rows.length; i < count; i++) {
|
12 | if (this.rows[i].rowId == rowid) {
|
13 | this.rows.splice(i, 1);
|
14 | count--;
|
15 | this.updateSelectedIndices(i, '-');
|
16 | this.updateFocusIndex(i, '-');
|
17 | }
|
18 | }
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var updateSelectedIndices = function updateSelectedIndices(index, type, num) {
|
34 | if (!(0, _util.isNumber)(num)) {
|
35 | num = 1;
|
36 | }
|
37 | var selectedIndices = this.selectedIndices.slice();
|
38 | if (selectedIndices == null || selectedIndices.length == 0) return;
|
39 | for (var i = 0, count = selectedIndices.length; i < count; i++) {
|
40 | if (type == '+') {
|
41 | if (selectedIndices[i] >= index) selectedIndices[i] = parseInt(selectedIndices[i]) + num;
|
42 | } else if (type == '-') {
|
43 | if (selectedIndices[i] >= index && selectedIndices[i] <= index + num - 1) {
|
44 | selectedIndices.splice(i, 1);
|
45 | } else if (selectedIndices[i] > index + num - 1) selectedIndices[i] = selectedIndices[i] - num;
|
46 | }
|
47 | }
|
48 | this.selectedIndices = selectedIndices;
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var updateFocusIndex = function updateFocusIndex(opIndex, opType, num) {
|
58 | if (!(0, _util.isNumber)(num)) {
|
59 | num = 1;
|
60 | }
|
61 | if (opIndex <= this.focus && this.focus != -1) {
|
62 | if (opType === '+') {
|
63 | this.focus = this.focus + num;
|
64 | } else if (opType === '-') {
|
65 | if (this.focus >= opIndex && this.focus <= opIndex + num - 1) {
|
66 | this.focus = this.focus - 1;
|
67 | } else if (this.focus > opIndex + num - 1) {
|
68 | this.focus = this.focus - num;
|
69 | }
|
70 | }
|
71 | }
|
72 | };
|
73 |
|
74 | exports.removeRowByRowId = removeRowByRowId;
|
75 | exports.updateSelectedIndices = updateSelectedIndices;
|
76 | exports.updateFocusIndex = updateFocusIndex; |
\ | No newline at end of file |