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 200 | |
31 */ | |
32 maxHeight: 200, | |
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. | |
88 * @return {boolean} Whether or not the device state is enabled. | |
89 * @private | |
90 */ | |
91 deviceIsEnabled_: function(deviceState) { | |
92 return deviceState && deviceState.State == 'Enabled'; | |
93 }, | |
94 | |
95 /** | |
96 * @param {?DeviceStateProperties} deviceState The device state. | |
97 * @return {boolean} Whether or not to show the UI to enable the network. | |
98 * @private | |
99 */ | |
100 deviceEnabledIsVisible_: 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>} netwprkList A list of networks. | |
Jeremy Klein
2015/04/27 22:29:03
"networkList"
stevenjb
2015/04/28 01:05:02
Done.
| |
108 * @return {boolean} Whether or not to show the UI to expand the list. | |
109 * @private | |
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 }, | |
137 | |
138 /** | |
139 * Event triggered when a cr-network-item is the network list is selected. | |
140 * @param {!{detail: CrNetworkListItem}} event | |
141 * @private | |
142 */ | |
143 onListItemSelected_: function(event) { | |
144 var onc = event.detail; | |
145 this.fire('selected', onc); | |
146 }, | |
147 | |
148 /** | |
149 * Event triggered when the enable button is toggled. | |
150 * @param {!Object} event The enable button event. | |
151 * @private | |
152 */ | |
153 onDeviceEnabledToggled_: function(event) { | |
154 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | |
155 var type = this.deviceState ? this.deviceState.Type : ''; | |
156 this.fire('device-enabled-toggled', | |
157 {enabled: !deviceIsEnabled, type: type}); | |
158 // Make sure this does not propagate to onDetailsClicked_. | |
159 event.stopPropagation(); | |
160 }, | |
161 | |
162 /** | |
163 * Called whenever the 'selectable' state might change. | |
164 * @private | |
165 */ | |
166 updateSelectable_: function() { | |
167 // TODO(stevenjb): Make any actionable item selectable. | |
168 var selectable = | |
169 this.expandIsVisible_(this.deviceState, this.networkStateList); | |
170 this.$.details.classList.toggle('selectable', selectable); | |
171 }, | |
172 }); | |
173 })(); | |
OLD | NEW |