Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ui/webui/resources/cr_elements/network/cr_network_select.js

Issue 2627353003: Settings/Oobe: Simplify cr-network-select and use flex (Closed)
Patch Set: Add comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/webui/resources/cr_elements/network/cr_network_select.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 wrapping cr-network-list including the 6 * @fileoverview Polymer element wrapping cr-network-list including the
7 * networkingPrivate calls to populate it. 7 * networkingPrivate calls to populate it.
8 */ 8 */
9 9
10 Polymer({ 10 Polymer({
11 is: 'cr-network-select', 11 is: 'cr-network-select',
12 12
13 behaviors: [I18nBehavior], 13 behaviors: [I18nBehavior],
14 14
15 properties: { 15 properties: {
16 /** 16 /**
17 * Network state for the active network.
18 * @type {?CrOnc.NetworkStateProperties}
19 */
20 activeNetworkState: Object,
21
22 /**
23 * If true, the element includes an 'expand' button that toggles the
24 * expanded state of the network list.
25 */
26 expandable: {
27 type: Boolean,
28 value: false,
29 },
30
31 /**
32 * The maximum height in pixels for the list.
33 */
34 maxHeight: {
35 type: Number,
36 value: 1000,
37 },
38
39 /**
40 * If true, expand the network list.
41 */
42 networkListOpened: {
43 type: Boolean,
44 value: true,
45 observer: 'networkListOpenedChanged_',
46 },
47
48 /**
49 * If true, show the active network state.
50 */
51 showActive: {
52 type: Boolean,
53 value: false,
54 reflectToAttribute: true,
55 },
56
57 /**
58 * Show all buttons in list items. 17 * Show all buttons in list items.
59 */ 18 */
60 showButtons: { 19 showButtons: {
61 type: Boolean, 20 type: Boolean,
62 value: false, 21 value: false,
63 reflectToAttribute: true, 22 reflectToAttribute: true,
64 }, 23 },
65 24
66 /** 25 /**
67 * List of all network state data for all visible networks.
68 * @type {!Array<!CrOnc.NetworkStateProperties>}
69 */
70 networkStateList: {
71 type: Array,
72 value: function() {
73 return [];
74 }
75 },
76
77 /**
78 * The list of custom items to display after the list of networks. 26 * The list of custom items to display after the list of networks.
79 * See CrNetworkList for details. 27 * See CrNetworkList for details.
80 * @type {!Array<CrNetworkList.CustomItemState>} 28 * @type {!Array<CrNetworkList.CustomItemState>}
81 */ 29 */
82 customItems: { 30 customItems: {
83 type: Array, 31 type: Array,
84 value: function() { 32 value: function() {
85 return []; 33 return [];
86 }, 34 },
87 }, 35 },
88 36
89 /** 37 /**
90 * Whether to handle "item-selected" for network items. 38 * Whether to handle "item-selected" for network items.
91 * If this property is false, "network-item-selected" event is fired 39 * If this property is false, "network-item-selected" event is fired
92 * carrying CrOnc.NetworkStateProperties as event detail. 40 * carrying CrOnc.NetworkStateProperties as event detail.
93 *
94 * @type {Function} 41 * @type {Function}
95 */ 42 */
96 handleNetworkItemSelected: { 43 handleNetworkItemSelected: {
97 type: Boolean, 44 type: Boolean,
98 value: false, 45 value: false,
99 reflectToAttribute: true, 46 reflectToAttribute: true,
100 }, 47 },
48
49 /**
50 * List of all network state data for all visible networks.
51 * @private {!Array<!CrOnc.NetworkStateProperties>}
52 */
53 networkStateList_: {
54 type: Array,
55 value: function() {
56 return [];
57 }
58 },
59
101 }, 60 },
102 61
103 /** 62 /**
104 * Listener function for chrome.networkingPrivate.onNetworkListChanged event. 63 * Listener function for chrome.networkingPrivate.onNetworkListChanged event.
105 * @type {function(!Array<string>)} 64 * @type {function(!Array<string>)}
106 * @private 65 * @private
107 */ 66 */
108 networkListChangedListener_: function() {}, 67 networkListChangedListener_: function() {},
109 68
110 /** 69 /**
111 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged 70 * Listener function for chrome.networkingPrivate.onDeviceStateListChanged
112 * event. 71 * event.
113 * @type {function(!Array<string>)} 72 * @type {function(!Array<string>)}
114 * @private 73 * @private
115 */ 74 */
116 deviceStateListChangedListener_: function() {}, 75 deviceStateListChangedListener_: function() {},
117 76
118 /** @override */ 77 /** @override */
119 attached: function() { 78 attached: function() {
120 this.networkListChangedListener_ = this.refreshNetworks_.bind(this); 79 this.networkListChangedListener_ = this.refreshNetworks.bind(this);
121 chrome.networkingPrivate.onNetworkListChanged.addListener( 80 chrome.networkingPrivate.onNetworkListChanged.addListener(
122 this.networkListChangedListener_); 81 this.networkListChangedListener_);
123 82
124 this.deviceStateListChangedListener_ = this.refreshNetworks_.bind(this); 83 this.deviceStateListChangedListener_ = this.refreshNetworks.bind(this);
125 chrome.networkingPrivate.onDeviceStateListChanged.addListener( 84 chrome.networkingPrivate.onDeviceStateListChanged.addListener(
126 this.deviceStateListChangedListener_); 85 this.deviceStateListChangedListener_);
127 86
128 this.refreshNetworks_(); 87 this.refreshNetworks();
129 chrome.networkingPrivate.requestNetworkScan(); 88 chrome.networkingPrivate.requestNetworkScan();
130 }, 89 },
131 90
132 /** @override */ 91 /** @override */
133 detached: function() { 92 detached: function() {
134 chrome.networkingPrivate.onNetworkListChanged.removeListener( 93 chrome.networkingPrivate.onNetworkListChanged.removeListener(
135 this.networkListChangedListener_); 94 this.networkListChangedListener_);
136 chrome.networkingPrivate.onDeviceStateListChanged.removeListener( 95 chrome.networkingPrivate.onDeviceStateListChanged.removeListener(
137 this.deviceStateListChangedListener_); 96 this.deviceStateListChangedListener_);
138 }, 97 },
139 98
140 /** 99 /**
141 * Polymer changed function. 100 * Request the list of visible networks. May be called externally to force a
101 * refresh and list update (e.g. when the element is shown).
142 * @private 102 * @private
143 */ 103 */
144 networkListOpenedChanged_: function() { 104 refreshNetworks: function() {
145 if (this.networkListOpened)
146 chrome.networkingPrivate.requestNetworkScan();
147 },
148
149 /**
150 * Request the list of visible networks.
151 * @private
152 */
153 refreshNetworks_: function() {
154 var filter = { 105 var filter = {
155 networkType: chrome.networkingPrivate.NetworkType.ALL, 106 networkType: chrome.networkingPrivate.NetworkType.ALL,
156 visible: true, 107 visible: true,
157 configured: false 108 configured: false
158 }; 109 };
159 chrome.networkingPrivate.getNetworks( 110 chrome.networkingPrivate.getNetworks(
160 filter, this.getNetworksCallback_.bind(this)); 111 filter, this.getNetworksCallback_.bind(this));
161 }, 112 },
162 113
163 /** 114 /**
164 * @param {!Array<!CrOnc.NetworkStateProperties>} states 115 * @param {!Array<!CrOnc.NetworkStateProperties>} states
165 * @private 116 * @private
166 */ 117 */
167 getNetworksCallback_: function(states) { 118 getNetworksCallback_: function(states) {
168 this.activeNetworkState = states[0] || undefined; 119 this.networkStateList_ = states;
169 this.networkStateList = states;
170 }, 120 },
171 121
172 /** 122 /**
173 * Event triggered when a cr-network-list-item is selected. 123 * Event triggered when a cr-network-list-item is selected.
174 * @param {!{detail: !CrOnc.NetworkStateProperties}} event 124 * @param {!{detail: !CrOnc.NetworkStateProperties}} event
175 * @private 125 * @private
176 */ 126 */
177 onNetworkListItemSelected_: function(event) { 127 onNetworkListItemSelected_: function(event) {
178 var state = event.detail; 128 var state = event.detail;
179 129
180 if (!this.handleNetworkItemSelected) { 130 if (!this.handleNetworkItemSelected) {
181 this.fire('network-item-selected', state); 131 this.fire('network-item-selected', state);
182 return; 132 return;
183 } 133 }
184 134
185 if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED) 135 if (state.ConnectionState != CrOnc.ConnectionState.NOT_CONNECTED)
186 return; 136 return;
187 137
188 chrome.networkingPrivate.startConnect(state.GUID, function() { 138 chrome.networkingPrivate.startConnect(state.GUID, function() {
189 var lastError = chrome.runtime.lastError; 139 var lastError = chrome.runtime.lastError;
190 if (lastError && lastError != 'connecting') 140 if (lastError && lastError != 'connecting')
191 console.error('networkingPrivate.startConnect error: ' + lastError); 141 console.error('networkingPrivate.startConnect error: ' + lastError);
192 }); 142 });
193 }, 143 },
194
195 getExpandA11yText_: function() {
196 return this.i18n('networkExpandA11yLabel');
197 },
198 }); 144 });
OLDNEW
« no previous file with comments | « ui/webui/resources/cr_elements/network/cr_network_select.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698