OLD | NEW |
| (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 | |
9 // State variables. | |
10 var syncEnabled = false; | |
11 var syncSetupCompleted = false; | |
12 | |
13 /** | |
14 * Encapsulated handling of personal options page. | |
15 * @constructor | |
16 */ | |
17 function PersonalOptions() { | |
18 OptionsPage.call(this, 'personal', | |
19 templateData.personalPageTabTitle, | |
20 'personal-page'); | |
21 } | |
22 | |
23 cr.addSingletonGetter(PersonalOptions); | |
24 | |
25 PersonalOptions.prototype = { | |
26 // Inherit PersonalOptions from OptionsPage. | |
27 __proto__: options.OptionsPage.prototype, | |
28 | |
29 // Initialize PersonalOptions page. | |
30 initializePage: function() { | |
31 // Call base class implementation to start preference initialization. | |
32 OptionsPage.prototype.initializePage.call(this); | |
33 | |
34 var self = this; | |
35 $('sync-action-link').onclick = function(event) { | |
36 chrome.send('showSyncActionDialog'); | |
37 }; | |
38 $('start-stop-sync').onclick = function(event) { | |
39 if (self.syncSetupCompleted) | |
40 self.showStopSyncingOverlay_(); | |
41 else | |
42 chrome.send('showSyncLoginDialog'); | |
43 }; | |
44 $('customize-sync').onclick = function(event) { | |
45 chrome.send('showCustomizeSyncDialog'); | |
46 }; | |
47 $('privacy-dashboard-link').onclick = function(event) { | |
48 chrome.send('openPrivacyDashboardTabAndActivate'); | |
49 }; | |
50 $('manage-passwords').onclick = function(event) { | |
51 OptionsPage.navigateToPage('passwords'); | |
52 OptionsPage.showTab($('passwords-nav-tab')); | |
53 chrome.send('coreOptionsUserMetricsAction', | |
54 ['Options_ShowPasswordManager']); | |
55 }; | |
56 $('autofill-settings').onclick = function(event) { | |
57 OptionsPage.navigateToPage('autofill'); | |
58 chrome.send('coreOptionsUserMetricsAction', | |
59 ['Options_ShowAutofillSettings']); | |
60 }; | |
61 $('themes-reset').onclick = function(event) { | |
62 chrome.send('themesReset'); | |
63 }; | |
64 | |
65 if (!cr.isChromeOS) { | |
66 $('import-data').onclick = function(event) { | |
67 OptionsPage.navigateToPage('importData'); | |
68 chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']); | |
69 }; | |
70 | |
71 if ($('themes-GTK-button')) { | |
72 $('themes-GTK-button').onclick = function(event) { | |
73 chrome.send('themesSetGTK'); | |
74 }; | |
75 } | |
76 } else { | |
77 $('change-picture-button').onclick = function(event) { | |
78 OptionsPage.navigateToPage('changePicture'); | |
79 }; | |
80 chrome.send('loadAccountPicture'); | |
81 } | |
82 | |
83 if (cr.commandLine.options['--bwsi']) { | |
84 // Disable the screen lock checkbox for the guest mode. | |
85 $('enable-screen-lock').disabled = true; | |
86 } | |
87 | |
88 if (PersonalOptions.disablePasswordManagement()) { | |
89 $('passwords-offersave').disabled = true; | |
90 $('passwords-neversave').disabled = true; | |
91 $('passwords-offersave').value = false; | |
92 $('passwords-neversave').value = true; | |
93 $('manage-passwords').disabled = true; | |
94 } | |
95 }, | |
96 | |
97 showStopSyncingOverlay_: function() { | |
98 AlertOverlay.show(localStrings.getString('stop_syncing_title'), | |
99 localStrings.getString('stop_syncing_explanation'), | |
100 localStrings.getString('stop_syncing_confirm'), | |
101 localStrings.getString('cancel'), | |
102 function() { chrome.send('stopSyncing'); }); | |
103 }, | |
104 | |
105 setElementVisible_: function(element, visible) { | |
106 element.hidden = !visible; | |
107 if (visible) | |
108 element.classList.remove('hidden'); | |
109 else | |
110 element.classList.add('hidden'); | |
111 }, | |
112 | |
113 setSyncEnabled_: function(enabled) { | |
114 this.syncEnabled = enabled; | |
115 }, | |
116 | |
117 setSyncSetupCompleted_: function(completed) { | |
118 this.syncSetupCompleted = completed; | |
119 this.setElementVisible_($('customize-sync'), completed); | |
120 $('privacy-dashboard-link').hidden = !completed; | |
121 }, | |
122 | |
123 setAccountPicture_: function(image) { | |
124 $('account-picture').src = image; | |
125 }, | |
126 | |
127 setSyncStatus_: function(status) { | |
128 var statusSet = status != ''; | |
129 $('sync-overview').hidden = statusSet; | |
130 $('sync-status').hidden = !statusSet; | |
131 $('sync-status-text').textContent = status; | |
132 }, | |
133 | |
134 setSyncStatusErrorVisible_: function(visible) { | |
135 visible ? $('sync-status').classList.add('sync-error') : | |
136 $('sync-status').classList.remove('sync-error'); | |
137 }, | |
138 | |
139 setSyncActionLinkEnabled_: function(enabled) { | |
140 $('sync-action-link').disabled = !enabled; | |
141 }, | |
142 | |
143 setSyncActionLinkLabel_: function(status) { | |
144 $('sync-action-link').textContent = status; | |
145 | |
146 // link-button does is not zero-area when the contents of the button are | |
147 // empty, so explicitly hide the element. | |
148 this.setElementVisible_($('sync-action-link'), status.length != 0); | |
149 }, | |
150 | |
151 setProfilesSectionVisible_: function(visible) { | |
152 this.setElementVisible_($('profiles-create'), visible); | |
153 }, | |
154 | |
155 setNewProfileButtonEnabled_: function(enabled) { | |
156 $('new-profile').disabled = !enabled; | |
157 if (enabled) | |
158 $('profiles-create').classList.remove('disabled'); | |
159 else | |
160 $('profiles-create').classList.add('disabled'); | |
161 }, | |
162 | |
163 setStartStopButtonVisible_: function(visible) { | |
164 this.setElementVisible_($('start-stop-sync'), visible); | |
165 }, | |
166 | |
167 setStartStopButtonEnabled_: function(enabled) { | |
168 $('start-stop-sync').disabled = !enabled; | |
169 }, | |
170 | |
171 setStartStopButtonLabel_: function(label) { | |
172 $('start-stop-sync').textContent = label; | |
173 }, | |
174 | |
175 setGtkThemeButtonEnabled_: function(enabled) { | |
176 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { | |
177 $('themes-GTK-button').disabled = !enabled; | |
178 } | |
179 }, | |
180 | |
181 setThemesResetButtonEnabled_: function(enabled) { | |
182 $('themes-reset').disabled = !enabled; | |
183 }, | |
184 | |
185 hideSyncSection_: function() { | |
186 this.setElementVisible_($('sync-section'), false); | |
187 }, | |
188 | |
189 /** | |
190 * Toggles the visibility of the data type checkboxes based on whether they | |
191 * are enabled on not. | |
192 * @param {Object} dict A mapping from data type to a boolean indicating | |
193 * whether it is enabled. | |
194 * @private | |
195 */ | |
196 setRegisteredDataTypes_: function(dict) { | |
197 for (var type in dict) { | |
198 if (type.match(/Registered$/) && !dict[type]) { | |
199 node = $(type.replace(/([a-z]+)Registered$/i, '$1').toLowerCase() | |
200 + '-check'); | |
201 if (node) | |
202 node.parentNode.style.display = 'none'; | |
203 } | |
204 } | |
205 }, | |
206 }; | |
207 | |
208 /** | |
209 * Returns whether the user should be able to manage (view and edit) their | |
210 * stored passwords. Password management is disabled in guest mode. | |
211 * @return {boolean} True if password management should be disabled. | |
212 */ | |
213 PersonalOptions.disablePasswordManagement = function() { | |
214 return cr.commandLine.options['--bwsi']; | |
215 }; | |
216 | |
217 // Forward public APIs to private implementations. | |
218 [ | |
219 'setSyncEnabled', | |
220 'setSyncSetupCompleted', | |
221 'setAccountPicture', | |
222 'setSyncStatus', | |
223 'setSyncStatusErrorVisible', | |
224 'setSyncActionLinkEnabled', | |
225 'setSyncActionLinkLabel', | |
226 'setProfilesSectionVisible', | |
227 'setNewProfileButtonEnabled', | |
228 'setStartStopButtonVisible', | |
229 'setStartStopButtonEnabled', | |
230 'setStartStopButtonLabel', | |
231 'setGtkThemeButtonEnabled', | |
232 'setThemesResetButtonEnabled', | |
233 'hideSyncSection', | |
234 'setRegisteredDataTypes', | |
235 ].forEach(function(name) { | |
236 PersonalOptions[name] = function(value) { | |
237 PersonalOptions.getInstance()[name + '_'](value); | |
238 }; | |
239 }); | |
240 | |
241 // Export | |
242 return { | |
243 PersonalOptions: PersonalOptions | |
244 }; | |
245 | |
246 }); | |
OLD | NEW |