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.
6 * @fileoverview Polymer element for displaying the network state for a specific
7 * type and a list of networks for that type.
11 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */
12 var DeviceStateProperties
;
15 is
: 'network-summary-item',
19 * True if the list is expanded.
24 observer
: 'expandedChanged_'
28 * The maximum height in pixels for the list of networks.
36 * True if this item should be hidden. We need this computed property so
37 * that it can default to true, hiding this element, since no changed event
38 * will be fired for deviceState if it is undefined (in NetworkSummary).
43 computed
: 'noDeviceState_(deviceState)'
47 * Device state for the network type.
48 * @type {?DeviceStateProperties}
53 observer
: 'deviceStateChanged_'
57 * Network state for the active network.
58 * @type {?CrOnc.NetworkStateProperties}
66 * List of all network state data for the network type.
67 * @type {!Array<!CrOnc.NetworkStateProperties>}
71 value: function() { return []; },
72 observer
: 'networkStateListChanged_'
77 * Polymer expanded changed method.
79 expandedChanged_: function() {
80 var type
= this.deviceState
? this.deviceState
.Type
: '';
81 this.fire('expanded', {expanded
: this.expanded
, type
: type
});
85 * Polymer deviceState changed method.
87 deviceStateChanged_: function() {
88 this.updateSelectable_();
89 if (!this.deviceIsEnabled_(this.deviceState
))
90 this.expanded
= false;
94 * Polymer networkStateList changed method.
96 networkStateListChanged_: function() {
97 this.updateSelectable_();
101 * @param {?DeviceStateProperties} deviceState The state of a device.
102 * @return {boolean} True if the device state is not set.
105 noDeviceState_: function(deviceState
) {
110 * @param {?DeviceStateProperties} deviceState The state of a device.
111 * @return {boolean} Whether or not the scanning spinner should be shown.
114 showScanning_: function(deviceState
) {
115 return this.expanded
&& deviceState
.Scanning
;
119 * @param {?DeviceStateProperties} deviceState The state of a device.
120 * @return {boolean} Whether or not the device state is enabled.
123 deviceIsEnabled_: function(deviceState
) {
124 return deviceState
&& deviceState
.State
== 'Enabled';
128 * @param {?DeviceStateProperties} deviceState The device state.
129 * @return {string} The class value for the device enabled button.
132 getDeviceEnabledButtonClass_: function(deviceState
) {
133 var visible
= deviceState
&&
134 deviceState
.Type
!= CrOnc
.Type
.ETHERNET
&&
135 deviceState
.Type
!= CrOnc
.Type
.VPN
;
136 return visible
? '' : 'invisible';
140 * @param {?DeviceStateProperties} deviceState The device state.
141 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList
142 * @return {string} The class value for the expand button.
145 getExpandButtonClass_: function(deviceState
, networkList
) {
146 var visible
= this.expandIsVisible_(deviceState
, networkList
);
147 return visible
? '' : 'invisible';
151 * @param {?DeviceStateProperties} deviceState The device state.
152 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList
153 * @return {boolean} Whether or not to show the UI to expand the list.
156 expandIsVisible_: function(deviceState
, networkList
) {
157 if (!this.deviceIsEnabled_(deviceState
))
159 var minLength
= (this.type
== CrOnc
.Type
.WIFI
) ? 1 : 2;
160 return networkList
.length
>= minLength
;
164 * Event triggered when the details div is clicked on.
165 * @param {!Object} event The enable button event.
168 onDetailsClicked_: function(event
) {
169 if ((event
.target
.id
== 'expandListButton') ||
170 (this.deviceState
&& !this.deviceIsEnabled_(this.deviceState
))) {
171 // Already handled or disabled, do nothing.
174 if (this.expandIsVisible_(this.deviceState
, this.networkStateList
)) {
175 // Expandable, toggle expand.
176 this.expanded
= !this.expanded
;
179 // Not expandable, fire 'selected' with |networkState|.
180 this.fire('selected', this.networkState
);
184 * Event triggered when a network-list-item is the network list is selected.
185 * @param {!{detail: NetworkListItem}} event
188 onListItemSelected_: function(event
) {
189 var state
= event
.detail
;
190 this.fire('selected', state
);
194 * Event triggered when the enable button is toggled.
195 * @param {!Object} event The enable button event.
198 onDeviceEnabledToggled_: function(event
) {
199 var deviceIsEnabled
= this.deviceIsEnabled_(this.deviceState
);
200 var type
= this.deviceState
? this.deviceState
.Type
: '';
201 this.fire('device-enabled-toggled',
202 {enabled
: !deviceIsEnabled
, type
: type
});
203 // Make sure this does not propagate to onDetailsClicked_.
204 event
.stopPropagation();
208 * Called whenever the 'selectable' state might change.
211 updateSelectable_: function() {
212 var selectable
= this.deviceIsEnabled_(this.deviceState
);
213 this.$.details
.classList
.toggle('selectable', selectable
);