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 Page = cr.ui.pageManager.Page; | 6 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | 7 var PageManager = cr.ui.pageManager.PageManager; |
8 var ArrayDataModel = cr.ui.ArrayDataModel; | 8 var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 $('remove-shortcut-button').onclick = function(event) { | 82 $('remove-shortcut-button').onclick = function(event) { |
83 chrome.send('removeProfileShortcut', [self.profileInfo_.filePath]); | 83 chrome.send('removeProfileShortcut', [self.profileInfo_.filePath]); |
84 }; | 84 }; |
85 | 85 |
86 $('disconnect-managed-profile-ok').onclick = function(event) { | 86 $('disconnect-managed-profile-ok').onclick = function(event) { |
87 PageManager.closeOverlay(); | 87 PageManager.closeOverlay(); |
88 chrome.send('deleteProfile', | 88 chrome.send('deleteProfile', |
89 [BrowserOptions.getCurrentProfile().filePath]); | 89 [BrowserOptions.getCurrentProfile().filePath]); |
90 }; | 90 }; |
91 | 91 |
92 $('create-profile-supervised-not-signed-in').innerHTML = | |
93 loadTimeData.getStringF('manageProfilesSupervisedNotSignedIn'); | |
Pam (message me for reviews)
2014/08/13 14:25:47
You can do this directly in the HTML file, using
Marc Treib
2014/08/13 16:08:45
Ah, nice! TIL :)
| |
94 | |
92 $('create-profile-supervised-signed-in-learn-more-link').onclick = | 95 $('create-profile-supervised-signed-in-learn-more-link').onclick = |
93 function(event) { | 96 function(event) { |
94 PageManager.showPageByName('supervisedUserLearnMore'); | 97 PageManager.showPageByName('supervisedUserLearnMore'); |
95 return false; | 98 return false; |
96 }; | 99 }; |
97 | 100 |
98 $('create-profile-supervised-not-signed-in-link').onclick = | 101 $('create-profile-supervised-sign-in-link').onclick = |
99 function(event) { | 102 function(event) { |
100 // The signin process will open an overlay to configure sync, which | 103 // The signin process will open an overlay to configure sync, which |
101 // would replace this overlay. It's smoother to close this one now. | 104 // would replace this overlay. It's smoother to close this one now. |
102 // TODO(pamg): Move the sync-setup overlay to a higher layer so this one | 105 // TODO(pamg): Move the sync-setup overlay to a higher layer so this one |
103 // can stay open under it, after making sure that doesn't break anything | 106 // can stay open under it, after making sure that doesn't break anything |
104 // else. | 107 // else. |
105 PageManager.closeOverlay(); | 108 PageManager.closeOverlay(); |
106 SyncSetupOverlay.startSignIn(); | 109 SyncSetupOverlay.startSignIn(); |
107 }; | 110 }; |
108 | 111 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 * Called when the profile name is changed or the 'create supervised' | 331 * Called when the profile name is changed or the 'create supervised' |
329 * checkbox is toggled. Updates the 'ok' button and the 'import existing | 332 * checkbox is toggled. Updates the 'ok' button and the 'import existing |
330 * supervised user' link. | 333 * supervised user' link. |
331 * @param {string} mode A label that specifies the type of dialog box which | 334 * @param {string} mode A label that specifies the type of dialog box which |
332 * is currently being viewed (i.e. 'create' or 'manage'). | 335 * is currently being viewed (i.e. 'create' or 'manage'). |
333 * @private | 336 * @private |
334 */ | 337 */ |
335 updateCreateOrImport_: function(mode) { | 338 updateCreateOrImport_: function(mode) { |
336 // In 'create' mode, check for existing supervised users with the same | 339 // In 'create' mode, check for existing supervised users with the same |
337 // name. | 340 // name. |
338 if (mode == 'create' && $('create-profile-supervised').checked) { | 341 if (mode == 'create') { |
339 options.SupervisedUserListData.requestExistingSupervisedUsers().then( | 342 this.requestExistingSupervisedUsers_(); |
340 this.receiveExistingSupervisedUsers_.bind(this), | |
341 this.onSigninError_.bind(this)); | |
342 } else { | 343 } else { |
343 this.updateOkButton_(mode); | 344 this.updateOkButton_(mode); |
344 } | 345 } |
345 }, | 346 }, |
346 | 347 |
347 /** | 348 /** |
349 * Tries to get the list of existing supervised users and updates the UI | |
350 * accordingly. | |
351 * @private | |
352 */ | |
353 requestExistingSupervisedUsers_: function() { | |
354 options.SupervisedUserListData.requestExistingSupervisedUsers().then( | |
355 this.receiveExistingSupervisedUsers_.bind(this), | |
356 this.onSigninError_.bind(this)); | |
357 }, | |
358 | |
359 /** | |
348 * Callback which receives the list of existing supervised users. Checks if | 360 * Callback which receives the list of existing supervised users. Checks if |
349 * the currently entered name is the name of an already existing supervised | 361 * the currently entered name is the name of an already existing supervised |
350 * user. If yes, the user is prompted to import the existing supervised | 362 * user. If yes, the user is prompted to import the existing supervised |
351 * user, and the create button is disabled. | 363 * user, and the create button is disabled. |
364 * If the received list is empty, hides the "import" link. | |
352 * @param {Array.<Object>} The list of existing supervised users. | 365 * @param {Array.<Object>} The list of existing supervised users. |
353 * @private | 366 * @private |
354 */ | 367 */ |
355 receiveExistingSupervisedUsers_: function(supervisedUsers) { | 368 receiveExistingSupervisedUsers_: function(supervisedUsers) { |
369 $('import-existing-supervised-user-link').hidden = | |
370 supervisedUsers.length === 0; | |
371 if (!$('create-profile-supervised').checked) | |
372 return; | |
373 | |
356 var newName = $('create-profile-name').value; | 374 var newName = $('create-profile-name').value; |
357 var i; | 375 var i; |
358 for (i = 0; i < supervisedUsers.length; ++i) { | 376 for (i = 0; i < supervisedUsers.length; ++i) { |
359 if (supervisedUsers[i].name == newName && | 377 if (supervisedUsers[i].name == newName && |
360 !supervisedUsers[i].onCurrentDevice) { | 378 !supervisedUsers[i].onCurrentDevice) { |
361 var errorHtml = loadTimeData.getStringF( | 379 var errorHtml = loadTimeData.getStringF( |
362 'manageProfilesExistingSupervisedUser', | 380 'manageProfilesExistingSupervisedUser', |
363 HTMLEscape(elide(newName, /* maxLength */ 50))); | 381 HTMLEscape(elide(newName, /* maxLength */ 50))); |
364 this.showErrorBubble_(errorHtml, 'create', true); | 382 this.showErrorBubble_(errorHtml, 'create', true); |
365 | 383 |
(...skipping 28 matching lines...) Expand all Loading... | |
394 } | 412 } |
395 this.updateOkButton_('create'); | 413 this.updateOkButton_('create'); |
396 }, | 414 }, |
397 | 415 |
398 /** | 416 /** |
399 * Called in case the request for the list of supervised users fails because | 417 * Called in case the request for the list of supervised users fails because |
400 * of a signin error. | 418 * of a signin error. |
401 * @private | 419 * @private |
402 */ | 420 */ |
403 onSigninError_: function() { | 421 onSigninError_: function() { |
404 this.updateImportExistingSupervisedUserLink_(false); | 422 this.updateSignedInStatus_(this.signedInEmail_, true); |
405 }, | 423 }, |
406 | 424 |
407 /** | 425 /** |
408 * Called to update the state of the ok button depending if the name is | 426 * Called to update the state of the ok button depending if the name is |
409 * already used or not. | 427 * already used or not. |
410 * @param {string} mode A label that specifies the type of dialog box which | 428 * @param {string} mode A label that specifies the type of dialog box which |
411 * is currently being viewed (i.e. 'create' or 'manage'). | 429 * is currently being viewed (i.e. 'create' or 'manage'). |
412 * @private | 430 * @private |
413 */ | 431 */ |
414 updateOkButton_: function(mode) { | 432 updateOkButton_: function(mode) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 | 660 |
643 $('create-profile-name-label').hidden = true; | 661 $('create-profile-name-label').hidden = true; |
644 $('create-profile-name').hidden = true; | 662 $('create-profile-name').hidden = true; |
645 $('create-profile-ok').disabled = true; | 663 $('create-profile-ok').disabled = true; |
646 | 664 |
647 $('create-profile-supervised').checked = false; | 665 $('create-profile-supervised').checked = false; |
648 $('import-existing-supervised-user-link').hidden = true; | 666 $('import-existing-supervised-user-link').hidden = true; |
649 $('create-profile-supervised').onchange = function() { | 667 $('create-profile-supervised').onchange = function() { |
650 ManageProfileOverlay.getInstance().updateCreateOrImport_('create'); | 668 ManageProfileOverlay.getInstance().updateCreateOrImport_('create'); |
651 }; | 669 }; |
670 $('create-profile-supervised').hidden = true; | |
652 $('create-profile-supervised-signed-in').disabled = true; | 671 $('create-profile-supervised-signed-in').disabled = true; |
653 $('create-profile-supervised-signed-in').hidden = true; | 672 $('create-profile-supervised-signed-in').hidden = true; |
654 $('create-profile-supervised-not-signed-in').hidden = true; | 673 $('create-profile-supervised-not-signed-in').hidden = true; |
655 | 674 |
656 this.profileNameIsDefault_ = false; | 675 this.profileNameIsDefault_ = false; |
657 }, | 676 }, |
658 | 677 |
659 /** @override */ | 678 /** @override */ |
660 handleCancel: function() { | 679 handleCancel: function() { |
661 this.cancelCreateProfile_(); | 680 this.cancelCreateProfile_(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 * @param {string} email The email address of the currently signed-in user. | 778 * @param {string} email The email address of the currently signed-in user. |
760 * An empty string indicates that the user is not signed in. | 779 * An empty string indicates that the user is not signed in. |
761 * @param {boolean} hasError Whether the user's sign-in credentials are | 780 * @param {boolean} hasError Whether the user's sign-in credentials are |
762 * still valid. | 781 * still valid. |
763 * @private | 782 * @private |
764 */ | 783 */ |
765 updateSignedInStatus_: function(email, hasError) { | 784 updateSignedInStatus_: function(email, hasError) { |
766 this.signedInEmail_ = email; | 785 this.signedInEmail_ = email; |
767 this.hasError_ = hasError; | 786 this.hasError_ = hasError; |
768 var isSignedIn = email !== ''; | 787 var isSignedIn = email !== ''; |
788 $('create-profile-supervised').hidden = !isSignedIn; | |
769 $('create-profile-supervised-signed-in').hidden = !isSignedIn; | 789 $('create-profile-supervised-signed-in').hidden = !isSignedIn; |
770 $('create-profile-supervised-not-signed-in').hidden = isSignedIn; | 790 $('create-profile-supervised-not-signed-in').hidden = isSignedIn; |
771 | 791 |
772 if (isSignedIn) { | 792 if (isSignedIn) { |
773 var accountDetailsOutOfDate = | 793 var accountDetailsOutOfDate = |
774 $('create-profile-supervised-account-details-out-of-date-label'); | 794 $('create-profile-supervised-account-details-out-of-date-label'); |
775 accountDetailsOutOfDate.textContent = loadTimeData.getStringF( | 795 accountDetailsOutOfDate.textContent = loadTimeData.getStringF( |
776 'manageProfilesSupervisedAccountDetailsOutOfDate', email); | 796 'manageProfilesSupervisedAccountDetailsOutOfDate', email); |
777 accountDetailsOutOfDate.hidden = !hasError; | 797 accountDetailsOutOfDate.hidden = !hasError; |
778 | 798 |
779 $('create-profile-supervised-signed-in-label').textContent = | 799 $('create-profile-supervised-signed-in-label').textContent = |
780 loadTimeData.getStringF( | 800 loadTimeData.getStringF( |
781 'manageProfilesSupervisedSignedInLabel', email); | 801 'manageProfilesSupervisedSignedInLabel', email); |
782 $('create-profile-supervised-signed-in-label').hidden = hasError; | 802 $('create-profile-supervised-signed-in-label').hidden = hasError; |
783 | 803 |
784 $('create-profile-supervised-sign-in-again-link').hidden = !hasError; | 804 $('create-profile-supervised-sign-in-again-link').hidden = !hasError; |
785 $('create-profile-supervised-signed-in-learn-more-link').hidden = | 805 $('create-profile-supervised-signed-in-learn-more-link').hidden = |
786 hasError; | 806 hasError; |
787 } | 807 } |
788 | 808 |
789 this.updateImportExistingSupervisedUserLink_(isSignedIn && !hasError); | 809 this.updateCreateSupervisedUserCheckbox_(); |
810 // If we're signed in, showing/hiding import-existing-supervised-user-link | |
811 // is handled in receiveExistingSupervisedUsers_. | |
812 if (isSignedIn && !hasError) | |
813 this.requestExistingSupervisedUsers_(); | |
814 else | |
815 $('import-existing-supervised-user-link').hidden = true; | |
790 }, | 816 }, |
791 | 817 |
792 /** | 818 /** |
793 * Enables/disables the 'import existing supervised users' link button. | |
794 * It also updates the button text. | |
795 * @param {boolean} enable True to enable the link button and | |
796 * false otherwise. | |
797 * @private | |
798 */ | |
799 updateImportExistingSupervisedUserLink_: function(enable) { | |
800 var importSupervisedUserElement = | |
801 $('import-existing-supervised-user-link'); | |
802 importSupervisedUserElement.hidden = false; | |
803 importSupervisedUserElement.disabled = !enable || this.createInProgress_; | |
804 importSupervisedUserElement.textContent = enable ? | |
805 loadTimeData.getString('importExistingSupervisedUserLink') : | |
806 loadTimeData.getString('signInToImportSupervisedUsers'); | |
807 }, | |
808 | |
809 /** | |
810 * Sets whether creating supervised users is allowed or not. Called by the | 819 * Sets whether creating supervised users is allowed or not. Called by the |
811 * handler in response to the 'requestCreateProfileUpdate' message or a | 820 * handler in response to the 'requestCreateProfileUpdate' message or a |
812 * change in the (policy-controlled) pref that prohibits creating supervised | 821 * change in the (policy-controlled) pref that prohibits creating supervised |
813 * users, after the signed-in status has been updated. | 822 * users, after the signed-in status has been updated. |
814 * @param {boolean} allowed True if creating supervised users should be | 823 * @param {boolean} allowed True if creating supervised users should be |
815 * allowed. | 824 * allowed. |
816 * @private | 825 * @private |
817 */ | 826 */ |
818 updateSupervisedUsersAllowed_: function(allowed) { | 827 updateSupervisedUsersAllowed_: function(allowed) { |
819 this.supervisedUsersAllowed_ = allowed; | 828 this.supervisedUsersAllowed_ = allowed; |
820 this.updateCreateSupervisedUserCheckbox_(); | 829 this.updateCreateSupervisedUserCheckbox_(); |
821 | 830 |
822 $('create-profile-supervised-not-signed-in-link').hidden = !allowed; | 831 $('create-profile-supervised-sign-in-link').enabled = allowed; |
823 if (!allowed) { | 832 if (!allowed) { |
824 $('create-profile-supervised-indicator').setAttribute('controlled-by', | 833 $('create-profile-supervised-indicator').setAttribute('controlled-by', |
825 'policy'); | 834 'policy'); |
826 } else { | 835 } else { |
827 $('create-profile-supervised-indicator').removeAttribute( | 836 $('create-profile-supervised-indicator').removeAttribute( |
828 'controlled-by'); | 837 'controlled-by'); |
829 } | 838 } |
830 }, | 839 }, |
831 | 840 |
832 /** | 841 /** |
(...skipping 25 matching lines...) Expand all Loading... | |
858 return instance[name + '_'].apply(instance, arguments); | 867 return instance[name + '_'].apply(instance, arguments); |
859 }; | 868 }; |
860 }); | 869 }); |
861 | 870 |
862 // Export | 871 // Export |
863 return { | 872 return { |
864 ManageProfileOverlay: ManageProfileOverlay, | 873 ManageProfileOverlay: ManageProfileOverlay, |
865 CreateProfileOverlay: CreateProfileOverlay, | 874 CreateProfileOverlay: CreateProfileOverlay, |
866 }; | 875 }; |
867 }); | 876 }); |
OLD | NEW |