Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview Polymer element for displaying the network state for a specific | |
| 7 * type and a list of networks for that type. | |
| 8 */ | |
| 9 (function() { | |
| 10 | |
| 11 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | |
| 12 var DeviceStateProperties; | |
| 13 | |
| 14 Polymer('cr-network-summary-item', { | |
| 15 publish: { | |
| 16 /** | |
| 17 * True if the list is expanded. | |
| 18 * | |
| 19 * @attribute expanded | |
| 20 * @type boolean | |
| 21 * @default false | |
| 22 */ | |
| 23 expanded: false, | |
| 24 | |
| 25 /** | |
| 26 * The maximum height in pixels for the list of networks. | |
| 27 * | |
| 28 * @attribute maxHeight | |
| 29 * @type number | |
| 30 * @default 1000 | |
|
Jeremy Klein
2015/04/23 18:21:15
If all actual uses are 200, why not make that the
stevenjb
2015/04/24 01:25:25
I guess that's fine here. I didn't want to bake th
| |
| 31 */ | |
| 32 maxHeight: 1000, | |
| 33 | |
| 34 /** | |
| 35 * Device state for the network type. | |
| 36 * | |
| 37 * @attribute deviceState | |
| 38 * @type {DeviceStateProperties} | |
| 39 * @default null | |
| 40 */ | |
| 41 deviceState: null, | |
| 42 | |
| 43 /** | |
| 44 * Network state for the active network. | |
| 45 * | |
| 46 * @attribute networkState | |
| 47 * @type {CrOncDataElement} | |
| 48 * @default null | |
| 49 */ | |
| 50 networkState: null, | |
| 51 | |
| 52 /** | |
| 53 * List of all network state data for the network type. | |
| 54 * | |
| 55 * @attribute networkStateList | |
| 56 * @type {Array<CrOncDataElement>} | |
| 57 * @default null | |
| 58 */ | |
| 59 networkStateList: null, | |
| 60 }, | |
| 61 | |
| 62 /** | |
| 63 * Polymer expanded changed method. | |
| 64 */ | |
| 65 expandedChanged: function() { | |
| 66 var type = this.deviceState ? this.deviceState.Type : ''; | |
| 67 this.fire('expanded', {expanded: this.expanded, type: type}); | |
| 68 }, | |
| 69 | |
| 70 /** | |
| 71 * Polymer deviceState changed method. | |
| 72 */ | |
| 73 deviceStateChanged: function() { | |
| 74 this.updateSelectable_(); | |
| 75 if (!this.deviceIsEnabled(this.deviceState)) | |
| 76 this.expanded = false; | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * Polymer networkStateList changed method. | |
| 81 */ | |
| 82 networkStateListChanged: function() { | |
| 83 this.updateSelectable_(); | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * @param {DeviceStateProperties} deviceState The state of a device. | |
|
Jeremy Klein
2015/04/23 18:21:15
nit: For nullable params here and elsewhere, pleas
stevenjb
2015/04/24 01:25:25
Ugh. Michael suggested elsewhere that ? wasn't nec
Jeremy Klein
2015/04/24 02:55:28
?s are strongly encouraged in Google3 by John Lenz
stevenjb
2015/04/24 19:03:18
Done.
michaelpg
2015/04/24 19:35:37
We are not in google3 and we should not be referen
Jeremy Klein
2015/04/24 20:26:07
Enforcing ! for non-nullable types isn't exactly t
| |
| 88 * @private | |
|
Jeremy Klein
2015/04/23 18:21:15
nit here and below: Our convention most places is
stevenjb
2015/04/24 01:25:25
Done.
| |
| 89 * @return {boolean} Whether or not the device state is enabled. | |
| 90 */ | |
| 91 deviceIsEnabled: function(deviceState) { | |
|
Jeremy Klein
2015/04/23 18:21:15
Here and elsewhere: trailing _ on private function
stevenjb
2015/04/24 01:25:25
I'll change all data binding methods if we decide
| |
| 92 return deviceState && deviceState.State == 'Enabled'; | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @param {DeviceStateProperties} deviceState The device state. | |
| 97 * @private | |
| 98 * @return {boolean} Whether or not to show the UI to enable the network. | |
| 99 */ | |
| 100 enableIsVisible: function(deviceState) { | |
| 101 return deviceState && | |
| 102 deviceState.Type != 'Ethernet' && deviceState.Type != 'VPN'; | |
| 103 }, | |
| 104 | |
| 105 /** | |
| 106 * @param {DeviceStateProperties} deviceState The device state. | |
| 107 * @param {Array<CrOncDataElement>|undefined} netowrkList A list of networks. | |
|
Jeremy Klein
2015/04/23 18:21:15
Can the networkList be null or undefined? If it ca
Jeremy Klein
2015/04/23 18:21:15
s/netowrkList/networkList/
stevenjb
2015/04/24 01:25:25
It can be null, not undefined. Fixed.
| |
| 108 * @private | |
| 109 * @return {boolean} Whether or not to show the UI to expand the list. | |
| 110 */ | |
| 111 expandIsVisible: function(deviceState, networkList) { | |
| 112 if (!this.deviceIsEnabled(deviceState) || !networkList) | |
| 113 return false; | |
| 114 var minLength = (this.type == 'WiFi') ? 1 : 2; | |
| 115 return networkList.length >= minLength; | |
| 116 }, | |
| 117 | |
| 118 /** | |
| 119 * Event triggered when the details div is clicked on. | |
| 120 * @param {Object} event The enable button event. | |
| 121 * @private | |
| 122 */ | |
| 123 onDetailsClicked: function(event) { | |
| 124 if ((event.target.id == 'expandListButton') || | |
| 125 (this.deviceState && !this.deviceIsEnabled(this.deviceState))) { | |
| 126 // Already handled or disabled, do nothing. | |
| 127 return; | |
| 128 } | |
| 129 if (this.expandIsVisible(this.deviceState, this.networkStateList)) { | |
| 130 // Expandable, toggle expand. | |
| 131 this.expanded = !this.expanded; | |
| 132 return; | |
| 133 } | |
| 134 // Not expandable, fire 'selected' with |networkState|. | |
| 135 this.fire('selected', this.networkState); | |
| 136 event.stopPropagation(); | |
|
Jeremy Klein
2015/04/23 18:21:15
Why do we need to stop propagation in this case?
stevenjb
2015/04/24 01:25:25
Probably here we don't, but I got bit by the butto
Jeremy Klein
2015/04/24 02:55:29
We really shouldn't be adding unnecessary stopProp
stevenjb
2015/04/24 19:03:19
Done.
| |
| 137 }, | |
| 138 | |
| 139 /** | |
| 140 * Event triggered when a cr-network-item is the network list is selected. | |
| 141 * @param {{detail: CrNetworkListItem}} event | |
| 142 */ | |
| 143 onListItemSelected: function(event) { | |
| 144 var onc = event.detail; | |
| 145 this.fire('selected', onc); | |
| 146 event.stopPropagation(); | |
| 147 }, | |
| 148 | |
| 149 /** | |
| 150 * Event triggered the enable button is toggled. | |
|
michaelpg
2015/04/23 02:16:29
nit: "when"
stevenjb
2015/04/24 01:25:25
Done.
| |
| 151 * @param {Object} event The enable button event. | |
| 152 * @private | |
| 153 */ | |
| 154 onEnableToggled: function(event) { | |
| 155 var deviceIsEnabled = this.deviceIsEnabled(this.deviceState); | |
| 156 var type = this.deviceState ? this.deviceState.Type : ''; | |
| 157 this.fire('toggle-enabled', {enabled: !deviceIsEnabled, type: type}); | |
| 158 event.stopPropagation(); | |
| 159 }, | |
| 160 | |
| 161 /** | |
| 162 * Called whenever the 'selectable' state might change. | |
| 163 */ | |
| 164 updateSelectable_: function() { | |
| 165 // TODO(stevenjb): Make any actionalble item selectable. | |
|
Jeremy Klein
2015/04/23 18:21:15
"actionable"
stevenjb
2015/04/24 01:25:25
Done.
| |
| 166 var selectable = | |
| 167 this.expandIsVisible(this.deviceState, this.networkStateList); | |
| 168 this.$.details.classList.toggle('selectable', selectable); | |
| 169 }, | |
| 170 }); | |
| 171 })(); | |
| OLD | NEW |