1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __extends = (this && this.__extends) || (function () {
|
9 | var extendStatics = Object.setPrototypeOf ||
|
10 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
11 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
12 | return function (d, b) {
|
13 | extendStatics(d, b);
|
14 | function __() { this.constructor = d; }
|
15 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
16 | };
|
17 | })();
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | var utils_1 = require("../../utils");
|
20 | var rowNode_1 = require("../../entities/rowNode");
|
21 | var beanStub_1 = require("../../context/beanStub");
|
22 | var RowNodeBlock = (function (_super) {
|
23 | __extends(RowNodeBlock, _super);
|
24 | function RowNodeBlock(blockNumber, rowNodeCacheParams) {
|
25 | var _this = _super.call(this) || this;
|
26 | _this.version = 0;
|
27 | _this.state = RowNodeBlock.STATE_DIRTY;
|
28 | _this.rowNodeCacheParams = rowNodeCacheParams;
|
29 | _this.blockNumber = blockNumber;
|
30 |
|
31 |
|
32 | _this.startRow = blockNumber * rowNodeCacheParams.blockSize;
|
33 | _this.endRow = _this.startRow + rowNodeCacheParams.blockSize;
|
34 | return _this;
|
35 | }
|
36 | RowNodeBlock.prototype.isAnyNodeOpen = function (rowCount) {
|
37 | var result = false;
|
38 | this.forEachNodeCallback(function (rowNode) {
|
39 | if (rowNode.expanded) {
|
40 | result = true;
|
41 | }
|
42 | }, rowCount);
|
43 | return result;
|
44 | };
|
45 | RowNodeBlock.prototype.forEachNodeCallback = function (callback, rowCount) {
|
46 | for (var rowIndex = this.startRow; rowIndex < this.endRow; rowIndex++) {
|
47 |
|
48 |
|
49 | if (rowIndex < rowCount) {
|
50 | var rowNode = this.getRowUsingLocalIndex(rowIndex);
|
51 | callback(rowNode, rowIndex);
|
52 | }
|
53 | }
|
54 | };
|
55 | RowNodeBlock.prototype.forEachNode = function (callback, sequence, rowCount, deep) {
|
56 | this.forEachNodeCallback(function (rowNode) {
|
57 | callback(rowNode, sequence.next());
|
58 |
|
59 |
|
60 | if (deep && rowNode.childrenCache) {
|
61 | rowNode.childrenCache.forEachNodeDeep(callback, sequence);
|
62 | }
|
63 | }, rowCount);
|
64 | };
|
65 | RowNodeBlock.prototype.forEachNodeDeep = function (callback, sequence, rowCount) {
|
66 | this.forEachNode(callback, sequence, rowCount, true);
|
67 | };
|
68 | RowNodeBlock.prototype.forEachNodeShallow = function (callback, sequence, rowCount) {
|
69 | this.forEachNode(callback, sequence, rowCount, false);
|
70 | };
|
71 | RowNodeBlock.prototype.getVersion = function () {
|
72 | return this.version;
|
73 | };
|
74 | RowNodeBlock.prototype.getLastAccessed = function () {
|
75 | return this.lastAccessed;
|
76 | };
|
77 | RowNodeBlock.prototype.getRowUsingLocalIndex = function (rowIndex, dontTouchLastAccessed) {
|
78 | if (dontTouchLastAccessed === void 0) { dontTouchLastAccessed = false; }
|
79 | if (!dontTouchLastAccessed) {
|
80 | this.lastAccessed = this.rowNodeCacheParams.lastAccessedSequence.next();
|
81 | }
|
82 | var localIndex = rowIndex - this.startRow;
|
83 | return this.rowNodes[localIndex];
|
84 | };
|
85 | RowNodeBlock.prototype.init = function (beans) {
|
86 | this.beans = beans;
|
87 | this.createRowNodes();
|
88 | };
|
89 | RowNodeBlock.prototype.getStartRow = function () {
|
90 | return this.startRow;
|
91 | };
|
92 | RowNodeBlock.prototype.getEndRow = function () {
|
93 | return this.endRow;
|
94 | };
|
95 | RowNodeBlock.prototype.getBlockNumber = function () {
|
96 | return this.blockNumber;
|
97 | };
|
98 | RowNodeBlock.prototype.setDirty = function () {
|
99 |
|
100 | this.version++;
|
101 | this.state = RowNodeBlock.STATE_DIRTY;
|
102 | };
|
103 | RowNodeBlock.prototype.setDirtyAndPurge = function () {
|
104 | this.setDirty();
|
105 | this.rowNodes.forEach(function (rowNode) {
|
106 | rowNode.setData(null);
|
107 | });
|
108 | };
|
109 | RowNodeBlock.prototype.getState = function () {
|
110 | return this.state;
|
111 | };
|
112 | RowNodeBlock.prototype.setRowNode = function (rowIndex, rowNode) {
|
113 | var localIndex = rowIndex - this.startRow;
|
114 | this.rowNodes[localIndex] = rowNode;
|
115 | };
|
116 | RowNodeBlock.prototype.setBlankRowNode = function (rowIndex) {
|
117 | var localIndex = rowIndex - this.startRow;
|
118 | var newRowNode = this.createBlankRowNode(rowIndex);
|
119 | this.rowNodes[localIndex] = newRowNode;
|
120 | return newRowNode;
|
121 | };
|
122 | RowNodeBlock.prototype.setNewData = function (rowIndex, dataItem) {
|
123 | var newRowNode = this.setBlankRowNode(rowIndex);
|
124 | this.setDataAndId(newRowNode, dataItem, this.startRow + rowIndex);
|
125 | return newRowNode;
|
126 | };
|
127 | RowNodeBlock.prototype.createBlankRowNode = function (rowIndex) {
|
128 | var rowNode = new rowNode_1.RowNode();
|
129 | this.beans.context.wireBean(rowNode);
|
130 | rowNode.setRowHeight(this.rowNodeCacheParams.rowHeight);
|
131 | return rowNode;
|
132 | };
|
133 |
|
134 | RowNodeBlock.prototype.createRowNodes = function () {
|
135 | this.rowNodes = [];
|
136 | for (var i = 0; i < this.rowNodeCacheParams.blockSize; i++) {
|
137 | var rowIndex = this.startRow + i;
|
138 | var rowNode = this.createBlankRowNode(rowIndex);
|
139 | this.rowNodes.push(rowNode);
|
140 | }
|
141 | };
|
142 | RowNodeBlock.prototype.load = function () {
|
143 | this.state = RowNodeBlock.STATE_LOADING;
|
144 | this.loadFromDatasource();
|
145 | };
|
146 | RowNodeBlock.prototype.pageLoadFailed = function () {
|
147 | this.state = RowNodeBlock.STATE_FAILED;
|
148 | var event = {
|
149 | type: RowNodeBlock.EVENT_LOAD_COMPLETE,
|
150 | success: false,
|
151 | page: this,
|
152 | lastRow: null
|
153 | };
|
154 | this.dispatchEvent(event);
|
155 | };
|
156 | RowNodeBlock.prototype.populateWithRowData = function (rows) {
|
157 | var _this = this;
|
158 | var rowNodesToRefresh = [];
|
159 | this.rowNodes.forEach(function (rowNode, index) {
|
160 | var data = rows[index];
|
161 | if (rowNode.stub) {
|
162 | rowNodesToRefresh.push(rowNode);
|
163 | }
|
164 | _this.setDataAndId(rowNode, data, _this.startRow + index);
|
165 | });
|
166 | if (rowNodesToRefresh.length > 0) {
|
167 | this.beans.rowRenderer.redrawRows(rowNodesToRefresh);
|
168 | }
|
169 | };
|
170 | RowNodeBlock.prototype.destroy = function () {
|
171 | _super.prototype.destroy.call(this);
|
172 | this.rowNodes.forEach(function (rowNode) {
|
173 | if (rowNode.childrenCache) {
|
174 | rowNode.childrenCache.destroy();
|
175 | rowNode.childrenCache = null;
|
176 | }
|
177 |
|
178 |
|
179 |
|
180 | rowNode.clearRowTop();
|
181 | });
|
182 | };
|
183 | RowNodeBlock.prototype.pageLoaded = function (version, rows, lastRow) {
|
184 |
|
185 |
|
186 |
|
187 | if (version === this.version) {
|
188 | this.state = RowNodeBlock.STATE_LOADED;
|
189 | this.populateWithRowData(rows);
|
190 | }
|
191 | lastRow = utils_1.Utils.cleanNumber(lastRow);
|
192 |
|
193 | var event = {
|
194 | type: RowNodeBlock.EVENT_LOAD_COMPLETE,
|
195 | success: true,
|
196 | page: this,
|
197 | lastRow: lastRow
|
198 | };
|
199 | this.dispatchEvent(event);
|
200 | };
|
201 | RowNodeBlock.EVENT_LOAD_COMPLETE = 'loadComplete';
|
202 | RowNodeBlock.STATE_DIRTY = 'dirty';
|
203 | RowNodeBlock.STATE_LOADING = 'loading';
|
204 | RowNodeBlock.STATE_LOADED = 'loaded';
|
205 | RowNodeBlock.STATE_FAILED = 'failed';
|
206 | return RowNodeBlock;
|
207 | }(beanStub_1.BeanStub));
|
208 | exports.RowNodeBlock = RowNodeBlock;
|