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

Side by Side Diff: chrome/browser/resources/options/chromeos/internet_detail.js

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 cr.define('options.internet', function() {
6 var OptionsPage = options.OptionsPage;
7
8 /*
9 * Helper function to set hidden attribute on given element list.
10 * @param {Array} elements List of elements to be updated.
11 * @param {bool} hidden New hidden value.
12 */
13 function updateHidden(elements, hidden) {
14 for (var i = 0, el; el = elements[i]; i++) {
15 el.hidden = hidden;
16 }
17 }
18
19 /////////////////////////////////////////////////////////////////////////////
20 // DetailsInternetPage class:
21
22 /**
23 * Encapsulated handling of ChromeOS internet details overlay page.
24 * @constructor
25 */
26 function DetailsInternetPage() {
27 OptionsPage.call(this, 'detailsInternetPage', null, 'detailsInternetPage');
28 }
29
30 cr.addSingletonGetter(DetailsInternetPage);
31
32 DetailsInternetPage.prototype = {
33 __proto__: OptionsPage.prototype,
34
35 /**
36 * Initializes DetailsInternetPage page.
37 * Calls base class implementation to starts preference initialization.
38 */
39 initializePage: function() {
40 OptionsPage.prototype.initializePage.call(this);
41 },
42
43 /**
44 * Initializes the controlled setting indicators for the page.
45 * @param {Object} data Dictionary with metadata about the settings.
46 */
47 initializeControlledSettingIndicators: function(data) {
48 indicators =
49 this.pageDiv.querySelectorAll('.controlled-setting-indicator');
50 for (var i = 0; i < indicators.length; i++) {
51 var dataProperty = indicators[i].getAttribute('data');
52 if (dataProperty && data[dataProperty]) {
53 this.initializeIndicator_(indicators[i],
54 data[dataProperty].controlledBy,
55 data[dataProperty].default);
56 }
57 }
58 },
59
60 /**
61 * Sets up a single controlled setting indicator, setting the controlledBy
62 * property and an event handler for resetting to the default value if
63 * appropriate.
64 * @param {Object} indicator The indicator element.
65 * @param {string} controlledBy The entity that controls the setting.
66 * @param {Object} defaultValue The default value to reset to, if
67 * applicable.
68 */
69 initializeIndicator_ : function(indicator, controlledBy, defaultValue) {
70 var forElement = $(indicator.getAttribute('for'));
71 var recommended = controlledBy == 'recommended';
72 if (!controlledBy || (recommended && !defaultValue))
73 controlledBy = null;
74
75 indicator.controlledBy = controlledBy;
76
77 if (forElement) {
78 forElement.disabled = (controlledBy != null) && !recommended;
79
80 // Special handling for radio buttons:
81 // - If the setting is recommended, show the recommended indicator
82 // next to the choice that is recommended.
83 // - Else, show the indicator next to the selected choice.
84 if (forElement.type == 'radio') {
85 if (recommended)
86 indicator.hidden = (defaultValue != forElement.value);
87 else
88 indicator.hidden = !forElement.checked;
89 }
90
91 indicator.setAttribute('allow-reset');
92 indicator.addEventListener(
93 'reset',
94 function(element, e) {
95 if (forElement.type == 'radio' || forElement.type == 'checkbox') {
96 // The recommended setting indicator is always shown next to
97 // the recommended choice.
98 forElement.checked = true;
99 } else {
100 forElement.value = defaultValue;
101 }
102 e.preventDefault();
103 });
104 }
105 },
106
107 /**
108 * Update details page controls.
109 * @private
110 */
111 updateControls_: function() {
112 // Only show ipconfig section if network is connected OR if nothing on
113 // this device is connected. This is so that you can fix the ip configs
114 // if you can't connect to any network.
115 // TODO(chocobo): Once ipconfig is moved to flimflam service objects,
116 // we need to redo this logic to allow configuration of all networks.
117 $('ipconfigSection').hidden = !this.connected && this.deviceConnected;
118
119 // Network type related.
120 updateHidden(
121 cr.doc.querySelectorAll('#detailsInternetPage .cellular-details'),
122 !this.cellular);
123 updateHidden(
124 cr.doc.querySelectorAll('#detailsInternetPage .wifi-details'),
125 !this.wireless);
126 updateHidden(
127 cr.doc.querySelectorAll('#detailsInternetPage .vpn-details'),
128 !this.vpn);
129
130 // Cell plan related.
131 $('planList').hidden = this.cellplanloading;
132 updateHidden(
133 cr.doc.querySelectorAll('#detailsInternetPage .no-plan-info'),
134 !this.cellular || this.cellplanloading || this.hascellplan);
135 updateHidden(
136 cr.doc.querySelectorAll('#detailsInternetPage .plan-loading-info'),
137 !this.cellular || this.nocellplan || this.hascellplan);
138 updateHidden(
139 cr.doc.querySelectorAll('#detailsInternetPage .plan-details-info'),
140 !this.cellular || this.nocellplan || this.cellplanloading);
141 updateHidden(
142 cr.doc.querySelectorAll('#detailsInternetPage .gsm-only'),
143 !this.cellular || !this.gsm);
144 updateHidden(
145 cr.doc.querySelectorAll('#detailsInternetPage .cdma-only'),
146 !this.cellular || this.gsm);
147 updateHidden(
148 cr.doc.querySelectorAll('#detailsInternetPage .apn-list-view'),
149 !this.cellular || !this.gsm);
150 updateHidden(
151 cr.doc.querySelectorAll('#detailsInternetPage .apn-details-view'),
152 true);
153
154 // Password and shared.
155 updateHidden(
156 cr.doc.querySelectorAll('#detailsInternetPage .password-details'),
157 !this.wireless || !this.password);
158 updateHidden(
159 cr.doc.querySelectorAll('#detailsInternetPage .shared-network'),
160 !this.shared);
161 updateHidden(
162 cr.doc.querySelectorAll('#detailsInternetPage .prefer-network'),
163 !this.showPreferred);
164 }
165 };
166
167 /**
168 * Whether the underlying network is connected. Only used for display purpose.
169 * @type {boolean}
170 */
171 cr.defineProperty(DetailsInternetPage, 'connected',
172 cr.PropertyKind.JS,
173 DetailsInternetPage.prototype.updateControls_);
174
175 /**
176 * Whether the underlying network is wifi. Only used for display purpose.
177 * @type {boolean}
178 */
179 cr.defineProperty(DetailsInternetPage, 'wireless',
180 cr.PropertyKind.JS,
181 DetailsInternetPage.prototype.updateControls_);
182
183 /**
184 * Whether the underlying network shared wifi. Only used for display purpose.
185 * @type {boolean}
186 */
187 cr.defineProperty(DetailsInternetPage, 'shared',
188 cr.PropertyKind.JS,
189 DetailsInternetPage.prototype.updateControls_);
190
191 /**
192 * Whether the underlying network is a vpn. Only used for display purpose.
193 * @type {boolean}
194 */
195 cr.defineProperty(DetailsInternetPage, 'vpn',
196 cr.PropertyKind.JS,
197 DetailsInternetPage.prototype.updateControls_);
198
199 /**
200 * Whether the underlying network is ethernet. Only used for display purpose.
201 * @type {boolean}
202 */
203 cr.defineProperty(DetailsInternetPage, 'ethernet',
204 cr.PropertyKind.JS,
205 DetailsInternetPage.prototype.updateControls_);
206
207 /**
208 * Whether the underlying network is cellular. Only used for display purpose.
209 * @type {boolean}
210 */
211 cr.defineProperty(DetailsInternetPage, 'cellular',
212 cr.PropertyKind.JS,
213 DetailsInternetPage.prototype.updateControls_);
214
215 /**
216 * Whether the network is loading cell plan. Only used for display purpose.
217 * @type {boolean}
218 */
219 cr.defineProperty(DetailsInternetPage, 'cellplanloading',
220 cr.PropertyKind.JS,
221 DetailsInternetPage.prototype.updateControls_);
222
223 /**
224 * Whether the network has cell plan(s). Only used for display purpose.
225 * @type {boolean}
226 */
227 cr.defineProperty(DetailsInternetPage, 'hascellplan',
228 cr.PropertyKind.JS,
229 DetailsInternetPage.prototype.updateControls_);
230
231 /**
232 * Whether the network has no cell plan. Only used for display purpose.
233 * @type {boolean}
234 */
235 cr.defineProperty(DetailsInternetPage, 'nocellplan',
236 cr.PropertyKind.JS,
237 DetailsInternetPage.prototype.updateControls_);
238
239 /**
240 * Whether the network is gsm. Only used for display purpose.
241 * @type {boolean}
242 */
243 cr.defineProperty(DetailsInternetPage, 'gsm',
244 cr.PropertyKind.JS,
245 DetailsInternetPage.prototype.updateControls_);
246
247 /**
248 * Whether show password details for network. Only used for display purpose.
249 * @type {boolean}
250 */
251 cr.defineProperty(DetailsInternetPage, 'password',
252 cr.PropertyKind.JS,
253 DetailsInternetPage.prototype.updateControls_);
254
255 // TODO(xiyuan): Check to see if it is safe to remove these attributes.
256 cr.defineProperty(DetailsInternetPage, 'hasactiveplan',
257 cr.PropertyKind.JS);
258 cr.defineProperty(DetailsInternetPage, 'activated',
259 cr.PropertyKind.JS);
260 cr.defineProperty(DetailsInternetPage, 'connecting',
261 cr.PropertyKind.JS);
262 cr.defineProperty(DetailsInternetPage, 'connected',
263 cr.PropertyKind.JS);
264
265 return {
266 DetailsInternetPage: DetailsInternetPage
267 };
268 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698