| 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 /** The expanded state of the list of networks. */ | |
| 18 expanded: { | |
| 19 type: Boolean, | |
| 20 value: false, | |
| 21 observer: 'expandedChanged_', | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * Whether the list has been expanded. This is used to ensure the | |
| 26 * iron-collapse section animates correctly. | |
| 27 */ | |
| 28 wasExpanded: { | |
| 29 type: Boolean, | |
| 30 value: false, | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * The maximum height in pixels for the list of networks. | |
| 35 */ | |
| 36 maxHeight: { | |
| 37 type: Number, | |
| 38 value: 200, | |
| 39 }, | |
| 40 | |
| 41 /** | 17 /** |
| 42 * Device state for the network type. | 18 * Device state for the network type. |
| 43 * @type {DeviceStateProperties|undefined} | 19 * @type {DeviceStateProperties|undefined} |
| 44 */ | 20 */ |
| 45 deviceState: { | 21 deviceState: { |
| 46 type: Object, | 22 type: Object, |
| 47 observer: 'deviceStateChanged_', | 23 observer: 'deviceStateChanged_', |
| 48 }, | 24 }, |
| 49 | 25 |
| 50 /** | 26 /** |
| 51 * Network state for the active network. | 27 * Network state for the active network. |
| 52 * @type {!CrOnc.NetworkStateProperties|undefined} | 28 * @type {!CrOnc.NetworkStateProperties|undefined} |
| 53 */ | 29 */ |
| 54 activeNetworkState: { | 30 activeNetworkState: { |
| 55 type: Object, | 31 type: Object, |
| 56 observer: 'activeNetworkStateChanged_', | 32 observer: 'activeNetworkStateChanged_', |
| 57 }, | 33 }, |
| 58 | 34 |
| 59 /** | 35 /** |
| 60 * List of all network state data for the network type. | 36 * List of all network state data for the network type. |
| 61 * @type {!Array<!CrOnc.NetworkStateProperties>} | 37 * @type {!Array<!CrOnc.NetworkStateProperties>} |
| 62 */ | 38 */ |
| 63 networkStateList: { | 39 networkStateList: { |
| 64 type: Array, | 40 type: Array, |
| 65 value: function() { return []; }, | 41 value: function() { |
| 42 return []; |
| 43 }, |
| 66 observer: 'networkStateListChanged_', | 44 observer: 'networkStateListChanged_', |
| 67 } | 45 }, |
| 46 |
| 47 /** The maximum height in pixels for the list of networks. */ |
| 48 maxHeight: { |
| 49 type: Number, |
| 50 value: 200, |
| 51 }, |
| 52 |
| 53 /** The expanded state of the list of networks. */ |
| 54 expanded_: { |
| 55 type: Boolean, |
| 56 value: false, |
| 57 observer: 'expandedChanged_', |
| 58 }, |
| 59 |
| 60 /** |
| 61 * Whether the list has been expanded. This is used to ensure the |
| 62 * iron-collapse section animates correctly. |
| 63 */ |
| 64 wasExpanded_: { |
| 65 type: Boolean, |
| 66 value: false, |
| 67 }, |
| 68 }, | 68 }, |
| 69 | 69 |
| 70 /** @private */ | 70 /** @private */ |
| 71 expandedChanged_: function() { | 71 expandedChanged_: function() { |
| 72 var type = this.deviceState ? this.deviceState.Type : ''; | 72 var type = this.deviceState ? this.deviceState.Type : ''; |
| 73 this.fire('expanded', {expanded: this.expanded, type: type}); | 73 this.fire('expanded', {expanded: this.expanded_, type: type}); |
| 74 }, | 74 }, |
| 75 | 75 |
| 76 /** @private */ | 76 /** @private */ |
| 77 deviceStateChanged_: function() { | 77 deviceStateChanged_: function() { |
| 78 this.updateSelectable_(); | 78 this.updateSelectable_(); |
| 79 if (this.expanded && !this.deviceIsEnabled_(this.deviceState)) | 79 if (this.expanded_ && !this.deviceIsEnabled_()) |
| 80 this.expanded = false; | 80 this.expanded_ = false; |
| 81 }, | 81 }, |
| 82 | 82 |
| 83 /** @private */ | 83 /** @private */ |
| 84 activeNetworkStateChanged_: function() { | 84 activeNetworkStateChanged_: function() { |
| 85 this.updateSelectable_(); | 85 this.updateSelectable_(); |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** @private */ | 88 /** @private */ |
| 89 networkStateListChanged_: function() { this.updateSelectable_(); }, | 89 networkStateListChanged_: function() { |
| 90 this.updateSelectable_(); |
| 91 }, |
| 90 | 92 |
| 91 /** | 93 /** |
| 92 * @param {DeviceStateProperties} deviceState | |
| 93 * @param {boolean} expanded The expanded state. | |
| 94 * @return {boolean} Whether or not the scanning spinner should be shown. | 94 * @return {boolean} Whether or not the scanning spinner should be shown. |
| 95 * @private | 95 * @private |
| 96 */ | 96 */ |
| 97 showScanning_: function(deviceState, expanded) { | 97 showScanning_: function() { |
| 98 return !!expanded && !!deviceState.Scanning; | 98 return !!this.expanded_ && !!this.deviceState.Scanning; |
| 99 }, | 99 }, |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * @param {DeviceStateProperties|undefined} deviceState | |
| 103 * @return {boolean} Whether or not the device state is enabled. | 102 * @return {boolean} Whether or not the device state is enabled. |
| 104 * @private | 103 * @private |
| 105 */ | 104 */ |
| 106 deviceIsEnabled_: function(deviceState) { | 105 deviceIsEnabled_: function() { |
| 107 return !!deviceState && deviceState.State == 'Enabled'; | 106 return !!this.deviceState && |
| 107 this.deviceState.State == |
| 108 chrome.networkingPrivate.DeviceStateType.ENABLED; |
| 108 }, | 109 }, |
| 109 | 110 |
| 110 /** | 111 /** |
| 111 * @return {boolean} Whether the dom-if for the network list should be true. | 112 * @return {boolean} Whether the dom-if for the network list should be true. |
| 112 * The logic here is designed to allow the enclosed content to be stamped | 113 * The logic here is designed to allow the enclosed content to be stamped |
| 113 * before it is expanded. | 114 * before it is expanded. |
| 114 * @private | 115 * @private |
| 115 */ | 116 */ |
| 116 networksDomIfIsTrue_() { | 117 networksDomIfIsTrue_() { |
| 117 if (this.expanded == this.wasExpanded) | 118 if (this.expanded_ == this.wasExpanded_) |
| 118 return this.expanded; | 119 return this.expanded_; |
| 119 if (this.expanded) { | 120 if (this.expanded_) { |
| 120 Polymer.RenderStatus.afterNextRender(this, function() { | 121 Polymer.RenderStatus.afterNextRender(this, function() { |
| 121 this.wasExpanded = true; | 122 this.wasExpanded_ = true; |
| 122 }.bind(this)); | 123 }.bind(this)); |
| 123 return true; | 124 return true; |
| 124 } | 125 } |
| 125 return this.wasExpanded; | 126 return this.wasExpanded_; |
| 126 }, | 127 }, |
| 127 | 128 |
| 128 /** | 129 /** |
| 129 * @return {boolean} Whether the iron-collapse for the network list should | 130 * @return {boolean} Whether the iron-collapse for the network list should |
| 130 * be opened. | 131 * be opened. |
| 131 * @private | 132 * @private |
| 132 */ | 133 */ |
| 133 networksIronCollapseIsOpened_() { | 134 networksIronCollapseIsOpened_() { |
| 134 return this.expanded && this.wasExpanded; | 135 return this.expanded_ && this.wasExpanded_; |
| 135 }, | 136 }, |
| 136 | 137 |
| 137 /** | 138 /** |
| 138 * @param {DeviceStateProperties} deviceState | |
| 139 * @return {boolean} | 139 * @return {boolean} |
| 140 * @private | 140 * @private |
| 141 */ | 141 */ |
| 142 enableIsVisible_: function(deviceState) { | 142 enableIsVisible_: function() { |
| 143 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && | 143 return !!this.deviceState && this.deviceState.Type != CrOnc.Type.ETHERNET && |
| 144 deviceState.Type != CrOnc.Type.VPN; | 144 this.deviceState.Type != CrOnc.Type.VPN; |
| 145 }, | 145 }, |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {DeviceStateProperties|undefined} deviceState | |
| 149 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList | |
| 150 * @return {boolean} Whether or not to show the UI to expand the list. | 148 * @return {boolean} Whether or not to show the UI to expand the list. |
| 151 * @private | 149 * @private |
| 152 */ | 150 */ |
| 153 expandIsVisible_: function(deviceState, networkStateList) { | 151 expandIsVisible_: function() { |
| 154 if (!this.deviceIsEnabled_(deviceState)) | 152 if (!this.deviceIsEnabled_()) |
| 155 return false; | 153 return false; |
| 156 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; | 154 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; |
| 157 return networkStateList.length >= minLength; | 155 return this.networkStateList.length >= minLength; |
| 158 }, | 156 }, |
| 159 | 157 |
| 160 /** | 158 /** |
| 161 * @param {!CrOnc.NetworkStateProperties} state | |
| 162 * @return {boolean} True if the known networks button should be shown. | 159 * @return {boolean} True if the known networks button should be shown. |
| 163 * @private | 160 * @private |
| 164 */ | 161 */ |
| 165 knownNetworksIsVisible_: function(state) { | 162 knownNetworksIsVisible_: function() { |
| 166 return !!state && state.Type == CrOnc.Type.WI_FI; | 163 return !!this.activeNetworkState && |
| 164 this.activeNetworkState.Type == CrOnc.Type.WI_FI; |
| 167 }, | 165 }, |
| 168 | 166 |
| 169 /** | 167 /** |
| 170 * Event triggered when the details div is tapped. | 168 * Event triggered when the details div is tapped. |
| 171 * @param {Event} event The enable button event. | 169 * @param {Event} event The enable button event. |
| 172 * @private | 170 * @private |
| 173 */ | 171 */ |
| 174 onDetailsTap_: function(event) { | 172 onDetailsTap_: function(event) { |
| 175 if ((event.target.id == 'expandListButton') || | 173 if ((event.target.id == 'expandListButton') || |
| 176 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) { | 174 (this.deviceState && !this.deviceIsEnabled_())) { |
| 177 // Already handled or disabled, do nothing. | 175 // Already handled or disabled, do nothing. |
| 178 return; | 176 return; |
| 179 } | 177 } |
| 180 if (this.expandIsVisible_(this.deviceState, this.networkStateList)) { | 178 if (this.expandIsVisible_()) { |
| 181 // Expandable, toggle expand. | 179 // Expandable, toggle expand. |
| 182 this.expanded = !this.expanded; | 180 this.expanded_ = !this.expanded_; |
| 183 return; | 181 return; |
| 184 } | 182 } |
| 185 // Not expandable, fire 'selected' with |activeNetworkState|. | 183 // Not expandable, fire 'selected' with |activeNetworkState|. |
| 186 this.fire('selected', this.activeNetworkState); | 184 this.fire('selected', this.activeNetworkState); |
| 187 }, | 185 }, |
| 188 | 186 |
| 189 /** | 187 /** |
| 190 * Event triggered when the known networks button is tapped. | 188 * Event triggered when the known networks button is tapped. |
| 191 * @private | 189 * @private |
| 192 */ | 190 */ |
| 193 onKnownNetworksTap_: function() { | 191 onKnownNetworksTap_: function() { |
| 194 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); | 192 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); |
| 195 }, | 193 }, |
| 196 | 194 |
| 197 /** | 195 /** |
| 198 * Event triggered when the enable button is toggled. | 196 * Event triggered when the enable button is toggled. |
| 199 * @param {!Event} event | 197 * @param {!Event} event |
| 200 * @private | 198 * @private |
| 201 */ | 199 */ |
| 202 onDeviceEnabledTap_: function(event) { | 200 onDeviceEnabledTap_: function(event) { |
| 203 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 201 var deviceIsEnabled = this.deviceIsEnabled_(); |
| 204 var type = this.deviceState ? this.deviceState.Type : ''; | 202 var type = this.deviceState ? this.deviceState.Type : ''; |
| 205 this.fire( | 203 this.fire( |
| 206 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 204 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 207 // Make sure this does not propagate to onDetailsTap_. | 205 // Make sure this does not propagate to onDetailsTap_. |
| 208 event.stopPropagation(); | 206 event.stopPropagation(); |
| 209 }, | 207 }, |
| 210 | 208 |
| 211 /** | 209 /** |
| 212 * Called whenever the 'selectable' state might change. | 210 * Called whenever the 'selectable' state might change. |
| 213 * @private | 211 * @private |
| 214 */ | 212 */ |
| 215 updateSelectable_: function() { | 213 updateSelectable_: function() { |
| 216 var selectable = this.deviceIsEnabled_(this.deviceState); | 214 var selectable = this.deviceIsEnabled_(); |
| 217 this.$.details.classList.toggle('selectable', selectable); | 215 this.$.details.classList.toggle('selectable', selectable); |
| 218 }, | 216 }, |
| 219 }); | 217 }); |
| OLD | NEW |