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 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
19 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
20 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
21 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
22 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
23 | };
|
24 | var __metadata = (this && this.__metadata) || function (k, v) {
|
25 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | var agCheckbox_1 = require("../../widgets/agCheckbox");
|
29 | var beanStub_1 = require("../../context/beanStub");
|
30 | var context_1 = require("../../context/context");
|
31 | var columnApi_1 = require("../../columnController/columnApi");
|
32 | var gridApi_1 = require("../../gridApi");
|
33 | var events_1 = require("../../events");
|
34 | var eventService_1 = require("../../eventService");
|
35 | var constants_1 = require("../../constants");
|
36 | var selectionController_1 = require("../../selectionController");
|
37 | var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
|
38 | var SelectAllFeature = (function (_super) {
|
39 | __extends(SelectAllFeature, _super);
|
40 | function SelectAllFeature(cbSelectAll, column) {
|
41 | var _this = _super.call(this) || this;
|
42 | _this.cbSelectAllVisible = false;
|
43 | _this.processingEventFromCheckbox = false;
|
44 | _this.cbSelectAll = cbSelectAll;
|
45 | _this.column = column;
|
46 | var colDef = column.getColDef();
|
47 | _this.filteredOnly = colDef ? !!colDef.headerCheckboxSelectionFilteredOnly : false;
|
48 | return _this;
|
49 | }
|
50 | SelectAllFeature.prototype.postConstruct = function () {
|
51 | this.showOrHideSelectAll();
|
52 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED, this.showOrHideSelectAll.bind(this));
|
53 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_SELECTION_CHANGED, this.onSelectionChanged.bind(this));
|
54 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_MODEL_UPDATED, this.onModelChanged.bind(this));
|
55 | this.addDestroyableEventListener(this.cbSelectAll, agCheckbox_1.AgCheckbox.EVENT_CHANGED, this.onCbSelectAll.bind(this));
|
56 | };
|
57 | SelectAllFeature.prototype.showOrHideSelectAll = function () {
|
58 | this.cbSelectAllVisible = this.isCheckboxSelection();
|
59 | this.cbSelectAll.setVisible(this.cbSelectAllVisible);
|
60 | if (this.cbSelectAllVisible) {
|
61 |
|
62 | this.checkRightRowModelType();
|
63 |
|
64 | this.updateStateOfCheckbox();
|
65 | }
|
66 | };
|
67 | SelectAllFeature.prototype.onModelChanged = function () {
|
68 | if (!this.cbSelectAllVisible) {
|
69 | return;
|
70 | }
|
71 | this.updateStateOfCheckbox();
|
72 | };
|
73 | SelectAllFeature.prototype.onSelectionChanged = function () {
|
74 | if (!this.cbSelectAllVisible) {
|
75 | return;
|
76 | }
|
77 | this.updateStateOfCheckbox();
|
78 | };
|
79 | SelectAllFeature.prototype.getNextCheckboxState = function (selectionCount) {
|
80 | if (selectionCount.selected === 0 && selectionCount.notSelected === 0) {
|
81 |
|
82 | return false;
|
83 | }
|
84 | else if (selectionCount.selected > 0 && selectionCount.notSelected > 0) {
|
85 |
|
86 | return null;
|
87 | }
|
88 | else if (selectionCount.selected > 0) {
|
89 |
|
90 | return true;
|
91 | }
|
92 | else {
|
93 |
|
94 | return false;
|
95 | }
|
96 | };
|
97 | SelectAllFeature.prototype.updateStateOfCheckbox = function () {
|
98 | if (this.processingEventFromCheckbox) {
|
99 | return;
|
100 | }
|
101 | this.processingEventFromCheckbox = true;
|
102 | var selectionCount = this.getSelectionCount();
|
103 | var allSelected = this.getNextCheckboxState(selectionCount);
|
104 | this.cbSelectAll.setSelected(allSelected);
|
105 | this.processingEventFromCheckbox = false;
|
106 | };
|
107 | SelectAllFeature.prototype.getSelectionCount = function () {
|
108 | var selectedCount = 0;
|
109 | var notSelectedCount = 0;
|
110 | var callback = function (node) {
|
111 | if (node.isSelected()) {
|
112 | selectedCount++;
|
113 | }
|
114 | else if (!node.selectable) {
|
115 |
|
116 | }
|
117 | else {
|
118 | notSelectedCount++;
|
119 | }
|
120 | };
|
121 | if (this.filteredOnly) {
|
122 | this.gridApi.forEachNodeAfterFilter(callback);
|
123 | }
|
124 | else {
|
125 | this.gridApi.forEachNode(callback);
|
126 | }
|
127 | return {
|
128 | notSelected: notSelectedCount,
|
129 | selected: selectedCount
|
130 | };
|
131 | };
|
132 | SelectAllFeature.prototype.checkRightRowModelType = function () {
|
133 | var rowModelType = this.rowModel.getType();
|
134 | var rowModelMatches = rowModelType === constants_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE;
|
135 | if (!rowModelMatches) {
|
136 | console.log("ag-Grid: selectAllCheckbox is only available if using normal row model, you are using " + rowModelType);
|
137 | }
|
138 | };
|
139 | SelectAllFeature.prototype.onCbSelectAll = function () {
|
140 | if (this.processingEventFromCheckbox) {
|
141 | return;
|
142 | }
|
143 | if (!this.cbSelectAllVisible) {
|
144 | return;
|
145 | }
|
146 | var value = this.cbSelectAll.isSelected();
|
147 | if (value) {
|
148 | this.selectionController.selectAllRowNodes(this.filteredOnly);
|
149 | }
|
150 | else {
|
151 | this.selectionController.deselectAllRowNodes(this.filteredOnly);
|
152 | }
|
153 | };
|
154 | SelectAllFeature.prototype.isCheckboxSelection = function () {
|
155 | var result = this.column.getColDef().headerCheckboxSelection;
|
156 | if (typeof result === 'function') {
|
157 | var func = result;
|
158 | result = func({
|
159 | column: this.column,
|
160 | colDef: this.column.getColDef(),
|
161 | columnApi: this.columnApi,
|
162 | api: this.gridApi
|
163 | });
|
164 | }
|
165 | if (result) {
|
166 | if (this.gridOptionsWrapper.isRowModelServerSide()) {
|
167 | console.warn('headerCheckboxSelection is not supported for Server Side Row Model');
|
168 | return false;
|
169 | }
|
170 | if (this.gridOptionsWrapper.isRowModelInfinite()) {
|
171 | console.warn('headerCheckboxSelection is not supported for Infinite Row Model');
|
172 | return false;
|
173 | }
|
174 | if (this.gridOptionsWrapper.isRowModelViewport()) {
|
175 | console.warn('headerCheckboxSelection is not supported for Viewport Row Model');
|
176 | return false;
|
177 | }
|
178 |
|
179 | return true;
|
180 | }
|
181 | else {
|
182 | return false;
|
183 | }
|
184 | };
|
185 | __decorate([
|
186 | context_1.Autowired('gridApi'),
|
187 | __metadata("design:type", gridApi_1.GridApi)
|
188 | ], SelectAllFeature.prototype, "gridApi", void 0);
|
189 | __decorate([
|
190 | context_1.Autowired('columnApi'),
|
191 | __metadata("design:type", columnApi_1.ColumnApi)
|
192 | ], SelectAllFeature.prototype, "columnApi", void 0);
|
193 | __decorate([
|
194 | context_1.Autowired('eventService'),
|
195 | __metadata("design:type", eventService_1.EventService)
|
196 | ], SelectAllFeature.prototype, "eventService", void 0);
|
197 | __decorate([
|
198 | context_1.Autowired('rowModel'),
|
199 | __metadata("design:type", Object)
|
200 | ], SelectAllFeature.prototype, "rowModel", void 0);
|
201 | __decorate([
|
202 | context_1.Autowired('selectionController'),
|
203 | __metadata("design:type", selectionController_1.SelectionController)
|
204 | ], SelectAllFeature.prototype, "selectionController", void 0);
|
205 | __decorate([
|
206 | context_1.Autowired('gridOptionsWrapper'),
|
207 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
208 | ], SelectAllFeature.prototype, "gridOptionsWrapper", void 0);
|
209 | __decorate([
|
210 | context_1.PostConstruct,
|
211 | __metadata("design:type", Function),
|
212 | __metadata("design:paramtypes", []),
|
213 | __metadata("design:returntype", void 0)
|
214 | ], SelectAllFeature.prototype, "postConstruct", null);
|
215 | return SelectAllFeature;
|
216 | }(beanStub_1.BeanStub));
|
217 | exports.SelectAllFeature = SelectAllFeature;
|