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 component_1 = require("../widgets/component");
|
29 | var rowNode_1 = require("../entities/rowNode");
|
30 | var utils_1 = require("../utils");
|
31 | var context_1 = require("../context/context");
|
32 | var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
|
33 | var events_1 = require("../events");
|
34 | var eventService_1 = require("../eventService");
|
35 | var gridApi_1 = require("../gridApi");
|
36 | var columnApi_1 = require("../columnController/columnApi");
|
37 | var CheckboxSelectionComponent = (function (_super) {
|
38 | __extends(CheckboxSelectionComponent, _super);
|
39 | function CheckboxSelectionComponent() {
|
40 | return _super.call(this, "<span class=\"ag-selection-checkbox\"/>") || this;
|
41 | }
|
42 | CheckboxSelectionComponent.prototype.createAndAddIcons = function () {
|
43 | this.eCheckedIcon = utils_1.Utils.createIconNoSpan('checkboxChecked', this.gridOptionsWrapper, this.column);
|
44 | this.eUncheckedIcon = utils_1.Utils.createIconNoSpan('checkboxUnchecked', this.gridOptionsWrapper, this.column);
|
45 | this.eIndeterminateIcon = utils_1.Utils.createIconNoSpan('checkboxIndeterminate', this.gridOptionsWrapper, this.column);
|
46 | var element = this.getGui();
|
47 | element.appendChild(this.eCheckedIcon);
|
48 | element.appendChild(this.eUncheckedIcon);
|
49 | element.appendChild(this.eIndeterminateIcon);
|
50 | };
|
51 | CheckboxSelectionComponent.prototype.onDataChanged = function () {
|
52 |
|
53 |
|
54 | this.onSelectionChanged();
|
55 | };
|
56 | CheckboxSelectionComponent.prototype.onSelectableChanged = function () {
|
57 | this.showOrHideSelect();
|
58 | };
|
59 | CheckboxSelectionComponent.prototype.onSelectionChanged = function () {
|
60 | var state = this.rowNode.isSelected();
|
61 | utils_1.Utils.setVisible(this.eCheckedIcon, state === true);
|
62 | utils_1.Utils.setVisible(this.eUncheckedIcon, state === false);
|
63 | utils_1.Utils.setVisible(this.eIndeterminateIcon, typeof state !== 'boolean');
|
64 | };
|
65 | CheckboxSelectionComponent.prototype.onCheckedClicked = function () {
|
66 | var groupSelectsFiltered = this.gridOptionsWrapper.isGroupSelectsFiltered();
|
67 | var updatedCount = this.rowNode.setSelectedParams({ newValue: false, groupSelectsFiltered: groupSelectsFiltered });
|
68 | return updatedCount;
|
69 | };
|
70 | CheckboxSelectionComponent.prototype.onUncheckedClicked = function (event) {
|
71 | var groupSelectsFiltered = this.gridOptionsWrapper.isGroupSelectsFiltered();
|
72 | var updatedCount = this.rowNode.setSelectedParams({ newValue: true, rangeSelect: event.shiftKey, groupSelectsFiltered: groupSelectsFiltered });
|
73 | return updatedCount;
|
74 | };
|
75 | CheckboxSelectionComponent.prototype.onIndeterminateClicked = function (event) {
|
76 | var result = this.onUncheckedClicked(event);
|
77 | if (result === 0) {
|
78 | this.onCheckedClicked();
|
79 | }
|
80 | };
|
81 | CheckboxSelectionComponent.prototype.init = function (params) {
|
82 | this.rowNode = params.rowNode;
|
83 | this.column = params.column;
|
84 | this.createAndAddIcons();
|
85 | this.onSelectionChanged();
|
86 |
|
87 |
|
88 | this.addGuiEventListener('click', function (event) { return utils_1.Utils.stopPropagationForAgGrid(event); });
|
89 |
|
90 | this.addGuiEventListener('dblclick', function (event) { return utils_1.Utils.stopPropagationForAgGrid(event); });
|
91 | this.addDestroyableEventListener(this.eCheckedIcon, 'click', this.onCheckedClicked.bind(this));
|
92 | this.addDestroyableEventListener(this.eUncheckedIcon, 'click', this.onUncheckedClicked.bind(this));
|
93 | this.addDestroyableEventListener(this.eIndeterminateIcon, 'click', this.onIndeterminateClicked.bind(this));
|
94 | this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_ROW_SELECTED, this.onSelectionChanged.bind(this));
|
95 | this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_DATA_CHANGED, this.onDataChanged.bind(this));
|
96 | this.addDestroyableEventListener(this.rowNode, rowNode_1.RowNode.EVENT_SELECTABLE_CHANGED, this.onSelectableChanged.bind(this));
|
97 | this.isRowSelectableFunc = this.gridOptionsWrapper.getIsRowSelectableFunc();
|
98 | var checkboxVisibleIsDynamic = this.isRowSelectableFunc || this.checkboxCallbackExists();
|
99 | if (checkboxVisibleIsDynamic) {
|
100 | this.addDestroyableEventListener(this.eventService, events_1.Events.EVENT_DISPLAYED_COLUMNS_CHANGED, this.showOrHideSelect.bind(this));
|
101 | this.showOrHideSelect();
|
102 | }
|
103 | };
|
104 | CheckboxSelectionComponent.prototype.showOrHideSelect = function () {
|
105 |
|
106 | var selectable = this.rowNode.selectable;
|
107 |
|
108 |
|
109 |
|
110 | if (selectable && this.checkboxCallbackExists()) {
|
111 | selectable = this.column.isCellCheckboxSelection(this.rowNode);
|
112 | }
|
113 |
|
114 | this.setVisible(selectable);
|
115 | };
|
116 | CheckboxSelectionComponent.prototype.checkboxCallbackExists = function () {
|
117 |
|
118 | var colDef = this.column ? this.column.getColDef() : null;
|
119 | return colDef && typeof colDef.checkboxSelection === 'function';
|
120 | };
|
121 | __decorate([
|
122 | context_1.Autowired('gridOptionsWrapper'),
|
123 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
124 | ], CheckboxSelectionComponent.prototype, "gridOptionsWrapper", void 0);
|
125 | __decorate([
|
126 | context_1.Autowired('eventService'),
|
127 | __metadata("design:type", eventService_1.EventService)
|
128 | ], CheckboxSelectionComponent.prototype, "eventService", void 0);
|
129 | __decorate([
|
130 | context_1.Autowired('gridApi'),
|
131 | __metadata("design:type", gridApi_1.GridApi)
|
132 | ], CheckboxSelectionComponent.prototype, "gridApi", void 0);
|
133 | __decorate([
|
134 | context_1.Autowired('columnApi'),
|
135 | __metadata("design:type", columnApi_1.ColumnApi)
|
136 | ], CheckboxSelectionComponent.prototype, "columnApi", void 0);
|
137 | return CheckboxSelectionComponent;
|
138 | }(component_1.Component));
|
139 | exports.CheckboxSelectionComponent = CheckboxSelectionComponent;
|