| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Polymer element for displaying the network state for a specific | 6 * @fileoverview Polymer element for displaying the network state for a specific |
| 7 * type and a list of networks for that type. | 7 * type and a list of networks for that type. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ |
| 11 var DeviceStateProperties; | 11 var DeviceStateProperties; |
| 12 | 12 |
| 13 Polymer({ | 13 Polymer({ |
| 14 is: 'network-summary-item', | 14 is: 'network-summary-item', |
| 15 | 15 |
| 16 properties: { | 16 properties: { |
| 17 /** | 17 /** |
| 18 * True if the list is expanded. | 18 * True if the list is expanded. |
| 19 */ | 19 */ |
| 20 expanded: { | 20 expanded: { |
| 21 type: Boolean, | 21 type: Boolean, |
| 22 value: false, | 22 value: false, |
| 23 observer: 'expandedChanged_' | 23 observer: 'expandedChanged_', |
| 24 }, | 24 }, |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * The maximum height in pixels for the list of networks. | 27 * The maximum height in pixels for the list of networks. |
| 28 */ | 28 */ |
| 29 maxHeight: { | 29 maxHeight: { |
| 30 type: Number, | 30 type: Number, |
| 31 value: 200 | 31 value: 200, |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * True if this item should be hidden. We need this computed property so | |
| 36 * that it can default to true, hiding this element, since no changed event | |
| 37 * will be fired for deviceState if it is undefined (in NetworkSummary). | |
| 38 */ | |
| 39 isHidden: { | |
| 40 type: Boolean, | |
| 41 value: true, | |
| 42 computed: 'noDeviceState_(deviceState)' | |
| 43 }, | |
| 44 | |
| 45 /** | |
| 46 * Device state for the network type. | 35 * Device state for the network type. |
| 47 * @type {DeviceStateProperties|undefined} | 36 * @type {DeviceStateProperties|undefined} |
| 48 */ | 37 */ |
| 49 deviceState: { | 38 deviceState: { |
| 50 type: Object, | 39 type: Object, |
| 51 observer: 'deviceStateChanged_' | 40 observer: 'deviceStateChanged_', |
| 52 }, | 41 }, |
| 53 | 42 |
| 54 /** | 43 /** |
| 55 * Network state for the active network. | 44 * Network state for the active network. |
| 56 * @type {!CrOnc.NetworkStateProperties|undefined} | 45 * @type {!CrOnc.NetworkStateProperties|undefined} |
| 57 */ | 46 */ |
| 58 networkState: { | 47 activeNetworkState: { |
| 59 type: Object, | 48 type: Object, |
| 49 observer: 'activeNetworkStateChanged_', |
| 60 }, | 50 }, |
| 61 | 51 |
| 62 /** | 52 /** |
| 63 * List of all network state data for the network type. | 53 * List of all network state data for the network type. |
| 64 * @type {!Array<!CrOnc.NetworkStateProperties>} | 54 * @type {!Array<!CrOnc.NetworkStateProperties>} |
| 65 */ | 55 */ |
| 66 networkStateList: { | 56 networkStateList: { |
| 67 type: Array, | 57 type: Array, |
| 68 value: function() { return []; }, | 58 value: function() { return []; }, |
| 69 observer: 'networkStateListChanged_' | 59 observer: 'networkStateListChanged_', |
| 70 } | 60 } |
| 71 }, | 61 }, |
| 72 | 62 |
| 73 /** | 63 /** @private */ |
| 74 * Polymer expanded changed method. | |
| 75 */ | |
| 76 expandedChanged_: function() { | 64 expandedChanged_: function() { |
| 77 var type = this.deviceState ? this.deviceState.Type : ''; | 65 var type = this.deviceState ? this.deviceState.Type : ''; |
| 78 this.fire('expanded', {expanded: this.expanded, type: type}); | 66 this.fire('expanded', {expanded: this.expanded, type: type}); |
| 79 }, | 67 }, |
| 80 | 68 |
| 81 /** | 69 /** @private */ |
| 82 * Polymer deviceState changed method. | |
| 83 */ | |
| 84 deviceStateChanged_: function() { | 70 deviceStateChanged_: function() { |
| 85 this.updateSelectable_(); | 71 this.updateSelectable_(); |
| 86 if (this.expanded && !this.deviceIsEnabled_(this.deviceState)) | 72 if (this.expanded && !this.deviceIsEnabled_(this.deviceState)) |
| 87 this.expanded = false; | 73 this.expanded = false; |
| 88 }, | 74 }, |
| 89 | 75 |
| 90 /** | 76 /** @private */ |
| 91 * Polymer networkStateList changed method. | 77 activeNetworkStateChanged_: function() { |
| 92 */ | |
| 93 networkStateListChanged_: function() { | |
| 94 this.updateSelectable_(); | 78 this.updateSelectable_(); |
| 95 }, | 79 }, |
| 96 | 80 |
| 97 /** | 81 /** @private */ |
| 98 * @param {DeviceStateProperties} deviceState | 82 networkStateListChanged_: function() { this.updateSelectable_(); }, |
| 99 * @return {boolean} True if the device state is not set. | |
| 100 * @private | |
| 101 */ | |
| 102 noDeviceState_: function(deviceState) { | |
| 103 return !deviceState; | |
| 104 }, | |
| 105 | 83 |
| 106 /** | 84 /** |
| 107 * @param {DeviceStateProperties} deviceState | 85 * @param {DeviceStateProperties} deviceState |
| 108 * @param {boolean} expanded The expanded state. | 86 * @param {boolean} expanded The expanded state. |
| 109 * @return {boolean} Whether or not the scanning spinner should be shown. | 87 * @return {boolean} Whether or not the scanning spinner should be shown. |
| 110 * @private | 88 * @private |
| 111 */ | 89 */ |
| 112 showScanning_: function(deviceState, expanded) { | 90 showScanning_: function(deviceState, expanded) { |
| 113 return !!expanded && !!deviceState.Scanning; | 91 return !!expanded && !!deviceState.Scanning; |
| 114 }, | 92 }, |
| 115 | 93 |
| 116 /** | 94 /** |
| 117 * @param {DeviceStateProperties|undefined} deviceState | 95 * @param {DeviceStateProperties|undefined} deviceState |
| 118 * @return {boolean} Whether or not the device state is enabled. | 96 * @return {boolean} Whether or not the device state is enabled. |
| 119 * @private | 97 * @private |
| 120 */ | 98 */ |
| 121 deviceIsEnabled_: function(deviceState) { | 99 deviceIsEnabled_: function(deviceState) { |
| 122 return !!deviceState && deviceState.State == 'Enabled'; | 100 return !!deviceState && deviceState.State == 'Enabled'; |
| 123 }, | 101 }, |
| 124 | 102 |
| 125 /** | 103 /** |
| 126 * @param {DeviceStateProperties} deviceState | 104 * @param {DeviceStateProperties} deviceState |
| 127 * @return {string} The class value for the device enabled button. | 105 * @return {boolean} |
| 128 * @private | 106 * @private |
| 129 */ | 107 */ |
| 130 getDeviceEnabledButtonClass_: function(deviceState) { | 108 enableIsVisible_: function(deviceState) { |
| 131 var visible = deviceState && deviceState.Type != CrOnc.Type.ETHERNET && | 109 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && |
| 132 deviceState.Type != CrOnc.Type.VPN; | 110 deviceState.Type != CrOnc.Type.VPN; |
| 133 return visible ? '' : 'invisible'; | |
| 134 }, | |
| 135 | |
| 136 /** | |
| 137 * @param {DeviceStateProperties} deviceState | |
| 138 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList | |
| 139 * @return {string} The class value for the expand button. | |
| 140 * @private | |
| 141 */ | |
| 142 getExpandButtonClass_: function(deviceState, networkList) { | |
| 143 var visible = this.expandIsVisible_(deviceState, networkList); | |
| 144 return visible ? '' : 'invisible'; | |
| 145 }, | 111 }, |
| 146 | 112 |
| 147 /** | 113 /** |
| 148 * @param {DeviceStateProperties|undefined} deviceState | 114 * @param {DeviceStateProperties|undefined} deviceState |
| 149 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList | 115 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 150 * @return {boolean} Whether or not to show the UI to expand the list. | 116 * @return {boolean} Whether or not to show the UI to expand the list. |
| 151 * @private | 117 * @private |
| 152 */ | 118 */ |
| 153 expandIsVisible_: function(deviceState, networkList) { | 119 expandIsVisible_: function(deviceState, networkStateList) { |
| 154 if (!this.deviceIsEnabled_(deviceState)) | 120 if (!this.deviceIsEnabled_(deviceState)) |
| 155 return false; | 121 return false; |
| 156 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; | 122 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; |
| 157 return networkList.length >= minLength; | 123 return networkStateList.length >= minLength; |
| 158 }, | 124 }, |
| 159 | 125 |
| 160 /** | 126 /** |
| 161 * @param {!CrOnc.NetworkStateProperties} state | 127 * @param {!CrOnc.NetworkStateProperties} state |
| 162 * @param {boolean} expanded The expanded state. | 128 * @return {boolean} True if the known networks button should be shown. |
| 163 * @return {boolean} True if the 'Known networks' button should be shown. | |
| 164 * @private | 129 * @private |
| 165 */ | 130 */ |
| 166 showKnownNetworks_: function(state, expanded) { | 131 knownNetworksIsVisible_: function(state) { |
| 167 return !!expanded && !!state && state.Type == CrOnc.Type.WI_FI; | 132 return !!state && state.Type == CrOnc.Type.WI_FI; |
| 168 }, | 133 }, |
| 169 | 134 |
| 170 /** | 135 /** |
| 171 * Event triggered when the details div is tapped. | 136 * Event triggered when the details div is tapped. |
| 172 * @param {Event} event The enable button event. | 137 * @param {Event} event The enable button event. |
| 173 * @private | 138 * @private |
| 174 */ | 139 */ |
| 175 onDetailsTap_: function(event) { | 140 onDetailsTap_: function(event) { |
| 176 if ((event.target.id == 'expandListButton') || | 141 if ((event.target.id == 'expandListButton') || |
| 177 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) { | 142 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) { |
| 178 // Already handled or disabled, do nothing. | 143 // Already handled or disabled, do nothing. |
| 179 return; | 144 return; |
| 180 } | 145 } |
| 181 if (this.expandIsVisible_(this.deviceState, this.networkStateList)) { | 146 if (this.expandIsVisible_(this.deviceState, this.networkStateList)) { |
| 182 // Expandable, toggle expand. | 147 // Expandable, toggle expand. |
| 183 this.expanded = !this.expanded; | 148 this.expanded = !this.expanded; |
| 184 return; | 149 return; |
| 185 } | 150 } |
| 186 // Not expandable, fire 'selected' with |networkState|. | 151 // Not expandable, fire 'selected' with |activeNetworkState|. |
| 187 this.fire('selected', this.networkState); | 152 this.fire('selected', this.activeNetworkState); |
| 188 }, | 153 }, |
| 189 | 154 |
| 190 /** | 155 /** |
| 191 * Event triggered when the known networks button is tapped. | 156 * Event triggered when the known networks button is tapped. |
| 192 * @private | 157 * @private |
| 193 */ | 158 */ |
| 194 onKnownNetworksTap_: function() { | 159 onKnownNetworksTap_: function() { |
| 195 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); | 160 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); |
| 196 }, | 161 }, |
| 197 | 162 |
| 198 /** | 163 /** |
| 199 * Event triggered when the enable button is toggled. | 164 * Event triggered when the enable button is toggled. |
| 200 * @param {!Event} event | 165 * @param {!Event} event |
| 201 * @private | 166 * @private |
| 202 */ | 167 */ |
| 203 onDeviceEnabledTap_: function(event) { | 168 onDeviceEnabledTap_: function(event) { |
| 204 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 169 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
| 205 var type = this.deviceState ? this.deviceState.Type : ''; | 170 var type = this.deviceState ? this.deviceState.Type : ''; |
| 206 this.fire('device-enabled-toggled', | 171 this.fire( |
| 207 {enabled: !deviceIsEnabled, type: type}); | 172 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 208 // Make sure this does not propagate to onDetailsTap_. | 173 // Make sure this does not propagate to onDetailsTap_. |
| 209 event.stopPropagation(); | 174 event.stopPropagation(); |
| 210 }, | 175 }, |
| 211 | 176 |
| 212 /** | 177 /** |
| 213 * Called whenever the 'selectable' state might change. | 178 * Called whenever the 'selectable' state might change. |
| 214 * @private | 179 * @private |
| 215 */ | 180 */ |
| 216 updateSelectable_: function() { | 181 updateSelectable_: function() { |
| 217 var selectable = this.deviceIsEnabled_(this.deviceState); | 182 var selectable = this.deviceIsEnabled_(this.deviceState); |
| 218 this.$.details.classList.toggle('selectable', selectable); | 183 this.$.details.classList.toggle('selectable', selectable); |
| 219 }, | 184 }, |
| 220 }); | 185 }); |
| OLD | NEW |