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 30 matching lines...) Expand all Loading... | |
41 OptionsPage.prototype.initializePage.call(this); | 41 OptionsPage.prototype.initializePage.call(this); |
42 | 42 |
43 var self = this; | 43 var self = this; |
44 options.ProfilesIconGrid.decorate($('manage-profile-icon-grid')); | 44 options.ProfilesIconGrid.decorate($('manage-profile-icon-grid')); |
45 options.ProfilesIconGrid.decorate($('create-profile-icon-grid')); | 45 options.ProfilesIconGrid.decorate($('create-profile-icon-grid')); |
46 self.registerCommonEventHandlers_('create', | 46 self.registerCommonEventHandlers_('create', |
47 self.submitCreateProfile_.bind(self)); | 47 self.submitCreateProfile_.bind(self)); |
48 self.registerCommonEventHandlers_('manage', | 48 self.registerCommonEventHandlers_('manage', |
49 self.submitManageChanges_.bind(self)); | 49 self.submitManageChanges_.bind(self)); |
50 | 50 |
51 // Override the create-profile-ok handler, to avoid closing the overlay | |
52 // until we finish creating the profile. | |
53 $('create-profile-ok').onclick = function(event) { | |
54 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); | |
55 $('create-profile-ok').disabled = true; | |
56 self.submitCreateProfile_(); | |
57 }; | |
58 | |
51 if (loadTimeData.getBoolean('managedUsersEnabled')) { | 59 if (loadTimeData.getBoolean('managedUsersEnabled')) { |
52 $('create-profile-limited-container').hidden = false; | 60 $('create-profile-limited-container').hidden = false; |
53 } | 61 } |
54 $('manage-profile-cancel').onclick = | 62 $('manage-profile-cancel').onclick = |
55 $('delete-profile-cancel').onclick = | 63 $('delete-profile-cancel').onclick = |
56 $('create-profile-cancel').onclick = function(event) { | 64 $('create-profile-cancel').onclick = function(event) { |
57 OptionsPage.closeOverlay(); | 65 OptionsPage.closeOverlay(); |
58 }; | 66 }; |
59 $('delete-profile-ok').onclick = function(event) { | 67 $('delete-profile-ok').onclick = function(event) { |
60 OptionsPage.closeOverlay(); | 68 OptionsPage.closeOverlay(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 $('add-shortcut-button').hidden = hasShortcuts; | 230 $('add-shortcut-button').hidden = hasShortcuts; |
223 $('remove-shortcut-button').hidden = !hasShortcuts; | 231 $('remove-shortcut-button').hidden = !hasShortcuts; |
224 }, | 232 }, |
225 | 233 |
226 /** | 234 /** |
227 * Display the error bubble, with |errorText| in the bubble. | 235 * Display the error bubble, with |errorText| in the bubble. |
228 * @param {string} errorText The localized string id to display as an error. | 236 * @param {string} errorText The localized string id to display as an error. |
229 * @param {string} mode A label that specifies the type of dialog | 237 * @param {string} mode A label that specifies the type of dialog |
230 * box which is currently being viewed (i.e. 'create' or | 238 * box which is currently being viewed (i.e. 'create' or |
231 * 'manage'). | 239 * 'manage'). |
240 * @param {boolean} disableOKButton True if the dialog's OK button should be | |
241 * disabled when the error bubble is shown. It will be re-enabled when | |
242 * the error bubble is hidden. | |
232 * @private | 243 * @private |
233 */ | 244 */ |
234 showErrorBubble_: function(errorText, mode) { | 245 showErrorBubble_: function(errorText, mode, disableOKButton) { |
235 var nameErrorEl = $(mode + '-profile-error-bubble'); | 246 var nameErrorEl = $(mode + '-profile-error-bubble'); |
236 nameErrorEl.hidden = false; | 247 nameErrorEl.hidden = false; |
237 nameErrorEl.textContent = loadTimeData.getString(errorText); | 248 nameErrorEl.textContent = loadTimeData.getString(errorText); |
238 | 249 |
239 $(mode + '-profile-ok').disabled = true; | 250 if (disableOKButton) |
251 $(mode + '-profile-ok').disabled = true; | |
240 }, | 252 }, |
241 | 253 |
242 /** | 254 /** |
243 * Hide the error bubble. | 255 * Hide the error bubble. |
244 * @param {string} mode A label that specifies the type of dialog | 256 * @param {string} mode A label that specifies the type of dialog |
245 * box which is currently being viewed (i.e. 'create' or | 257 * box which is currently being viewed (i.e. 'create' or |
246 * 'manage'). | 258 * 'manage'). |
247 * @private | 259 * @private |
248 */ | 260 */ |
249 hideErrorBubble_: function(mode) { | 261 hideErrorBubble_: function(mode) { |
250 $(mode + '-profile-error-bubble').hidden = true; | 262 $(mode + '-profile-error-bubble').hidden = true; |
251 $(mode + '-profile-ok').disabled = false; | 263 $(mode + '-profile-ok').disabled = false; |
252 }, | 264 }, |
253 | 265 |
254 /** | 266 /** |
255 * oninput callback for <input> field. | 267 * oninput callback for <input> field. |
256 * @param {Event} event The event object. | 268 * @param {Event} event The event object. |
257 * @param {string} mode A label that specifies the type of dialog | 269 * @param {string} mode A label that specifies the type of dialog |
258 * box which is currently being viewed (i.e. 'create' or | 270 * box which is currently being viewed (i.e. 'create' or |
259 * 'manage'). | 271 * 'manage'). |
260 * @private | 272 * @private |
261 */ | 273 */ |
262 onNameChanged_: function(event, mode) { | 274 onNameChanged_: function(event, mode) { |
263 var newName = event.target.value; | 275 var newName = event.target.value; |
264 var oldName = this.profileInfo_.name; | 276 var oldName = this.profileInfo_.name; |
265 | 277 |
266 if (newName == oldName) { | 278 if (newName == oldName) { |
267 this.hideErrorBubble_(mode); | 279 this.hideErrorBubble_(mode); |
268 } else if (this.profileNames_[newName] != undefined) { | 280 } else if (this.profileNames_[newName] != undefined) { |
269 this.showErrorBubble_('manageProfilesDuplicateNameError', mode); | 281 this.showErrorBubble_('manageProfilesDuplicateNameError', mode, true); |
270 } else { | 282 } else { |
271 this.hideErrorBubble_(mode); | 283 this.hideErrorBubble_(mode); |
272 | 284 |
273 var nameIsValid = $(mode + '-profile-name').validity.valid; | 285 var nameIsValid = $(mode + '-profile-name').validity.valid; |
274 $(mode + '-profile-ok').disabled = !nameIsValid; | 286 $(mode + '-profile-ok').disabled = !nameIsValid; |
275 } | 287 } |
276 }, | 288 }, |
277 | 289 |
278 /** | 290 /** |
279 * Called when the user clicks "OK" or hits enter. Saves the newly changed | 291 * Called when the user clicks "OK" or hits enter. Saves the newly changed |
(...skipping 13 matching lines...) Expand all Loading... | |
293 * using the information in the dialog. | 305 * using the information in the dialog. |
294 * @private | 306 * @private |
295 */ | 307 */ |
296 submitCreateProfile_: function() { | 308 submitCreateProfile_: function() { |
297 // Get the user's chosen name and icon, or default if they do not | 309 // Get the user's chosen name and icon, or default if they do not |
298 // wish to customize their profile. | 310 // wish to customize their profile. |
299 var name = $('create-profile-name').value; | 311 var name = $('create-profile-name').value; |
300 var iconUrl = $('create-profile-icon-grid').selectedItem; | 312 var iconUrl = $('create-profile-icon-grid').selectedItem; |
301 var createShortcut = $('create-shortcut').checked; | 313 var createShortcut = $('create-shortcut').checked; |
302 var isManaged = $('create-profile-limited').checked; | 314 var isManaged = $('create-profile-limited').checked; |
315 | |
316 // 'createProfile' is handled by the BrowserOptionsHandler. | |
303 chrome.send('createProfile', | 317 chrome.send('createProfile', |
304 [name, iconUrl, createShortcut, isManaged]); | 318 [name, iconUrl, createShortcut, isManaged]); |
305 }, | 319 }, |
306 | 320 |
307 /** | 321 /** |
308 * Called when the selected icon in the icon grid changes. | 322 * Called when the selected icon in the icon grid changes. |
309 * @param {string} mode A label that specifies the type of dialog | 323 * @param {string} mode A label that specifies the type of dialog |
310 * box which is currently being viewed (i.e. 'create' or | 324 * box which is currently being viewed (i.e. 'create' or |
311 * 'manage'). | 325 * 'manage'). |
312 * @private | 326 * @private |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 didShowPage: function() { | 425 didShowPage: function() { |
412 chrome.send('requestSignedInText'); | 426 chrome.send('requestSignedInText'); |
413 chrome.send('requestDefaultProfileIcons'); | 427 chrome.send('requestDefaultProfileIcons'); |
414 chrome.send('requestNewProfileDefaults'); | 428 chrome.send('requestNewProfileDefaults'); |
415 | 429 |
416 $('manage-profile-overlay-create').hidden = false; | 430 $('manage-profile-overlay-create').hidden = false; |
417 $('manage-profile-overlay-manage').hidden = true; | 431 $('manage-profile-overlay-manage').hidden = true; |
418 $('manage-profile-overlay-delete').hidden = true; | 432 $('manage-profile-overlay-delete').hidden = true; |
419 $('create-profile-instructions').textContent = | 433 $('create-profile-instructions').textContent = |
420 loadTimeData.getStringF('createProfileInstructions'); | 434 loadTimeData.getStringF('createProfileInstructions'); |
421 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); | 435 this.hideErrorBubble_(); |
422 | 436 |
423 var shortcutsEnabled = loadTimeData.getBoolean('profileShortcutsEnabled'); | 437 var shortcutsEnabled = loadTimeData.getBoolean('profileShortcutsEnabled'); |
424 $('create-shortcut-container').hidden = !shortcutsEnabled; | 438 $('create-shortcut-container').hidden = !shortcutsEnabled; |
425 $('create-shortcut').checked = shortcutsEnabled; | 439 $('create-shortcut').checked = shortcutsEnabled; |
426 | 440 |
427 $('create-profile-name-label').hidden = true; | 441 $('create-profile-name-label').hidden = true; |
428 $('create-profile-name').hidden = true; | 442 $('create-profile-name').hidden = true; |
429 $('create-profile-ok').disabled = true; | 443 $('create-profile-ok').disabled = true; |
430 }, | 444 }, |
431 | 445 |
446 /** @override */ | |
447 showErrorBubble_: function(errorText) { | |
448 ManageProfileOverlay.getInstance().showErrorBubble_(errorText, | |
449 'create', | |
450 false); | |
451 }, | |
452 | |
453 /** @override */ | |
454 hideErrorBubble_: function() { | |
455 ManageProfileOverlay.getInstance().hideErrorBubble_('create'); | |
456 }, | |
457 | |
458 /** | |
459 * Shows an error message describing a local error (most likely a disk | |
460 * error) when creating a new profile. Called by BrowserOptions via the | |
461 * BrowserOptionsHandler. | |
462 * @private | |
463 */ | |
464 onLocalError_: function() { | |
465 $('create-profile-ok').disabled = false; | |
466 this.showErrorBubble_('createProfileLocalError'); | |
467 }, | |
468 | |
469 /** | |
470 * For new limited users, shows a confirmation page after successfully | |
471 * creating a new profile; otherwise, the handler will open a new window. | |
472 * @private | |
473 */ | |
474 onSuccess_: function(isManaged) { | |
475 OptionsPage.closeOverlay(); | |
476 $('create-profile-ok').disabled = false; | |
477 if (isManaged) { | |
478 // TODO(pamg): Fill out this stub. | |
479 console.log('Success - show confirmation'); | |
James Hawkins
2013/05/29 17:22:44
nit: Remove the log.
| |
480 } | |
481 }, | |
482 | |
432 /** | 483 /** |
433 * Updates the signed-in or not-signed-in UI when in create mode. Called by | 484 * Updates the signed-in or not-signed-in UI when in create mode. Called by |
434 * the handler in response to the 'requestSignedInText' message. | 485 * the handler in response to the 'requestSignedInText' message. |
435 * @param {string} text The text to show for a signed-in user. An empty | 486 * @param {string} text The text to show for a signed-in user. An empty |
436 * string indicates that the user is not signed in. | 487 * string indicates that the user is not signed in. |
437 * @private | 488 * @private |
438 */ | 489 */ |
439 updateSignedInStatus_: function(text) { | 490 updateSignedInStatus_: function(text) { |
440 var isSignedIn = text !== ''; | 491 var isSignedIn = text !== ''; |
441 $('create-profile-limited-signed-in').hidden = !isSignedIn; | 492 $('create-profile-limited-signed-in').hidden = !isSignedIn; |
442 $('create-profile-limited-not-signed-in').hidden = isSignedIn; | 493 $('create-profile-limited-not-signed-in').hidden = isSignedIn; |
443 $('create-profile-limited').disabled = !isSignedIn; | 494 $('create-profile-limited').disabled = !isSignedIn; |
444 | 495 |
445 $('create-profile-limited-signed-in-label').textContent = text; | 496 $('create-profile-limited-signed-in-label').textContent = text; |
446 }, | 497 }, |
447 }; | 498 }; |
448 | 499 |
449 // Forward public APIs to private implementations. | 500 // Forward public APIs to private implementations. |
450 [ | 501 [ |
502 'onLocalError', | |
503 'onSuccess', | |
451 'updateSignedInStatus', | 504 'updateSignedInStatus', |
452 ].forEach(function(name) { | 505 ].forEach(function(name) { |
453 CreateProfileOverlay[name] = function() { | 506 CreateProfileOverlay[name] = function() { |
454 var instance = CreateProfileOverlay.getInstance(); | 507 var instance = CreateProfileOverlay.getInstance(); |
455 return instance[name + '_'].apply(instance, arguments); | 508 return instance[name + '_'].apply(instance, arguments); |
456 }; | 509 }; |
457 }); | 510 }); |
458 | 511 |
459 // Export | 512 // Export |
460 return { | 513 return { |
461 ManageProfileOverlay: ManageProfileOverlay, | 514 ManageProfileOverlay: ManageProfileOverlay, |
462 CreateProfileOverlay: CreateProfileOverlay, | 515 CreateProfileOverlay: CreateProfileOverlay, |
463 }; | 516 }; |
464 }); | 517 }); |
OLD | NEW |