Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 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 Siegel | 1a44b34 | 2016-11-14 08:37:06 -0800 | [diff] [blame] | 17 | (function() { |
| 18 | 'use strict'; |
| 19 | |
| 20 | Polymer({ |
| 21 | is: 'gr-change-table-editor', |
brohlfs | 3e7f5fd | 2019-04-11 10:56:21 +0200 | [diff] [blame] | 22 | _legacyUndefinedCheck: true, |
Becky Siegel | 1a44b34 | 2016-11-14 08:37:06 -0800 | [diff] [blame] | 23 | |
| 24 | properties: { |
Becky Siegel | 14aa6ab | 2017-02-23 16:06:18 -0800 | [diff] [blame] | 25 | displayedColumns: { |
| 26 | type: Array, |
| 27 | notify: true, |
| 28 | }, |
Wyatt Allen | 5cb40d1 | 2017-09-18 15:47:22 -0700 | [diff] [blame] | 29 | showNumber: { |
| 30 | type: Boolean, |
| 31 | notify: true, |
| 32 | }, |
Becky Siegel | 1a44b34 | 2016-11-14 08:37:06 -0800 | [diff] [blame] | 33 | }, |
| 34 | |
| 35 | behaviors: [ |
| 36 | Gerrit.ChangeTableBehavior, |
| 37 | ], |
| 38 | |
Wyatt Allen | 605bc57 | 2018-08-01 15:08:30 -0700 | [diff] [blame] | 39 | /** |
| 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() { |
brohlfs | b20eee4 | 2019-04-11 17:00:43 +0200 | [diff] [blame] | 45 | // Polymer2: querySelectorAll returns NodeList instead of Array. |
| 46 | return Array.from(Polymer.dom(this.root) |
| 47 | .querySelectorAll('.checkboxContainer input:not([name=number])')) |
Wyatt Allen | 605bc57 | 2018-08-01 15:08:30 -0700 | [diff] [blame] | 48 | .filter(checkbox => checkbox.checked) |
| 49 | .map(checkbox => checkbox.name); |
Becky Siegel | 14aa6ab | 2017-02-23 16:06:18 -0800 | [diff] [blame] | 50 | }, |
Becky Siegel | 1a44b34 | 2016-11-14 08:37:06 -0800 | [diff] [blame] | 51 | |
Becky Siegel | 14aa6ab | 2017-02-23 16:06:18 -0800 | [diff] [blame] | 52 | /** |
Wyatt Allen | 605bc57 | 2018-08-01 15:08:30 -0700 | [diff] [blame] | 53 | * 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 Siegel | 14aa6ab | 2017-02-23 16:06:18 -0800 | [diff] [blame] | 73 | */ |
Kasper Nilsson | 6ce6182 | 2017-05-15 17:14:30 -0700 | [diff] [blame] | 74 | _handleTargetTap(e) { |
Wyatt Allen | 605bc57 | 2018-08-01 15:08:30 -0700 | [diff] [blame] | 75 | this.set('displayedColumns', this._getDisplayedColumns()); |
Becky Siegel | 1a44b34 | 2016-11-14 08:37:06 -0800 | [diff] [blame] | 76 | }, |
| 77 | }); |
| 78 | })(); |