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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 $('manage-profile-cancel').onclick = | 61 $('manage-profile-cancel').onclick = |
62 $('delete-profile-cancel').onclick = function(event) { | 62 $('delete-profile-cancel').onclick = function(event) { |
63 OptionsPage.closeOverlay(); | 63 OptionsPage.closeOverlay(); |
64 }; | 64 }; |
65 $('delete-profile-ok').onclick = function(event) { | 65 $('delete-profile-ok').onclick = function(event) { |
66 OptionsPage.closeOverlay(); | 66 OptionsPage.closeOverlay(); |
67 if (BrowserOptions.getCurrentProfile().isManaged) | 67 if (BrowserOptions.getCurrentProfile().isManaged) |
68 return; | 68 return; |
69 chrome.send('deleteProfile', [self.profileInfo_.filePath]); | 69 chrome.send('deleteProfile', [self.profileInfo_.filePath]); |
70 options.ManagedUserListData.reloadExistingManagedUsers(); | 70 options.ManagedUserListData.resetPromise(); |
71 }; | 71 }; |
72 $('add-shortcut-button').onclick = function(event) { | 72 $('add-shortcut-button').onclick = function(event) { |
73 chrome.send('addProfileShortcut', [self.profileInfo_.filePath]); | 73 chrome.send('addProfileShortcut', [self.profileInfo_.filePath]); |
74 }; | 74 }; |
75 $('remove-shortcut-button').onclick = function(event) { | 75 $('remove-shortcut-button').onclick = function(event) { |
76 chrome.send('removeProfileShortcut', [self.profileInfo_.filePath]); | 76 chrome.send('removeProfileShortcut', [self.profileInfo_.filePath]); |
77 }; | 77 }; |
78 | 78 |
79 $('create-profile-managed-signed-in-learn-more-link').onclick = | 79 $('create-profile-managed-signed-in-learn-more-link').onclick = |
80 function(event) { | 80 function(event) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 $(mode + '-profile-ok').disabled = true; | 269 $(mode + '-profile-ok').disabled = true; |
270 }, | 270 }, |
271 | 271 |
272 /** | 272 /** |
273 * Hide the error bubble. | 273 * Hide the error bubble. |
274 * @param {string} mode A label that specifies the type of dialog box which | 274 * @param {string} mode A label that specifies the type of dialog box which |
275 * is currently being viewed (i.e. 'create' or 'manage'). | 275 * is currently being viewed (i.e. 'create' or 'manage'). |
276 * @private | 276 * @private |
277 */ | 277 */ |
278 hideErrorBubble_: function(mode) { | 278 hideErrorBubble_: function(mode) { |
| 279 $(mode + '-profile-error-bubble').innerHTML = ''; |
279 $(mode + '-profile-error-bubble').hidden = true; | 280 $(mode + '-profile-error-bubble').hidden = true; |
280 $(mode + '-profile-ok').disabled = false; | 281 $(mode + '-profile-ok').disabled = false; |
281 }, | 282 }, |
282 | 283 |
283 /** | 284 /** |
284 * oninput callback for <input> field. | 285 * oninput callback for <input> field. |
285 * @param {string} mode A label that specifies the type of dialog box which | 286 * @param {string} mode A label that specifies the type of dialog box which |
286 * is currently being viewed (i.e. 'create' or 'manage'). | 287 * is currently being viewed (i.e. 'create' or 'manage'). |
287 * @private | 288 * @private |
288 */ | 289 */ |
289 onNameChanged_: function(mode) { | 290 onNameChanged_: function(mode) { |
290 var newName = $(mode + '-profile-name').value; | 291 var newName = $(mode + '-profile-name').value; |
291 var oldName = this.profileInfo_.name; | 292 var oldName = this.profileInfo_.name; |
292 | 293 |
293 // In 'create' mode, the initial name can be the name of an already | 294 // In 'create' mode, the initial name can be the name of an already |
294 // existing supervised user. | 295 // existing supervised user. |
295 if (newName == oldName && mode == 'manage') { | 296 if (newName == oldName && mode == 'manage') { |
296 this.hideErrorBubble_(mode); | 297 this.hideErrorBubble_(mode); |
297 } else if (this.profileNames_[newName] != undefined) { | |
298 var errorHtml = | |
299 loadTimeData.getString('manageProfilesDuplicateNameError'); | |
300 this.showErrorBubble_(errorHtml, mode, true); | |
301 } else if (mode == 'create' && | 298 } else if (mode == 'create' && |
302 loadTimeData.getBoolean('allowCreateExistingManagedUsers')) { | 299 loadTimeData.getBoolean('allowCreateExistingManagedUsers') && |
303 this.checkIfSupervisedUserExists_(); | 300 $('create-profile-managed').checked) { |
| 301 options.ManagedUserListData.requestExistingManagedUsers().then( |
| 302 this.receiveExistingManagedUsers_.bind(this), |
| 303 this.onSigninError_.bind(this)); |
304 } else { | 304 } else { |
305 this.updateOkButton_(mode); | 305 this.updateOkButton_(mode); |
306 } | 306 } |
307 }, | 307 }, |
308 | 308 |
309 /** | 309 /** |
310 * Checks if a supervised user with the currently entered name already | |
311 * exists. | |
312 * @private | |
313 */ | |
314 checkIfSupervisedUserExists_: function() { | |
315 if (!$('create-profile-managed').checked) { | |
316 this.updateOkButton_('create'); | |
317 return; | |
318 } | |
319 options.ManagedUserListData.requestExistingManagedUsers( | |
320 this.receiveExistingManagedUsers_.bind(this), | |
321 this.onSigninError_.bind(this)); | |
322 }, | |
323 | |
324 /** | |
325 * Callback which receives the list of existing managed users. Checks if the | 310 * Callback which receives the list of existing managed users. Checks if the |
326 * currently entered name is the name of an already existing managed user. | 311 * currently entered name is the name of an already existing managed user. |
327 * If yes, the user is prompted to import the existing managed user, and the | 312 * If yes, the user is prompted to import the existing managed user, and the |
328 * create button is disabled. | 313 * create button is disabled. |
329 * @param {Array.<Object>} The list of existing managed users. | 314 * @param {Array.<Object>} The list of existing managed users. |
330 * @private | 315 * @private |
331 */ | 316 */ |
332 receiveExistingManagedUsers_: function(managedUsers) { | 317 receiveExistingManagedUsers_: function(managedUsers) { |
333 var newName = $('create-profile-name').value; | 318 var newName = $('create-profile-name').value; |
334 var i; | 319 var i; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 this.updateOkButton_('create'); | 354 this.updateOkButton_('create'); |
370 }, | 355 }, |
371 | 356 |
372 /** | 357 /** |
373 * Called in case the request for the list of managed users fails because of | 358 * Called in case the request for the list of managed users fails because of |
374 * a signin error. | 359 * a signin error. |
375 * @private | 360 * @private |
376 */ | 361 */ |
377 onSigninError_: function() { | 362 onSigninError_: function() { |
378 this.updateImportExistingManagedUserLink_(false); | 363 this.updateImportExistingManagedUserLink_(false); |
379 this.updateManagedUsersAllowed_(false); | |
380 }, | 364 }, |
381 | 365 |
382 /** | 366 /** |
383 * Called if the name seems to be unused so far. | 367 * Called to update the state of the ok button depending if the name is |
| 368 * already used or not. |
384 * @param {string} mode A label that specifies the type of dialog box which | 369 * @param {string} mode A label that specifies the type of dialog box which |
385 * is currently being viewed (i.e. 'create' or 'manage'). | 370 * is currently being viewed (i.e. 'create' or 'manage'). |
386 * @private | 371 * @private |
387 */ | 372 */ |
388 updateOkButton_: function(mode) { | 373 updateOkButton_: function(mode) { |
389 this.hideErrorBubble_(mode); | 374 var newName = $(mode + '-profile-name').value; |
| 375 if (this.profileNames_[newName] != undefined) { |
| 376 var errorHtml = |
| 377 loadTimeData.getString('manageProfilesDuplicateNameError'); |
| 378 this.showErrorBubble_(errorHtml, mode, true); |
| 379 } else { |
| 380 this.hideErrorBubble_(mode); |
390 | 381 |
391 var nameIsValid = $(mode + '-profile-name').validity.valid; | 382 var nameIsValid = $(mode + '-profile-name').validity.valid; |
392 $(mode + '-profile-ok').disabled = !nameIsValid; | 383 $(mode + '-profile-ok').disabled = !nameIsValid; |
| 384 } |
393 }, | 385 }, |
394 | 386 |
395 /** | 387 /** |
396 * Called when the user clicks "OK" or hits enter. Saves the newly changed | 388 * Called when the user clicks "OK" or hits enter. Saves the newly changed |
397 * profile info. | 389 * profile info. |
398 * @private | 390 * @private |
399 */ | 391 */ |
400 submitManageChanges_: function() { | 392 submitManageChanges_: function() { |
401 var name = $('manage-profile-name').value; | 393 var name = $('manage-profile-name').value; |
402 var iconURL = $('manage-profile-icon-grid').selectedItem; | 394 var iconURL = $('manage-profile-icon-grid').selectedItem; |
403 | 395 |
404 chrome.send('setProfileIconAndName', | 396 chrome.send('setProfileIconAndName', |
405 [this.profileInfo_.filePath, iconURL, name]); | 397 [this.profileInfo_.filePath, iconURL, name]); |
| 398 if (name != this.profileInfo_.name) |
| 399 options.ManagedUserListData.resetPromise(); |
406 }, | 400 }, |
407 | 401 |
408 /** | 402 /** |
409 * Called when the user clicks "OK" or hits enter. Creates the profile | 403 * Called when the user clicks "OK" or hits enter. Creates the profile |
410 * using the information in the dialog. | 404 * using the information in the dialog. |
411 * @private | 405 * @private |
412 */ | 406 */ |
413 submitCreateProfile_: function() { | 407 submitCreateProfile_: function() { |
414 // This is visual polish: the UI to access this should be disabled for | 408 // This is visual polish: the UI to access this should be disabled for |
415 // managed users, and the back end will prevent user creation anyway. | 409 // managed users, and the back end will prevent user creation anyway. |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 * name: "Profile Name", | 657 * name: "Profile Name", |
664 * filePath: "/path/to/profile/data/on/disk" | 658 * filePath: "/path/to/profile/data/on/disk" |
665 * isManaged: (true|false), | 659 * isManaged: (true|false), |
666 * }; | 660 * }; |
667 * @private | 661 * @private |
668 */ | 662 */ |
669 onSuccess_: function(profileInfo) { | 663 onSuccess_: function(profileInfo) { |
670 this.updateCreateInProgress_(false); | 664 this.updateCreateInProgress_(false); |
671 OptionsPage.closeOverlay(); | 665 OptionsPage.closeOverlay(); |
672 if (profileInfo.isManaged) { | 666 if (profileInfo.isManaged) { |
673 options.ManagedUserListData.reloadExistingManagedUsers(); | 667 options.ManagedUserListData.resetPromise(); |
674 profileInfo.custodianEmail = this.signedInEmail_; | 668 profileInfo.custodianEmail = this.signedInEmail_; |
675 ManagedUserCreateConfirmOverlay.setProfileInfo(profileInfo); | 669 ManagedUserCreateConfirmOverlay.setProfileInfo(profileInfo); |
676 OptionsPage.showPageByName('managedUserCreateConfirm', false); | 670 OptionsPage.showPageByName('managedUserCreateConfirm', false); |
677 BrowserOptions.updateManagesSupervisedUsers(true); | 671 BrowserOptions.updateManagesSupervisedUsers(true); |
678 } | 672 } |
679 }, | 673 }, |
680 | 674 |
681 /** | 675 /** |
682 * Updates the signed-in or not-signed-in UI when in create mode. Called by | 676 * Updates the signed-in or not-signed-in UI when in create mode. Called by |
683 * the handler in response to the 'requestCreateProfileUpdate' message. | 677 * the handler in response to the 'requestCreateProfileUpdate' message. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 return instance[name + '_'].apply(instance, arguments); | 775 return instance[name + '_'].apply(instance, arguments); |
782 }; | 776 }; |
783 }); | 777 }); |
784 | 778 |
785 // Export | 779 // Export |
786 return { | 780 return { |
787 ManageProfileOverlay: ManageProfileOverlay, | 781 ManageProfileOverlay: ManageProfileOverlay, |
788 CreateProfileOverlay: CreateProfileOverlay, | 782 CreateProfileOverlay: CreateProfileOverlay, |
789 }; | 783 }; |
790 }); | 784 }); |
OLD | NEW |