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("./component");
|
29 | var componentAnnotations_1 = require("./componentAnnotations");
|
30 | var utils_1 = require("../utils");
|
31 | var context_1 = require("../context/context");
|
32 | var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
|
33 | var AgCheckbox = (function (_super) {
|
34 | __extends(AgCheckbox, _super);
|
35 | function AgCheckbox() {
|
36 | var _this = _super.call(this) || this;
|
37 | _this.selected = false;
|
38 | _this.readOnly = false;
|
39 | _this.passive = false;
|
40 | return _this;
|
41 | }
|
42 | AgCheckbox.prototype.preConstruct = function () {
|
43 | this.setTemplate(AgCheckbox.TEMPLATE);
|
44 | };
|
45 | AgCheckbox.prototype.postConstruct = function () {
|
46 | this.loadIcons();
|
47 | this.updateIcons();
|
48 | if (this.props.label) {
|
49 | this.eLabel.innerText = this.props.label;
|
50 | }
|
51 | };
|
52 | AgCheckbox.prototype.loadIcons = function () {
|
53 | utils_1.Utils.removeAllChildren(this.eChecked);
|
54 | utils_1.Utils.removeAllChildren(this.eUnchecked);
|
55 | utils_1.Utils.removeAllChildren(this.eIndeterminate);
|
56 | if (this.readOnly) {
|
57 | this.eChecked.appendChild(utils_1.Utils.createIconNoSpan('checkboxCheckedReadOnly', this.gridOptionsWrapper, null));
|
58 | this.eUnchecked.appendChild(utils_1.Utils.createIconNoSpan('checkboxUncheckedReadOnly', this.gridOptionsWrapper, null));
|
59 | this.eIndeterminate.appendChild(utils_1.Utils.createIconNoSpan('checkboxIndeterminateReadOnly', this.gridOptionsWrapper, null));
|
60 | }
|
61 | else {
|
62 | this.eChecked.appendChild(utils_1.Utils.createIconNoSpan('checkboxChecked', this.gridOptionsWrapper, null));
|
63 | this.eUnchecked.appendChild(utils_1.Utils.createIconNoSpan('checkboxUnchecked', this.gridOptionsWrapper, null));
|
64 | this.eIndeterminate.appendChild(utils_1.Utils.createIconNoSpan('checkboxIndeterminate', this.gridOptionsWrapper, null));
|
65 | }
|
66 | };
|
67 | AgCheckbox.prototype.onClick = function (event) {
|
68 |
|
69 |
|
70 |
|
71 | utils_1.Utils.addAgGridEventPath(event);
|
72 | if (!this.readOnly) {
|
73 | this.toggle();
|
74 | }
|
75 | };
|
76 | AgCheckbox.prototype.getNextValue = function () {
|
77 | if (this.selected === undefined) {
|
78 | return true;
|
79 | }
|
80 | else {
|
81 | return !this.selected;
|
82 | }
|
83 | };
|
84 | AgCheckbox.prototype.setPassive = function (passive) {
|
85 | this.passive = passive;
|
86 | };
|
87 | AgCheckbox.prototype.setReadOnly = function (readOnly) {
|
88 | this.readOnly = readOnly;
|
89 | this.loadIcons();
|
90 | };
|
91 | AgCheckbox.prototype.isReadOnly = function () {
|
92 | return this.readOnly;
|
93 | };
|
94 | AgCheckbox.prototype.isSelected = function () {
|
95 | return this.selected;
|
96 | };
|
97 | AgCheckbox.prototype.toggle = function () {
|
98 | var nextValue = this.getNextValue();
|
99 | if (this.passive) {
|
100 | var event_1 = {
|
101 | type: AgCheckbox.EVENT_CHANGED,
|
102 | selected: nextValue
|
103 | };
|
104 | this.dispatchEvent(event_1);
|
105 | }
|
106 | else {
|
107 | this.setSelected(nextValue);
|
108 | }
|
109 | };
|
110 | AgCheckbox.prototype.setSelected = function (selected) {
|
111 | if (this.selected === selected) {
|
112 | return;
|
113 | }
|
114 | if (selected === true) {
|
115 | this.selected = true;
|
116 | }
|
117 | else if (selected === false) {
|
118 | this.selected = false;
|
119 | }
|
120 | else {
|
121 | this.selected = undefined;
|
122 | }
|
123 | this.updateIcons();
|
124 | var event = {
|
125 | type: AgCheckbox.EVENT_CHANGED,
|
126 | selected: this.selected
|
127 | };
|
128 | this.dispatchEvent(event);
|
129 | };
|
130 | AgCheckbox.prototype.updateIcons = function () {
|
131 | utils_1.Utils.setVisible(this.eChecked, this.selected === true);
|
132 | utils_1.Utils.setVisible(this.eUnchecked, this.selected === false);
|
133 | utils_1.Utils.setVisible(this.eIndeterminate, this.selected === undefined);
|
134 | };
|
135 | AgCheckbox.EVENT_CHANGED = 'change';
|
136 | AgCheckbox.TEMPLATE = '<span class="ag-checkbox" role="presentation">' +
|
137 | ' <span class="ag-checkbox-checked" role="presentation"></span>' +
|
138 | ' <span class="ag-checkbox-unchecked" role="presentation"></span>' +
|
139 | ' <span class="ag-checkbox-indeterminate" role="presentation"></span>' +
|
140 | ' <span class="ag-checkbox-label" role="presentation"></span>' +
|
141 | '</span>';
|
142 | __decorate([
|
143 | context_1.Autowired('gridOptionsWrapper'),
|
144 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
145 | ], AgCheckbox.prototype, "gridOptionsWrapper", void 0);
|
146 | __decorate([
|
147 | componentAnnotations_1.QuerySelector('.ag-checkbox-checked'),
|
148 | __metadata("design:type", HTMLElement)
|
149 | ], AgCheckbox.prototype, "eChecked", void 0);
|
150 | __decorate([
|
151 | componentAnnotations_1.QuerySelector('.ag-checkbox-unchecked'),
|
152 | __metadata("design:type", HTMLElement)
|
153 | ], AgCheckbox.prototype, "eUnchecked", void 0);
|
154 | __decorate([
|
155 | componentAnnotations_1.QuerySelector('.ag-checkbox-indeterminate'),
|
156 | __metadata("design:type", HTMLElement)
|
157 | ], AgCheckbox.prototype, "eIndeterminate", void 0);
|
158 | __decorate([
|
159 | componentAnnotations_1.QuerySelector('.ag-checkbox-label'),
|
160 | __metadata("design:type", HTMLElement)
|
161 | ], AgCheckbox.prototype, "eLabel", void 0);
|
162 | __decorate([
|
163 | context_1.PreConstruct,
|
164 | __metadata("design:type", Function),
|
165 | __metadata("design:paramtypes", []),
|
166 | __metadata("design:returntype", void 0)
|
167 | ], AgCheckbox.prototype, "preConstruct", null);
|
168 | __decorate([
|
169 | context_1.PostConstruct,
|
170 | __metadata("design:type", Function),
|
171 | __metadata("design:paramtypes", []),
|
172 | __metadata("design:returntype", void 0)
|
173 | ], AgCheckbox.prototype, "postConstruct", null);
|
174 | __decorate([
|
175 | componentAnnotations_1.Listener('click'),
|
176 | __metadata("design:type", Function),
|
177 | __metadata("design:paramtypes", [MouseEvent]),
|
178 | __metadata("design:returntype", void 0)
|
179 | ], AgCheckbox.prototype, "onClick", null);
|
180 | return AgCheckbox;
|
181 | }(component_1.Component));
|
182 | exports.AgCheckbox = AgCheckbox;
|