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

Side by Side Diff: chrome/browser/resources/options/chromeos/proxy_options.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) 2011 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', function() {
6
7 var OptionsPage = options.OptionsPage;
8 var Preferences = options.Preferences;
9
10 /////////////////////////////////////////////////////////////////////////////
11 // ProxyOptions class:
12
13 /**
14 * Encapsulated handling of ChromeOS proxy options page.
15 * @constructor
16 */
17 function ProxyOptions(model) {
18 OptionsPage.call(this, 'proxy', localStrings.getString('proxyPage'),
19 'proxyPage');
20 }
21
22 cr.addSingletonGetter(ProxyOptions);
23
24 /**
25 * UI pref change handler.
26 */
27 function handlePrefUpdate(e) {
28 ProxyOptions.getInstance().updateControls();
29 }
30
31 /**
32 * Monitor pref change of given element.
33 */
34 function observePrefsUI(el) {
35 Preferences.getInstance().addEventListener(el.pref, handlePrefUpdate);
36 }
37
38 ProxyOptions.prototype = {
39 // Inherit ProxyOptions from OptionsPage.
40 __proto__: OptionsPage.prototype,
41
42 /**
43 * Initializes ProxyOptions page.
44 */
45 initializePage: function() {
46 // Call base class implementation to start preference initialization.
47 OptionsPage.prototype.initializePage.call(this);
48
49 // Set up ignored page.
50 options.proxyexceptions.ProxyExceptions.decorate($('ignoredHostList'));
51
52 this.addEventListener('visibleChange', this.handleVisibleChange_);
53 $('removeHost').addEventListener('click', this.handleRemoveExceptions_);
54 $('addHost').addEventListener('click', this.handleAddException_);
55 $('directProxy').addEventListener('click', this.disableManual_);
56 $('manualProxy').addEventListener('click', this.enableManual_);
57 $('autoProxy').addEventListener('click', this.disableManual_);
58 $('proxyAllProtocols').addEventListener('click', this.toggleSingle_);
59
60 observePrefsUI($('directProxy'));
61 observePrefsUI($('manualProxy'));
62 observePrefsUI($('autoProxy'));
63 observePrefsUI($('proxyAllProtocols'));
64 },
65
66 proxyListInitialized_: false,
67
68 /**
69 * Update controls state.
70 * @public
71 */
72 updateControls: function() {
73 this.updateBannerVisibility_();
74 this.toggleSingle_();
75 if ($('manualProxy').checked) {
76 this.enableManual_();
77 } else {
78 this.disableManual_();
79 }
80 if (!this.proxyListInitialized_ && this.visible) {
81 this.proxyListInitialized_ = true;
82 $('ignoredHostList').redraw();
83 }
84 },
85
86 /**
87 * Handler for OptionsPage's visible property change event.
88 * @private
89 * @param {Event} e Property change event.
90 */
91 handleVisibleChange_: function(e) {
92 this.updateControls();
93 },
94
95 /**
96 * Updates info banner visibility state. This function shows the banner
97 * if proxy is managed or shared-proxies is off for shared network.
98 * @private
99 */
100 updateBannerVisibility_: function() {
101 var bannerDiv = $('info-banner');
102 // Remove class and listener for click event in case they were added
103 // before and updateBannerVisibility_ is called repeatedly.
104 bannerDiv.classList.remove("clickable");
105 bannerDiv.removeEventListener('click', this.handleSharedProxiesHint_);
106
107 // Show banner and determine its message if necessary.
108 var controlledBy = $('directProxy').controlledBy;
109 if (controlledBy == '') {
110 bannerDiv.hidden = true;
111 } else {
112 bannerDiv.hidden = false;
113 // controlledBy must match strings loaded in proxy_handler.cc and
114 // set in proxy_cros_settings_provider.cc.
115 $('banner-text').textContent = localStrings.getString(controlledBy);
116 if (controlledBy == "enableSharedProxiesBannerText") {
117 bannerDiv.classList.add("clickable");
118 bannerDiv.addEventListener('click', this.handleSharedProxiesHint_);
119 }
120 }
121 },
122
123 /**
124 * Handler for "click" event on yellow banner with enable-shared-proxies
125 * hint.
126 * @private
127 * @param {Event} e Click event fired from info-banner.
128 */
129 handleSharedProxiesHint_: function(e) {
130 OptionsPage.navigateToPage("internet");
131 },
132
133 /**
134 * Handler for when the user clicks on the checkbox to allow a
135 * single proxy usage.
136 * @private
137 * @param {Event} e Click Event.
138 */
139 toggleSingle_: function(e) {
140 if ($('proxyAllProtocols').checked) {
141 $('multiProxy').style.display = 'none';
142 $('singleProxy').style.display = 'block';
143 } else {
144 $('multiProxy').style.display = 'block';
145 $('singleProxy').style.display = 'none';
146 }
147 },
148
149 /**
150 * Handler for selecting a radio button that will disable the manual
151 * controls.
152 * @private
153 * @param {Event} e Click event.
154 */
155 disableManual_: function(e) {
156 $('advancedConfig').hidden = true;
157 $('proxyAllProtocols').disabled = true;
158 $('proxyHostName').disabled = true;
159 $('proxyHostPort').disabled = true;
160 $('proxyHostSingleName').disabled = true;
161 $('proxyHostSinglePort').disabled = true;
162 $('secureProxyHostName').disabled = true;
163 $('secureProxyPort').disabled = true;
164 $('ftpProxy').disabled = true;
165 $('ftpProxyPort').disabled = true;
166 $('socksHost').disabled = true;
167 $('socksPort').disabled = true;
168 $('proxyConfig').disabled = $('autoProxy').disabled ||
169 !$('autoProxy').checked;
170 },
171
172 /**
173 * Handler for selecting a radio button that will enable the manual
174 * controls.
175 * @private
176 * @param {Event} e Click event.
177 */
178 enableManual_: function(e) {
179 $('advancedConfig').hidden = false;
180 $('ignoredHostList').redraw();
181 var all_disabled = $('manualProxy').disabled;
182 $('newHost').disabled = all_disabled;
183 $('removeHost').disabled = all_disabled;
184 $('addHost').disabled = all_disabled;
185 $('proxyAllProtocols').disabled = all_disabled;
186 $('proxyHostName').disabled = all_disabled;
187 $('proxyHostPort').disabled = all_disabled;
188 $('proxyHostSingleName').disabled = all_disabled;
189 $('proxyHostSinglePort').disabled = all_disabled;
190 $('secureProxyHostName').disabled = all_disabled;
191 $('secureProxyPort').disabled = all_disabled;
192 $('ftpProxy').disabled = all_disabled;
193 $('ftpProxyPort').disabled = all_disabled;
194 $('socksHost').disabled = all_disabled;
195 $('socksPort').disabled = all_disabled;
196 $('proxyConfig').disabled = true;
197 },
198
199 /**
200 * Handler for "add" event fired from userNameEdit.
201 * @private
202 * @param {Event} e Add event fired from userNameEdit.
203 */
204 handleAddException_: function(e) {
205 var exception = $('newHost').value;
206 $('newHost').value = '';
207
208 exception = exception.trim();
209 if (exception)
210 $('ignoredHostList').addException(exception);
211 },
212
213 /**
214 * Handler for when the remove button is clicked
215 * @private
216 */
217 handleRemoveExceptions_: function(e) {
218 var selectedItems = $('ignoredHostList').selectedItems;
219 for (var x = 0; x < selectedItems.length; x++) {
220 $('ignoredHostList').removeException(selectedItems[x]);
221 }
222 },
223
224 /**
225 * Sets proxy page title using given network name.
226 * @param {string} network The network name to use in page title.
227 * @public
228 */
229 setNetworkName: function(network) {
230 $('proxy-page-title').textContent =
231 localStrings.getStringF('proxyPageTitleFormat', network);
232 }
233 };
234
235 ProxyOptions.setNetworkName = function(network) {
236 ProxyOptions.getInstance().setNetworkName(network);
237 };
238
239 // Export
240 return {
241 ProxyOptions: ProxyOptions
242 };
243
244 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698