OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('options.internet', function() { | 5 cr.define('options.internet', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 | 7 |
8 /* | 8 /* |
9 * Helper function to set hidden attribute on given element list. | 9 * Helper function to set hidden attribute on given element list. |
10 * @param {Array} elements List of elements to be updated. | 10 * @param {Array} elements List of elements to be updated. |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 /** | 35 /** |
36 * Initializes DetailsInternetPage page. | 36 * Initializes DetailsInternetPage page. |
37 * Calls base class implementation to starts preference initialization. | 37 * Calls base class implementation to starts preference initialization. |
38 */ | 38 */ |
39 initializePage: function() { | 39 initializePage: function() { |
40 OptionsPage.prototype.initializePage.call(this); | 40 OptionsPage.prototype.initializePage.call(this); |
41 }, | 41 }, |
42 | 42 |
43 /** | 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 = !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 /** |
44 * Update details page controls. | 108 * Update details page controls. |
45 * @private | 109 * @private |
46 */ | 110 */ |
47 updateControls_: function() { | 111 updateControls_: function() { |
48 // Only show ipconfig section if network is connected OR if nothing on | 112 // Only show ipconfig section if network is connected OR if nothing on |
49 // this device is connected. This is so that you can fix the ip configs | 113 // this device is connected. This is so that you can fix the ip configs |
50 // if you can't connect to any network. | 114 // if you can't connect to any network. |
51 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, | 115 // TODO(chocobo): Once ipconfig is moved to flimflam service objects, |
52 // we need to redo this logic to allow configuration of all networks. | 116 // we need to redo this logic to allow configuration of all networks. |
53 $('ipconfigSection').hidden = !this.connected && this.deviceConnected; | 117 $('ipconfigSection').hidden = !this.connected && this.deviceConnected; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 cr.PropertyKind.JS); | 259 cr.PropertyKind.JS); |
196 cr.defineProperty(DetailsInternetPage, 'connecting', | 260 cr.defineProperty(DetailsInternetPage, 'connecting', |
197 cr.PropertyKind.JS); | 261 cr.PropertyKind.JS); |
198 cr.defineProperty(DetailsInternetPage, 'connected', | 262 cr.defineProperty(DetailsInternetPage, 'connected', |
199 cr.PropertyKind.JS); | 263 cr.PropertyKind.JS); |
200 | 264 |
201 return { | 265 return { |
202 DetailsInternetPage: DetailsInternetPage | 266 DetailsInternetPage: DetailsInternetPage |
203 }; | 267 }; |
204 }); | 268 }); |
OLD | NEW |