OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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', function() { | 5 cr.define('options', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | 7 var ArrayDataModel = cr.ui.ArrayDataModel; |
8 | 8 |
9 /** | 9 /** |
10 * ManageProfileOverlay class | 10 * ManageProfileOverlay class |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 $('delete-profile-ok').onclick = function(event) { | 64 $('delete-profile-ok').onclick = function(event) { |
65 OptionsPage.closeOverlay(); | 65 OptionsPage.closeOverlay(); |
66 chrome.send('deleteProfile', [self.profileInfo_.filePath]); | 66 chrome.send('deleteProfile', [self.profileInfo_.filePath]); |
67 }; | 67 }; |
68 }, | 68 }, |
69 | 69 |
70 /** @override */ | 70 /** @override */ |
71 didShowPage: function() { | 71 didShowPage: function() { |
72 chrome.send('requestDefaultProfileIcons'); | 72 chrome.send('requestDefaultProfileIcons'); |
73 | 73 |
74 if ($('manage-shortcut')) | |
75 $('manage-shortcut').checked = false; | |
76 | |
77 // Just ignore the manage profile dialog on Chrome OS, they use /accounts. | 74 // Just ignore the manage profile dialog on Chrome OS, they use /accounts. |
78 if (!cr.isChromeOS && window.location.pathname == '/manageProfile') | 75 if (!cr.isChromeOS && window.location.pathname == '/manageProfile') |
79 ManageProfileOverlay.getInstance().prepareForManageDialog_(); | 76 ManageProfileOverlay.getInstance().prepareForManageDialog_(); |
80 | 77 |
| 78 // When editing a profile, initially hide both the "create shortcut" and |
| 79 // "remove shortcut" boxes and ask the handler which to show. It will call |
| 80 // |receiveHasProfileShortcuts|, which will show the appropriate one. |
| 81 $('manage-shortcut-container').hidden = true; |
| 82 $('remove-shortcut-container').hidden = true; |
| 83 $('manage-shortcut').checked = false; |
| 84 $('remove-shortcut').checked = false; |
| 85 if (loadTimeData.getBoolean('profileShortcutsEnabled')) { |
| 86 var profileInfo = ManageProfileOverlay.getInstance().profileInfo_; |
| 87 chrome.send('requestHasProfileShortcuts', [profileInfo.filePath]); |
| 88 } |
| 89 |
81 $('manage-profile-name').focus(); | 90 $('manage-profile-name').focus(); |
82 }, | 91 }, |
83 | 92 |
84 /** | 93 /** |
85 * Registers event handlers that are common between create and manage modes. | 94 * Registers event handlers that are common between create and manage modes. |
86 * @param {String} mode A label that specifies the type of dialog | 95 * @param {String} mode A label that specifies the type of dialog |
87 * box which is currently being viewed (i.e. 'create' or | 96 * box which is currently being viewed (i.e. 'create' or |
88 * 'manage'). | 97 * 'manage'). |
89 * @param {function()} submitFunction The function that should be called | 98 * @param {function()} submitFunction The function that should be called |
90 * when the user chooses to submit (e.g. by clicking the OK button). | 99 * when the user chooses to submit (e.g. by clicking the OK button). |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 * Set a dictionary of all profile names. These are used to prevent the | 194 * Set a dictionary of all profile names. These are used to prevent the |
186 * user from naming two profiles the same. | 195 * user from naming two profiles the same. |
187 * @param {Object} profileNames A dictionary of profile names. | 196 * @param {Object} profileNames A dictionary of profile names. |
188 * @private | 197 * @private |
189 */ | 198 */ |
190 receiveProfileNames_: function(profileNames) { | 199 receiveProfileNames_: function(profileNames) { |
191 this.profileNames_ = profileNames; | 200 this.profileNames_ = profileNames; |
192 }, | 201 }, |
193 | 202 |
194 /** | 203 /** |
| 204 * Callback to show the create shortcut checkbox when in edit mode, called |
| 205 * by the handler as a result of the 'requestHasProfileShortcuts_' message. |
| 206 * @param {boolean} hasShortcuts Whether profile has any existing shortcuts. |
| 207 * @private |
| 208 */ |
| 209 receiveHasProfileShortcuts_: function(hasShortcuts) { |
| 210 var mode = hasShortcuts ? 'remove' : 'manage'; |
| 211 $(mode + '-shortcut-container').hidden = false; |
| 212 }, |
| 213 |
| 214 /** |
195 * Display the error bubble, with |errorText| in the bubble. | 215 * Display the error bubble, with |errorText| in the bubble. |
196 * @param {string} errorText The localized string id to display as an error. | 216 * @param {string} errorText The localized string id to display as an error. |
197 * @param {string} mode A label that specifies the type of dialog | 217 * @param {string} mode A label that specifies the type of dialog |
198 * box which is currently being viewed (i.e. 'create' or | 218 * box which is currently being viewed (i.e. 'create' or |
199 * 'manage'). | 219 * 'manage'). |
200 * @private | 220 * @private |
201 */ | 221 */ |
202 showErrorBubble_: function(errorText, mode) { | 222 showErrorBubble_: function(errorText, mode) { |
203 var nameErrorEl = $(mode + '-profile-error-bubble'); | 223 var nameErrorEl = $(mode + '-profile-error-bubble'); |
204 nameErrorEl.hidden = false; | 224 nameErrorEl.hidden = false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 }, | 264 }, |
245 | 265 |
246 /** | 266 /** |
247 * Called when the user clicks "OK" or hits enter. Saves the newly changed | 267 * Called when the user clicks "OK" or hits enter. Saves the newly changed |
248 * profile info. | 268 * profile info. |
249 * @private | 269 * @private |
250 */ | 270 */ |
251 submitManageChanges_: function() { | 271 submitManageChanges_: function() { |
252 var name = $('manage-profile-name').value; | 272 var name = $('manage-profile-name').value; |
253 var iconURL = $('manage-profile-icon-grid').selectedItem; | 273 var iconURL = $('manage-profile-icon-grid').selectedItem; |
254 var manage_checkbox = false; | 274 var shortcutAction = ''; |
255 if ($('manage-shortcut')) | 275 if ($('manage-shortcut').checked) |
256 manage_checkbox = $('manage-shortcut').checked; | 276 shortcutAction = 'create'; |
| 277 else if ($('remove-shortcut').checked) |
| 278 shortcutAction = 'remove'; |
| 279 |
257 chrome.send('setProfileNameAndIcon', | 280 chrome.send('setProfileNameAndIcon', |
258 [this.profileInfo_.filePath, name, iconURL, | 281 [this.profileInfo_.filePath, name, iconURL, shortcutAction]); |
259 manage_checkbox]); | |
260 }, | 282 }, |
261 | 283 |
262 /** | 284 /** |
263 * Called when the user clicks "OK" or hits enter. Creates the profile | 285 * Called when the user clicks "OK" or hits enter. Creates the profile |
264 * using the information in the dialog. | 286 * using the information in the dialog. |
265 * @private | 287 * @private |
266 */ | 288 */ |
267 submitCreateProfile_: function() { | 289 submitCreateProfile_: function() { |
268 // Get the user's chosen name and icon, or default if they do not | 290 // Get the user's chosen name and icon, or default if they do not |
269 // wish to customize their profile. | 291 // wish to customize their profile. |
270 var name = $('create-profile-name').value; | 292 var name = $('create-profile-name').value; |
271 var icon_url = $('create-profile-icon-grid').selectedItem; | 293 var iconUrl = $('create-profile-icon-grid').selectedItem; |
272 var create_shortcut = false; | 294 var createShortcut = $('create-shortcut').checked; |
273 if ($('create-shortcut')) | 295 var isManaged = $('create-profile-managed').checked; |
274 create_checkbox = $('create-shortcut').checked; | |
275 var is_managed = $('create-profile-managed').checked; | |
276 chrome.send('createProfile', | 296 chrome.send('createProfile', |
277 [name, icon_url, create_shortcut, is_managed]); | 297 [name, iconUrl, createShortcut, isManaged]); |
278 }, | 298 }, |
279 | 299 |
280 /** | 300 /** |
281 * Called when the selected icon in the icon grid changes. | 301 * Called when the selected icon in the icon grid changes. |
282 * @param {string} mode A label that specifies the type of dialog | 302 * @param {string} mode A label that specifies the type of dialog |
283 * box which is currently being viewed (i.e. 'create' or | 303 * box which is currently being viewed (i.e. 'create' or |
284 * 'manage'). | 304 * 'manage'). |
285 * @private | 305 * @private |
286 */ | 306 */ |
287 onIconGridSelectionChanged_: function(mode) { | 307 onIconGridSelectionChanged_: function(mode) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 showCreateDialog_: function() { | 365 showCreateDialog_: function() { |
346 OptionsPage.navigateToPage('createProfile'); | 366 OptionsPage.navigateToPage('createProfile'); |
347 }, | 367 }, |
348 }; | 368 }; |
349 | 369 |
350 // Forward public APIs to private implementations. | 370 // Forward public APIs to private implementations. |
351 [ | 371 [ |
352 'receiveDefaultProfileIcons', | 372 'receiveDefaultProfileIcons', |
353 'receiveNewProfileDefaults', | 373 'receiveNewProfileDefaults', |
354 'receiveProfileNames', | 374 'receiveProfileNames', |
| 375 'receiveHasProfileShortcuts', |
355 'setProfileInfo', | 376 'setProfileInfo', |
356 'setProfileName', | 377 'setProfileName', |
357 'showManageDialog', | 378 'showManageDialog', |
358 'showDeleteDialog', | 379 'showDeleteDialog', |
359 'showCreateDialog', | 380 'showCreateDialog', |
360 ].forEach(function(name) { | 381 ].forEach(function(name) { |
361 ManageProfileOverlay[name] = function() { | 382 ManageProfileOverlay[name] = function() { |
362 var instance = ManageProfileOverlay.getInstance(); | 383 var instance = ManageProfileOverlay.getInstance(); |
363 return instance[name + '_'].apply(instance, arguments); | 384 return instance[name + '_'].apply(instance, arguments); |
364 }; | 385 }; |
(...skipping 19 matching lines...) Expand all Loading... |
384 chrome.send('requestDefaultProfileIcons'); | 405 chrome.send('requestDefaultProfileIcons'); |
385 chrome.send('requestNewProfileDefaults'); | 406 chrome.send('requestNewProfileDefaults'); |
386 | 407 |
387 $('manage-profile-overlay-create').hidden = false; | 408 $('manage-profile-overlay-create').hidden = false; |
388 $('manage-profile-overlay-manage').hidden = true; | 409 $('manage-profile-overlay-manage').hidden = true; |
389 $('manage-profile-overlay-delete').hidden = true; | 410 $('manage-profile-overlay-delete').hidden = true; |
390 $('create-profile-instructions').textContent = | 411 $('create-profile-instructions').textContent = |
391 loadTimeData.getStringF('createProfileInstructions'); | 412 loadTimeData.getStringF('createProfileInstructions'); |
392 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); | 413 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); |
393 | 414 |
394 if ($('create-shortcut')) | 415 var shortcutsEnabled = loadTimeData.getBoolean('profileShortcutsEnabled'); |
395 $('create-shortcut').checked = true; | 416 $('create-shortcut-container').hidden = !shortcutsEnabled; |
| 417 $('create-shortcut').checked = shortcutsEnabled; |
| 418 |
396 $('create-profile-name-label').hidden = true; | 419 $('create-profile-name-label').hidden = true; |
397 $('create-profile-name').hidden = true; | 420 $('create-profile-name').hidden = true; |
398 $('create-profile-ok').disabled = true; | 421 $('create-profile-ok').disabled = true; |
399 }, | 422 }, |
400 }; | 423 }; |
401 | 424 |
402 // Export | 425 // Export |
403 return { | 426 return { |
404 ManageProfileOverlay: ManageProfileOverlay, | 427 ManageProfileOverlay: ManageProfileOverlay, |
405 CreateProfileOverlay: CreateProfileOverlay, | 428 CreateProfileOverlay: CreateProfileOverlay, |
406 }; | 429 }; |
407 }); | 430 }); |
OLD | NEW |