OLD | NEW |
| (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', function() { | |
6 var OptionsPage = options.OptionsPage; | |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | |
8 | |
9 /** | |
10 * Encapsulated handling of personal options page. | |
11 * @constructor | |
12 */ | |
13 function PersonalOptions() { | |
14 OptionsPage.call(this, 'personal', | |
15 templateData.personalPageTabTitle, | |
16 'personal-page'); | |
17 if (cr.isChromeOS) { | |
18 // Username (canonical email) of the currently logged in user or | |
19 // |kGuestUser| if a guest session is active. | |
20 this.username_ = localStrings.getString('username'); | |
21 } | |
22 } | |
23 | |
24 cr.addSingletonGetter(PersonalOptions); | |
25 | |
26 PersonalOptions.prototype = { | |
27 // Inherit PersonalOptions from OptionsPage. | |
28 __proto__: options.OptionsPage.prototype, | |
29 | |
30 // Initialize PersonalOptions page. | |
31 initializePage: function() { | |
32 // Call base class implementation to start preference initialization. | |
33 OptionsPage.prototype.initializePage.call(this); | |
34 | |
35 var self = this; | |
36 | |
37 // Profiles. | |
38 var profilesList = $('profiles-list'); | |
39 options.personal_options.ProfileList.decorate(profilesList); | |
40 profilesList.autoExpands = true; | |
41 | |
42 profilesList.onchange = self.setProfileViewButtonsStatus_; | |
43 $('profiles-create').onclick = function(event) { | |
44 chrome.send('createProfile'); | |
45 }; | |
46 $('profiles-manage').onclick = function(event) { | |
47 var selectedProfile = self.getSelectedProfileItem_(); | |
48 if (selectedProfile) | |
49 ManageProfileOverlay.showManageDialog(selectedProfile); | |
50 }; | |
51 $('profiles-delete').onclick = function(event) { | |
52 var selectedProfile = self.getSelectedProfileItem_(); | |
53 if (selectedProfile) | |
54 ManageProfileOverlay.showDeleteDialog(selectedProfile); | |
55 }; | |
56 | |
57 // Appearance. | |
58 $('themes-reset').onclick = function(event) { | |
59 chrome.send('themesReset'); | |
60 }; | |
61 | |
62 if (!cr.isChromeOS) { | |
63 $('import-data').onclick = function(event) { | |
64 // Make sure that any previous import success message is hidden, and | |
65 // we're showing the UI to import further data. | |
66 $('import-data-configure').hidden = false; | |
67 $('import-data-success').hidden = true; | |
68 OptionsPage.navigateToPage('importData'); | |
69 chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']); | |
70 }; | |
71 | |
72 if ($('themes-GTK-button')) { | |
73 $('themes-GTK-button').onclick = function(event) { | |
74 chrome.send('themesSetGTK'); | |
75 }; | |
76 } | |
77 } else { | |
78 $('change-picture-button').onclick = function(event) { | |
79 OptionsPage.navigateToPage('changePicture'); | |
80 }; | |
81 this.updateAccountPicture_(); | |
82 | |
83 if (cr.commandLine && cr.commandLine.options['--bwsi']) { | |
84 // Disable the screen lock checkbox and change-picture-button in | |
85 // guest mode. | |
86 $('enable-screen-lock').disabled = true; | |
87 $('change-picture-button').disabled = true; | |
88 } | |
89 } | |
90 }, | |
91 | |
92 /** | |
93 * Get the selected profile item from the profile list. This also works | |
94 * correctly if the list is not displayed. | |
95 * @return {Object} the profile item object, or null if nothing is selected. | |
96 * @private | |
97 */ | |
98 getSelectedProfileItem_: function() { | |
99 var profilesList = $('profiles-list'); | |
100 if (profilesList.hidden) { | |
101 if (profilesList.dataModel.length > 0) | |
102 return profilesList.dataModel.item(0); | |
103 } else { | |
104 return profilesList.selectedItem; | |
105 } | |
106 return null; | |
107 }, | |
108 | |
109 /** | |
110 * Helper function to set the status of profile view buttons to disabled or | |
111 * enabled, depending on the number of profiles and selection status of the | |
112 * profiles list. | |
113 */ | |
114 setProfileViewButtonsStatus_: function() { | |
115 var profilesList = $('profiles-list'); | |
116 var selectedProfile = profilesList.selectedItem; | |
117 var hasSelection = selectedProfile != null; | |
118 var hasSingleProfile = profilesList.dataModel.length == 1; | |
119 $('profiles-manage').disabled = !hasSelection || | |
120 !selectedProfile.isCurrentProfile; | |
121 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; | |
122 }, | |
123 | |
124 /** | |
125 * Display the correct dialog layout, depending on how many profiles are | |
126 * available. | |
127 * @param {number} numProfiles The number of profiles to display. | |
128 */ | |
129 setProfileViewSingle_: function(numProfiles) { | |
130 var hasSingleProfile = numProfiles == 1; | |
131 $('profiles-list').hidden = hasSingleProfile; | |
132 $('profiles-single-message').hidden = !hasSingleProfile; | |
133 $('profiles-manage').hidden = hasSingleProfile; | |
134 $('profiles-delete').textContent = hasSingleProfile ? | |
135 templateData.profilesDeleteSingle : | |
136 templateData.profilesDelete; | |
137 }, | |
138 | |
139 /** | |
140 * Adds all |profiles| to the list. | |
141 * @param {Array.<Object>} An array of profile info objects. | |
142 * each object is of the form: | |
143 * profileInfo = { | |
144 * name: "Profile Name", | |
145 * iconURL: "chrome://path/to/icon/image", | |
146 * filePath: "/path/to/profile/data/on/disk", | |
147 * isCurrentProfile: false | |
148 * }; | |
149 */ | |
150 setProfilesInfo_: function(profiles) { | |
151 this.setProfileViewSingle_(profiles.length); | |
152 // add it to the list, even if the list is hidden so we can access it | |
153 // later. | |
154 $('profiles-list').dataModel = new ArrayDataModel(profiles); | |
155 this.setProfileViewButtonsStatus_(); | |
156 }, | |
157 | |
158 setGtkThemeButtonEnabled_: function(enabled) { | |
159 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { | |
160 $('themes-GTK-button').disabled = !enabled; | |
161 } | |
162 }, | |
163 | |
164 setThemesResetButtonEnabled_: function(enabled) { | |
165 $('themes-reset').disabled = !enabled; | |
166 }, | |
167 | |
168 /** | |
169 * (Re)loads IMG element with current user account picture. | |
170 */ | |
171 updateAccountPicture_: function() { | |
172 $('account-picture').src = | |
173 'chrome://userimage/' + this.username_ + | |
174 '?id=' + (new Date()).getTime(); | |
175 }, | |
176 }; | |
177 | |
178 if (cr.isChromeOS) { | |
179 /** | |
180 * Returns username (canonical email) of the user logged in (ChromeOS only). | |
181 * @return {string} user email. | |
182 */ | |
183 PersonalOptions.getLoggedInUsername = function() { | |
184 return PersonalOptions.getInstance().username_; | |
185 }; | |
186 } | |
187 | |
188 // Forward public APIs to private implementations. | |
189 [ | |
190 'setGtkThemeButtonEnabled', | |
191 'setProfilesInfo', | |
192 'setProfilesSectionVisible', | |
193 'setThemesResetButtonEnabled', | |
194 'updateAccountPicture', | |
195 ].forEach(function(name) { | |
196 PersonalOptions[name] = function(value) { | |
197 return PersonalOptions.getInstance()[name + '_'](value); | |
198 }; | |
199 }); | |
200 | |
201 // Export | |
202 return { | |
203 PersonalOptions: PersonalOptions | |
204 }; | |
205 | |
206 }); | |
OLD | NEW |