OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 var NetworkUI = (function() { | 5 var NetworkUI = (function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 // Properties to display in the network state table. Each entry can be either | 8 // Properties to display in the network state table. Each entry can be either |
9 // a single state field or an array of state fields. If more than one is | 9 // a single state field or an array of state fields. If more than one is |
10 // specified then the first non empty value is used. | 10 // specified then the first non empty value is used. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 button.addEventListener('click', function(event) { | 48 button.addEventListener('click', function(event) { |
49 toggleExpandRow(event.target, guid); | 49 toggleExpandRow(event.target, guid); |
50 }); | 50 }); |
51 button.className = 'state-table-expand-button'; | 51 button.className = 'state-table-expand-button'; |
52 button.textContent = '+'; | 52 button.textContent = '+'; |
53 cell.appendChild(button); | 53 cell.appendChild(button); |
54 return cell; | 54 return cell; |
55 }; | 55 }; |
56 | 56 |
57 /** | 57 /** |
58 * Create a cell with an icon representing the network state. | |
59 * | |
60 * @param {Object} state Property values for the network. | |
61 * @return {DOMElement} The created td element that displays the icon. | |
michaelpg
2015/02/05 06:45:51
This should be HTMLElement, right? But the rest of
Jeremy Klein
2015/02/05 18:45:56
Nice catch, Michael. Is DOMElement a real type? I'
Dan Beam
2015/02/05 18:54:14
nothing here is compiled. DOMElement is a ruse.
stevenjb
2015/02/05 22:41:32
No idea where DOMElement came from, I suspect it w
| |
62 */ | |
63 var createStateTableIcon = function(state) { | |
64 var cell = document.createElement('td'); | |
65 cell.className = 'state-table-icon-cell'; | |
66 var icon = document.createElement('cr-network-icon'); | |
67 icon.$.listItem = true; | |
michaelpg
2015/02/05 06:45:51
See my other comment, shouldn't this just be "icon
stevenjb
2015/02/05 22:41:33
I'm not sure where I got the notion of using .$. f
| |
68 icon.setNetworkState(state); | |
69 cell.appendChild(icon); | |
70 return cell; | |
71 }; | |
72 | |
73 /** | |
58 * Create a cell in network state table. | 74 * Create a cell in network state table. |
59 * | 75 * |
60 * @param {string} value Content in the cell. | 76 * @param {string} value Content in the cell. |
61 * @return {DOMElement} The created td element that displays the given value. | 77 * @return {DOMElement} The created td element that displays the given value. |
62 */ | 78 */ |
63 var createStateTableCell = function(value) { | 79 var createStateTableCell = function(value) { |
64 var cell = document.createElement('td'); | 80 var cell = document.createElement('td'); |
65 cell.textContent = value || ''; | 81 cell.textContent = value || ''; |
66 return cell; | 82 return cell; |
67 }; | 83 }; |
68 | 84 |
69 /** | 85 /** |
70 * Create a row in the network state table. | 86 * Create a row in the network state table. |
71 * | 87 * |
72 * @param {Array} stateFields The state fields to use for the row. | 88 * @param {Array} stateFields The state fields to use for the row. |
73 * @param {Object} state Property values for the network or favorite. | 89 * @param {Object} state Property values for the network or favorite. |
74 * @return {DOMElement} The created tr element that contains the network | 90 * @return {DOMElement} The created tr element that contains the network |
75 * state information. | 91 * state information. |
76 */ | 92 */ |
77 var createStateTableRow = function(stateFields, state) { | 93 var createStateTableRow = function(stateFields, state) { |
78 var row = document.createElement('tr'); | 94 var row = document.createElement('tr'); |
79 row.className = 'state-table-row'; | 95 row.className = 'state-table-row'; |
80 var guid = state.GUID; | 96 var guid = state.GUID; |
81 row.appendChild(createStateTableExpandButton(guid)); | 97 row.appendChild(createStateTableExpandButton(guid)); |
98 row.appendChild(createStateTableIcon(state)); | |
82 for (var i = 0; i < stateFields.length; ++i) { | 99 for (var i = 0; i < stateFields.length; ++i) { |
83 var field = stateFields[i]; | 100 var field = stateFields[i]; |
84 var value = ''; | 101 var value = ''; |
85 if (typeof field == 'string') { | 102 if (typeof field == 'string') { |
86 value = networkConfig.getValueFromProperties(state, field); | 103 value = networkConfig.getValueFromProperties(state, field); |
87 } else { | 104 } else { |
88 for (var j = 0; j < field.length; ++j) { | 105 for (var j = 0; j < field.length; ++j) { |
89 value = networkConfig.getValueFromProperties(state, field[j]); | 106 value = networkConfig.getValueFromProperties(state, field[j]); |
90 if (value) | 107 if (value) |
91 break; | 108 break; |
(...skipping 23 matching lines...) Expand all Loading... | |
115 }); | 132 }); |
116 }; | 133 }; |
117 | 134 |
118 /** | 135 /** |
119 * This callback function is triggered when visible networks are received. | 136 * This callback function is triggered when visible networks are received. |
120 * | 137 * |
121 * @param {Array} data A list of network state information for each | 138 * @param {Array} data A list of network state information for each |
122 * visible network. | 139 * visible network. |
123 */ | 140 */ |
124 var onVisibleNetworksReceived = function(states) { | 141 var onVisibleNetworksReceived = function(states) { |
142 var defaultState; | |
143 if (states.length > 0) | |
michaelpg
2015/02/05 06:45:51
just "var defaultState = states[0]". if statement
stevenjb
2015/02/05 22:41:33
Discussed offline, both are fine, but the intent o
| |
144 defaultState = states[0]; | |
145 if (defaultState && defaultState['Type'] != 'VPN') { | |
146 $('default-network-text').textContent = | |
147 loadTimeData.getStringF('defaultNetworkText', | |
148 defaultState['Name'], | |
149 defaultState['ConnectionState']); | |
150 $('default-network-icon').setNetworkState(defaultState); | |
151 } else { | |
152 $('default-network-text').textContent = | |
153 loadTimeData.getString('noNetworkText'); | |
154 // Show the disconnected wifi icon if there are no networks. | |
155 $('default-network-icon').setNetworkType('WiFi'); | |
156 } | |
157 | |
125 createStateTable('network-state-table', NETWORK_STATE_FIELDS, states); | 158 createStateTable('network-state-table', NETWORK_STATE_FIELDS, states); |
126 }; | 159 }; |
127 | 160 |
128 /** | 161 /** |
129 * This callback function is triggered when favorite networks are received. | 162 * This callback function is triggered when favorite networks are received. |
130 * | 163 * |
131 * @param {Object} data A list of network state information for each | 164 * @param {Object} data A list of network state information for each |
132 * favorite network. | 165 * favorite network. |
133 */ | 166 */ |
134 var onFavoriteNetworksReceived = function(states) { | 167 var onFavoriteNetworksReceived = function(states) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 * Get network information from WebUI. | 247 * Get network information from WebUI. |
215 */ | 248 */ |
216 document.addEventListener('DOMContentLoaded', function() { | 249 document.addEventListener('DOMContentLoaded', function() { |
217 $('refresh').onclick = requestNetworks; | 250 $('refresh').onclick = requestNetworks; |
218 setRefresh(); | 251 setRefresh(); |
219 requestNetworks(); | 252 requestNetworks(); |
220 }); | 253 }); |
221 | 254 |
222 return {}; | 255 return {}; |
223 })(); | 256 })(); |
OLD | NEW |