blob: 3909c99c06b10b53366ade52e6d47f112a040014 [file] [log] [blame]
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04001/**
2 * @license
3 * Copyright (C) 2016 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Becky Siegel1a44b342016-11-14 08:37:06 -080017(function() {
18 'use strict';
19
20 Polymer({
21 is: 'gr-change-table-editor',
brohlfs3e7f5fd2019-04-11 10:56:21 +020022 _legacyUndefinedCheck: true,
Becky Siegel1a44b342016-11-14 08:37:06 -080023
24 properties: {
Becky Siegel14aa6ab2017-02-23 16:06:18 -080025 displayedColumns: {
26 type: Array,
27 notify: true,
28 },
Wyatt Allen5cb40d12017-09-18 15:47:22 -070029 showNumber: {
30 type: Boolean,
31 notify: true,
32 },
Becky Siegel1a44b342016-11-14 08:37:06 -080033 },
34
35 behaviors: [
36 Gerrit.ChangeTableBehavior,
37 ],
38
Wyatt Allen605bc572018-08-01 15:08:30 -070039 /**
40 * Get the list of enabled column names from whichever checkboxes are
41 * checked (excluding the number checkbox).
42 * @return {!Array<string>}
43 */
44 _getDisplayedColumns() {
brohlfsb20eee42019-04-11 17:00:43 +020045 // Polymer2: querySelectorAll returns NodeList instead of Array.
46 return Array.from(Polymer.dom(this.root)
47 .querySelectorAll('.checkboxContainer input:not([name=number])'))
Wyatt Allen605bc572018-08-01 15:08:30 -070048 .filter(checkbox => checkbox.checked)
49 .map(checkbox => checkbox.name);
Becky Siegel14aa6ab2017-02-23 16:06:18 -080050 },
Becky Siegel1a44b342016-11-14 08:37:06 -080051
Becky Siegel14aa6ab2017-02-23 16:06:18 -080052 /**
Wyatt Allen605bc572018-08-01 15:08:30 -070053 * Handle a tap on a checkbox container and relay the tap to the checkbox it
54 * contains.
55 */
56 _handleCheckboxContainerTap(e) {
57 const checkbox = Polymer.dom(e.target).querySelector('input');
58 if (!checkbox) { return; }
59 checkbox.click();
60 },
61
62 /**
63 * Handle a tap on the number checkbox and update the showNumber property
64 * accordingly.
65 */
66 _handleNumberCheckboxTap(e) {
67 this.showNumber = Polymer.dom(e).rootTarget.checked;
68 },
69
70 /**
71 * Handle a tap on a displayed column checkboxes (excluding number) and
72 * update the displayedColumns property accordingly.
Becky Siegel14aa6ab2017-02-23 16:06:18 -080073 */
Kasper Nilsson6ce61822017-05-15 17:14:30 -070074 _handleTargetTap(e) {
Wyatt Allen605bc572018-08-01 15:08:30 -070075 this.set('displayedColumns', this._getDisplayedColumns());
Becky Siegel1a44b342016-11-14 08:37:06 -080076 },
77 });
78})();