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.
5 cr
.define('options', function() {
6 var Page
= cr
.ui
.pageManager
.Page
;
7 var PageManager
= cr
.ui
.pageManager
.PageManager
;
8 var ArrayDataModel
= cr
.ui
.ArrayDataModel
;
11 * ManageProfileOverlay class
12 * Encapsulated handling of the 'Manage profile...' overlay page.
14 * @extends {cr.ui.pageManager.Page}
16 function ManageProfileOverlay() {
17 Page
.call(this, 'manageProfile',
18 loadTimeData
.getString('manageProfileTabTitle'),
19 'manage-profile-overlay');
22 cr
.addSingletonGetter(ManageProfileOverlay
);
24 ManageProfileOverlay
.prototype = {
26 __proto__
: Page
.prototype,
28 // Info about the currently managed/deleted profile.
31 // Whether the currently chosen name for a new profile was assigned
32 // automatically by choosing an avatar. Set on receiveNewProfileDefaults;
33 // cleared on first edit (in onNameChanged_).
34 profileNameIsDefault_
: false,
36 // List of default profile names corresponding to the respective icons.
37 defaultProfileNames_
: [],
39 // An object containing all names of existing profiles.
40 existingProfileNames_
: {},
42 // The currently selected icon in the icon grid.
43 iconGridSelectedURL_
: null,
46 initializePage: function() {
47 Page
.prototype.initializePage
.call(this);
50 options
.ProfilesIconGrid
.decorate($('manage-profile-icon-grid'));
51 options
.ProfilesIconGrid
.decorate($('create-profile-icon-grid'));
52 self
.registerCommonEventHandlers_('create',
53 self
.submitCreateProfile_
.bind(self
));
54 self
.registerCommonEventHandlers_('manage',
55 self
.submitManageChanges_
.bind(self
));
57 // Override the create-profile-ok and create-* keydown handlers, to avoid
58 // closing the overlay until we finish creating the profile.
59 $('create-profile-ok').onclick = function(event
) {
60 self
.submitCreateProfile_();
63 $('create-profile-cancel').onclick = function(event
) {
64 CreateProfileOverlay
.cancelCreateProfile();
67 $('manage-profile-cancel').onclick
=
68 $('disconnect-managed-profile-cancel').onclick
=
69 $('delete-profile-cancel').onclick = function(event
) {
70 PageManager
.closeOverlay();
72 $('delete-profile-ok').onclick = function(event
) {
73 PageManager
.closeOverlay();
74 chrome
.send('deleteProfile', [self
.profileInfo_
.filePath
]);
75 options
.SupervisedUserListData
.resetPromise();
77 $('add-shortcut-button').onclick = function(event
) {
78 chrome
.send('addProfileShortcut', [self
.profileInfo_
.filePath
]);
80 $('remove-shortcut-button').onclick = function(event
) {
81 chrome
.send('removeProfileShortcut', [self
.profileInfo_
.filePath
]);
84 $('disconnect-managed-profile-ok').onclick = function(event
) {
85 PageManager
.closeOverlay();
86 chrome
.send('deleteProfile',
87 [BrowserOptions
.getCurrentProfile().filePath
]);
90 $('create-profile-supervised-signed-in-learn-more-link').onclick
=
92 PageManager
.showPageByName('supervisedUserLearnMore');
96 $('create-profile-supervised-sign-in-link').onclick
=
98 // Without the new avatar menu, the signin process will open an overlay
99 // to configure sync, which would replace this overlay. It's smoother to
100 // close this one now.
101 // With the new avatar menu enabled, a sign-in flow in the avatar menu
102 // is triggered instead, which does not open any overlays, so there's no
103 // need to close this one.
104 if (!loadTimeData
.getBoolean('newAvatarMenuEnabled')) {
105 // TODO(pamg): Move the sync-setup overlay to a higher layer so this
106 // one can stay open under it, after making sure that doesn't break
108 PageManager
.closeOverlay();
110 SyncSetupOverlay
.startSignIn();
113 $('create-profile-supervised-sign-in-again-link').onclick
=
115 if (!loadTimeData
.getBoolean('newAvatarMenuEnabled'))
116 PageManager
.closeOverlay();
117 SyncSetupOverlay
.showSetupUI();
120 $('import-existing-supervised-user-link').onclick = function(event
) {
121 // Hide the import button to trigger a cursor update. The import button
122 // is shown again when the import overlay loads. TODO(akuegel): Remove
123 // this temporary fix when crbug/246304 is resolved.
124 $('import-existing-supervised-user-link').hidden
= true;
125 PageManager
.showPageByName('supervisedUserImport');
130 didShowPage: function() {
131 chrome
.send('requestDefaultProfileIcons', ['manage']);
133 // Just ignore the manage profile dialog on Chrome OS, they use /accounts.
134 if (!cr
.isChromeOS
&& window
.location
.pathname
== '/manageProfile')
135 ManageProfileOverlay
.getInstance().prepareForManageDialog_();
137 // When editing a profile, initially hide the "add shortcut" and
138 // "remove shortcut" buttons and ask the handler which to show. It will
139 // call |receiveHasProfileShortcuts|, which will show the appropriate one.
140 $('remove-shortcut-button').hidden
= true;
141 $('add-shortcut-button').hidden
= true;
143 if (loadTimeData
.getBoolean('profileShortcutsEnabled')) {
144 var profileInfo
= ManageProfileOverlay
.getInstance().profileInfo_
;
145 chrome
.send('requestHasProfileShortcuts', [profileInfo
.filePath
]);
148 var manageNameField
= $('manage-profile-name');
149 // Legacy supervised users cannot edit their names.
150 if (manageNameField
.disabled
)
151 $('manage-profile-ok').focus();
153 manageNameField
.focus();
155 this.profileNameIsDefault_
= false;
159 * Registers event handlers that are common between create and manage modes.
160 * @param {string} mode A label that specifies the type of dialog box which
161 * is currently being viewed (i.e. 'create' or 'manage').
162 * @param {function()} submitFunction The function that should be called
163 * when the user chooses to submit (e.g. by clicking the OK button).
166 registerCommonEventHandlers_: function(mode
, submitFunction
) {
168 $(mode
+ '-profile-icon-grid').addEventListener('change', function(e
) {
169 self
.onIconGridSelectionChanged_(mode
);
171 $(mode
+ '-profile-name').oninput = function(event
) {
172 self
.onNameChanged_(mode
);
174 $(mode
+ '-profile-ok').onclick = function(event
) {
175 PageManager
.closeOverlay();
181 * Set the profile info used in the dialog.
182 * @param {Object} profileInfo An object of the form:
184 * name: "Profile Name",
185 * iconURL: "chrome://path/to/icon/image",
186 * filePath: "/path/to/profile/data/on/disk",
187 * isCurrentProfile: false,
188 * isSupervised: false
190 * @param {string} mode A label that specifies the type of dialog box which
191 * is currently being viewed (i.e. 'create' or 'manage').
194 setProfileInfo_: function(profileInfo
, mode
) {
195 this.iconGridSelectedURL_
= profileInfo
.iconURL
;
196 this.profileInfo_
= profileInfo
;
197 $(mode
+ '-profile-name').value
= profileInfo
.name
;
198 $(mode
+ '-profile-icon-grid').selectedItem
= profileInfo
.iconURL
;
202 * Sets the name of the profile being edited or created.
203 * @param {string} name New profile name.
204 * @param {string} mode A label that specifies the type of dialog box which
205 * is currently being viewed (i.e. 'create' or 'manage').
208 setProfileName_: function(name
, mode
) {
209 if (this.profileInfo_
)
210 this.profileInfo_
.name
= name
;
211 $(mode
+ '-profile-name').value
= name
;
215 * Set an array of default icon URLs. These will be added to the grid that
216 * the user will use to choose their profile icon.
217 * @param {string} mode A label that specifies the type of dialog box which
218 * is currently being viewed (i.e. 'create' or 'manage').
219 * @param {!Array<string>} iconURLs An array of icon URLs.
220 * @param {Array<string>} names An array of default names
221 * corresponding to the icons.
224 receiveDefaultProfileIconsAndNames_: function(mode
, iconURLs
, names
) {
225 this.defaultProfileNames_
= names
;
227 var grid
= $(mode
+ '-profile-icon-grid');
229 grid
.dataModel
= new ArrayDataModel(iconURLs
);
231 if (this.profileInfo_
)
232 grid
.selectedItem
= this.profileInfo_
.iconURL
;
234 // Recalculate the measured item size.
235 grid
.measured_
= null;
241 * Callback to set the initial values when creating a new profile.
242 * @param {Object} profileInfo An object of the form:
244 * name: "Profile Name",
245 * iconURL: "chrome://path/to/icon/image",
249 receiveNewProfileDefaults_: function(profileInfo
) {
250 ManageProfileOverlay
.setProfileInfo(profileInfo
, 'create');
251 this.profileNameIsDefault_
= true;
252 $('create-profile-name-label').hidden
= false;
253 $('create-profile-name').hidden
= false;
254 // Trying to change the focus if this isn't the topmost overlay can
255 // instead cause the FocusManager to override another overlay's focus,
256 // e.g. if an overlay above this one is in the process of being reloaded.
257 // But the C++ handler calls this method directly on ManageProfileOverlay,
258 // so check the pageDiv to also include its subclasses (in particular
259 // CreateProfileOverlay, which has higher sub-overlays).
260 if (PageManager
.getTopmostVisiblePage().pageDiv
== this.pageDiv
) {
261 // This will only have an effect if the 'create-profile-name' element
262 // is visible, i.e. if the overlay is in create mode.
263 $('create-profile-name').focus();
265 $('create-profile-ok').disabled
= false;
269 * Set a dictionary of all profile names. These are used to prevent the
270 * user from naming two profiles the same.
271 * @param {Object} profileNames A dictionary of profile names.
274 receiveExistingProfileNames_: function(profileNames
) {
275 this.existingProfileNames_
= profileNames
;
279 * Callback to show the add/remove shortcut buttons when in edit mode,
280 * called by the handler as a result of the 'requestHasProfileShortcuts_'
282 * @param {boolean} hasShortcuts Whether profile has any existing shortcuts.
285 receiveHasProfileShortcuts_: function(hasShortcuts
) {
286 $('add-shortcut-button').hidden
= hasShortcuts
;
287 $('remove-shortcut-button').hidden
= !hasShortcuts
;
291 * Display the error bubble, with |errorHtml| in the bubble.
292 * @param {string} errorHtml The html string to display as an error.
293 * @param {string} mode A label that specifies the type of dialog box which
294 * is currently being viewed (i.e. 'create' or 'manage').
295 * @param {boolean} disableOKButton True if the dialog's OK button should be
296 * disabled when the error bubble is shown. It will be (re-)enabled when
297 * the error bubble is hidden.
300 showErrorBubble_: function(errorHtml
, mode
, disableOKButton
) {
301 var nameErrorEl
= $(mode
+ '-profile-error-bubble');
302 nameErrorEl
.hidden
= false;
303 nameErrorEl
.innerHTML
= errorHtml
;
306 $(mode
+ '-profile-ok').disabled
= true;
310 * Hide the error bubble.
311 * @param {string} mode A label that specifies the type of dialog box which
312 * is currently being viewed (i.e. 'create' or 'manage').
315 hideErrorBubble_: function(mode
) {
316 $(mode
+ '-profile-error-bubble').innerHTML
= '';
317 $(mode
+ '-profile-error-bubble').hidden
= true;
318 $(mode
+ '-profile-ok').disabled
= false;
322 * oninput callback for <input> field.
323 * @param {string} mode A label that specifies the type of dialog box which
324 * is currently being viewed (i.e. 'create' or 'manage').
327 onNameChanged_: function(mode
) {
328 this.profileNameIsDefault_
= false;
329 this.updateCreateOrImport_(mode
);
333 * Called when the profile name is changed or the 'create supervised'
334 * checkbox is toggled. Updates the 'ok' button and the 'import existing
335 * supervised user' link.
336 * @param {string} mode A label that specifies the type of dialog box which
337 * is currently being viewed (i.e. 'create' or 'manage').
340 updateCreateOrImport_: function(mode
) {
341 this.updateOkButton_(mode
);
342 // In 'create' mode, check for existing supervised users with the same
344 if (mode
== 'create')
345 this.requestExistingSupervisedUsers_();
349 * Tries to get the list of existing supervised users and updates the UI
353 requestExistingSupervisedUsers_: function() {
354 options
.SupervisedUserListData
.requestExistingSupervisedUsers().then(
355 this.receiveExistingSupervisedUsers_
.bind(this),
356 this.onSigninError_
.bind(this));
360 * @param {Object} supervisedUser
361 * @param {boolean} nameIsUnique
363 getImportHandler_: function(supervisedUser
, nameIsUnique
) {
365 if (supervisedUser
.needAvatar
|| !nameIsUnique
) {
366 PageManager
.showPageByName('supervisedUserImport');
368 this.hideErrorBubble_('create');
369 CreateProfileOverlay
.updateCreateInProgress(true);
370 chrome
.send('createProfile',
371 [supervisedUser
.name
, supervisedUser
.iconURL
, false, true,
378 * Callback which receives the list of existing supervised users. Checks if
379 * the currently entered name is the name of an already existing supervised
380 * user. If yes, the user is prompted to import the existing supervised
381 * user, and the create button is disabled.
382 * If the received list is empty, hides the "import" link.
383 * @param {Array<Object>} supervisedUsers The list of existing supervised
387 receiveExistingSupervisedUsers_: function(supervisedUsers
) {
388 $('import-existing-supervised-user-link').hidden
=
389 supervisedUsers
.length
=== 0;
390 if (!$('create-profile-supervised').checked
)
393 var newName
= $('create-profile-name').value
;
395 for (i
= 0; i
< supervisedUsers
.length
; ++i
) {
396 if (supervisedUsers
[i
].name
== newName
&&
397 !supervisedUsers
[i
].onCurrentDevice
) {
398 var errorHtml
= loadTimeData
.getStringF(
399 'manageProfilesExistingSupervisedUser',
400 HTMLEscape(elide(newName
, /* maxLength */ 50)));
401 this.showErrorBubble_(errorHtml
, 'create', true);
403 // Check if another supervised user also exists with that name.
404 var nameIsUnique
= true;
406 for (j
= i
+ 1; j
< supervisedUsers
.length
; ++j
) {
407 if (supervisedUsers
[j
].name
== newName
) {
408 nameIsUnique
= false;
412 $('supervised-user-import-existing').onclick
=
413 this.getImportHandler_(supervisedUsers
[i
], nameIsUnique
);
414 $('create-profile-ok').disabled
= true;
421 * Called in case the request for the list of supervised users fails because
425 onSigninError_: function() {
426 this.updateSignedInStatus(this.signedInEmail_
, true);
430 * Called to update the state of the ok button depending if the name is
431 * already used or not.
432 * @param {string} mode A label that specifies the type of dialog box which
433 * is currently being viewed (i.e. 'create' or 'manage').
436 updateOkButton_: function(mode
) {
437 var oldName
= this.profileInfo_
.name
;
438 var newName
= $(mode
+ '-profile-name').value
;
439 this.hideErrorBubble_(mode
);
441 var nameIsValid
= $(mode
+ '-profile-name').validity
.valid
;
442 $(mode
+ '-profile-ok').disabled
= !nameIsValid
;
446 * Called when the user clicks "OK" or hits enter. Saves the newly changed
450 submitManageChanges_: function() {
451 var name
= $('manage-profile-name').value
;
452 var iconURL
= $('manage-profile-icon-grid').selectedItem
;
454 chrome
.send('setProfileIconAndName',
455 [this.profileInfo_
.filePath
, iconURL
, name
]);
456 if (name
!= this.profileInfo_
.name
)
457 options
.SupervisedUserListData
.resetPromise();
461 * Abstract method. Should be overriden in subclasses.
462 * @param {string} email
463 * @param {boolean} hasError
466 updateSignedInStatus: function(email
, hasError
) {
467 // TODO: Fix triggering the assert, crbug.com/423267
468 // assertNotReached();
472 * Called when the user clicks "OK" or hits enter. Creates the profile
473 * using the information in the dialog.
476 submitCreateProfile_: function() {
477 // This is visual polish: the UI to access this should be disabled for
478 // supervised users, and the back end will prevent user creation anyway.
479 if (this.profileInfo_
&& this.profileInfo_
.isSupervised
)
482 this.hideErrorBubble_('create');
483 CreateProfileOverlay
.updateCreateInProgress(true);
485 // Get the user's chosen name and icon, or default if they do not
486 // wish to customize their profile.
487 var name
= $('create-profile-name').value
;
488 var iconUrl
= $('create-profile-icon-grid').selectedItem
;
489 var createShortcut
= $('create-shortcut').checked
;
490 var isSupervised
= $('create-profile-supervised').checked
;
491 var existingSupervisedUserId
= '';
493 // 'createProfile' is handled by the CreateProfileHandler.
494 chrome
.send('createProfile',
495 [name
, iconUrl
, createShortcut
,
496 isSupervised
, existingSupervisedUserId
]);
500 * Called when the selected icon in the icon grid changes.
501 * @param {string} mode A label that specifies the type of dialog box which
502 * is currently being viewed (i.e. 'create' or 'manage').
505 onIconGridSelectionChanged_: function(mode
) {
506 var iconURL
= $(mode
+ '-profile-icon-grid').selectedItem
;
507 if (!iconURL
|| iconURL
== this.iconGridSelectedURL_
)
509 this.iconGridSelectedURL_
= iconURL
;
510 if (this.profileNameIsDefault_
) {
511 var index
= $(mode
+ '-profile-icon-grid').selectionModel
.selectedIndex
;
512 var name
= this.defaultProfileNames_
[index
];
514 this.setProfileName_(name
, mode
);
515 this.updateCreateOrImport_(mode
);
518 if (this.profileInfo_
&& this.profileInfo_
.filePath
) {
519 chrome
.send('profileIconSelectionChanged',
520 [this.profileInfo_
.filePath
, iconURL
]);
525 * Updates the contents of the "Manage Profile" section of the dialog,
526 * and shows that section.
529 prepareForManageDialog_: function() {
530 chrome
.send('refreshGaiaPicture');
531 var profileInfo
= BrowserOptions
.getCurrentProfile();
532 ManageProfileOverlay
.setProfileInfo(profileInfo
, 'manage');
533 $('manage-profile-overlay-create').hidden
= true;
534 $('manage-profile-overlay-manage').hidden
= false;
535 $('manage-profile-overlay-delete').hidden
= true;
536 $('manage-profile-overlay-disconnect-managed').hidden
= true;
537 $('manage-profile-name').disabled
=
538 profileInfo
.isSupervised
&& !profileInfo
.isChild
;
539 this.hideErrorBubble_('manage');
543 * Display the "Manage Profile" dialog.
544 * @param {boolean=} opt_updateHistory If we should update the history after
545 * showing the dialog (defaults to true).
548 showManageDialog_: function(opt_updateHistory
) {
549 var updateHistory
= opt_updateHistory
!== false;
550 this.prepareForManageDialog_();
551 PageManager
.showPageByName('manageProfile', updateHistory
);
555 * Display the "Delete Profile" dialog.
556 * @param {Object} profileInfo The profile object of the profile to delete.
559 showDeleteDialog_: function(profileInfo
) {
560 ManageProfileOverlay
.setProfileInfo(profileInfo
, 'manage');
561 $('manage-profile-overlay-create').hidden
= true;
562 $('manage-profile-overlay-manage').hidden
= true;
563 $('manage-profile-overlay-delete').hidden
= false;
564 $('manage-profile-overlay-disconnect-managed').hidden
= true;
565 $('delete-profile-icon').style
.content
=
566 getProfileAvatarIcon(profileInfo
.iconURL
);
567 $('delete-profile-text').textContent
=
568 loadTimeData
.getStringF('deleteProfileMessage',
569 elide(profileInfo
.name
, /* maxLength */ 50));
570 $('delete-supervised-profile-addendum').hidden
=
571 !profileInfo
.isSupervised
|| profileInfo
.isChild
;
573 // Because this dialog isn't useful when refreshing or as part of the
574 // history, don't create a history entry for it when showing.
575 PageManager
.showPageByName('manageProfile', false);
576 chrome
.send('logDeleteUserDialogShown');
580 * Display the "Disconnect Managed Profile" dialog.
583 showDisconnectManagedProfileDialog_: function(replacements
) {
584 loadTimeData
.overrideValues(replacements
);
585 $('manage-profile-overlay-create').hidden
= true;
586 $('manage-profile-overlay-manage').hidden
= true;
587 $('manage-profile-overlay-delete').hidden
= true;
588 $('disconnect-managed-profile-domain-information').innerHTML
=
589 loadTimeData
.getString('disconnectManagedProfileDomainInformation');
590 $('disconnect-managed-profile-text').innerHTML
=
591 loadTimeData
.getString('disconnectManagedProfileText');
592 $('manage-profile-overlay-disconnect-managed').hidden
= false;
594 // Because this dialog isn't useful when refreshing or as part of the
595 // history, don't create a history entry for it when showing.
596 PageManager
.showPageByName('manageProfile', false);
600 * Display the "Create Profile" dialog.
603 showCreateDialog_: function() {
604 PageManager
.showPageByName('createProfile');
608 // Forward public APIs to private implementations.
609 cr
.makePublic(ManageProfileOverlay
, [
610 'receiveDefaultProfileIconsAndNames',
611 'receiveNewProfileDefaults',
612 'receiveExistingProfileNames',
613 'receiveHasProfileShortcuts',
618 'showDisconnectManagedProfileDialog',
622 function CreateProfileOverlay() {
623 Page
.call(this, 'createProfile',
624 loadTimeData
.getString('createProfileTabTitle'),
625 'manage-profile-overlay');
628 cr
.addSingletonGetter(CreateProfileOverlay
);
630 CreateProfileOverlay
.prototype = {
631 // Inherit from ManageProfileOverlay.
632 __proto__
: ManageProfileOverlay
.prototype,
634 // The signed-in email address of the current profile, or empty if they're
639 canShowPage: function() {
640 return !BrowserOptions
.getCurrentProfile().isSupervised
;
644 * Configures the overlay to the "create user" mode.
647 didShowPage: function() {
648 chrome
.send('requestCreateProfileUpdate');
649 chrome
.send('requestDefaultProfileIcons', ['create']);
650 chrome
.send('requestNewProfileDefaults');
652 $('manage-profile-overlay-create').hidden
= false;
653 $('manage-profile-overlay-manage').hidden
= true;
654 $('manage-profile-overlay-delete').hidden
= true;
655 $('manage-profile-overlay-disconnect-managed').hidden
= true;
656 $('create-profile-instructions').textContent
=
657 loadTimeData
.getStringF('createProfileInstructions');
658 this.hideErrorBubble_();
659 this.updateCreateInProgress_(false);
661 var shortcutsEnabled
= loadTimeData
.getBoolean('profileShortcutsEnabled');
662 $('create-shortcut-container').hidden
= !shortcutsEnabled
;
663 $('create-shortcut').checked
= shortcutsEnabled
;
665 $('create-profile-name-label').hidden
= true;
666 $('create-profile-name').hidden
= true;
667 $('create-profile-ok').disabled
= true;
669 $('create-profile-supervised').checked
= false;
670 $('import-existing-supervised-user-link').hidden
= true;
671 $('create-profile-supervised').onchange = function() {
672 ManageProfileOverlay
.getInstance().updateCreateOrImport_('create');
674 $('create-profile-supervised').hidden
= true;
675 $('create-profile-supervised-signed-in').disabled
= true;
676 $('create-profile-supervised-signed-in').hidden
= true;
677 $('create-profile-supervised-not-signed-in').hidden
= true;
679 this.profileNameIsDefault_
= false;
683 handleCancel: function() {
684 this.cancelCreateProfile_();
688 showErrorBubble_: function(errorHtml
) {
689 ManageProfileOverlay
.getInstance().showErrorBubble_(errorHtml
,
695 hideErrorBubble_: function() {
696 ManageProfileOverlay
.getInstance().hideErrorBubble_('create');
700 * Updates the UI when a profile create step begins or ends.
701 * Note that hideErrorBubble_() also enables the "OK" button, so it
702 * must be called before this function if both are used.
703 * @param {boolean} inProgress True if the UI should be updated to show that
704 * profile creation is now in progress.
707 updateCreateInProgress_: function(inProgress
) {
708 this.createInProgress_
= inProgress
;
709 this.updateCreateSupervisedUserCheckbox_();
711 $('create-profile-icon-grid').disabled
= inProgress
;
712 $('create-profile-name').disabled
= inProgress
;
713 $('create-shortcut').disabled
= inProgress
;
714 $('create-profile-ok').disabled
= inProgress
;
715 $('import-existing-supervised-user-link').disabled
= inProgress
;
717 $('create-profile-throbber').hidden
= !inProgress
;
721 * Cancels the creation of the a profile. It is safe to call this even
722 * when no profile is in the process of being created.
725 cancelCreateProfile_: function() {
726 PageManager
.closeOverlay();
727 chrome
.send('cancelCreateProfile');
728 this.hideErrorBubble_();
729 this.updateCreateInProgress_(false);
733 * Shows an error message describing an error that occurred while creating
735 * Called by BrowserOptions via the BrowserOptionsHandler.
736 * @param {string} error The error message to display.
739 onError_: function(error
) {
740 this.updateCreateInProgress_(false);
741 this.showErrorBubble_(error
);
745 * Shows a warning message giving information while creating a new profile.
746 * Called by BrowserOptions via the BrowserOptionsHandler.
747 * @param {string} warning The warning message to display.
750 onWarning_: function(warning
) {
751 this.showErrorBubble_(warning
);
755 * For new supervised users, shows a confirmation page after successfully
756 * creating a new profile; otherwise, the handler will open a new window.
757 * @param {Object} profileInfo An object of the form:
759 * name: "Profile Name",
760 * filePath: "/path/to/profile/data/on/disk"
761 * isSupervised: (true|false),
765 onSuccess_: function(profileInfo
) {
766 this.updateCreateInProgress_(false);
767 PageManager
.closeOverlay();
768 if (profileInfo
.isSupervised
) {
769 options
.SupervisedUserListData
.resetPromise();
770 profileInfo
.custodianEmail
= this.signedInEmail_
;
771 SupervisedUserCreateConfirmOverlay
.setProfileInfo(profileInfo
);
772 PageManager
.showPageByName('supervisedUserCreateConfirm', false);
773 BrowserOptions
.updateManagesSupervisedUsers(true);
778 * @param {string} email
779 * @param {boolean} hasError
782 updateSignedInStatus: function(email
, hasError
) {
783 this.updateSignedInStatus_(email
, hasError
);
787 * Updates the signed-in or not-signed-in UI when in create mode. Called by
788 * the handler in response to the 'requestCreateProfileUpdate' message.
789 * updateSupervisedUsersAllowed_ is expected to be called after this is, and
790 * will update additional UI elements.
791 * @param {string} email The email address of the currently signed-in user.
792 * An empty string indicates that the user is not signed in.
793 * @param {boolean} hasError Whether the user's sign-in credentials are
797 updateSignedInStatus_: function(email
, hasError
) {
798 this.signedInEmail_
= email
;
799 this.hasError_
= hasError
;
800 var isSignedIn
= email
!== '';
801 $('create-profile-supervised').hidden
= !isSignedIn
;
802 $('create-profile-supervised-signed-in').hidden
= !isSignedIn
;
803 $('create-profile-supervised-not-signed-in').hidden
= isSignedIn
;
806 var accountDetailsOutOfDate
=
807 $('create-profile-supervised-account-details-out-of-date-label');
808 accountDetailsOutOfDate
.textContent
= loadTimeData
.getStringF(
809 'manageProfilesSupervisedAccountDetailsOutOfDate', email
);
810 accountDetailsOutOfDate
.hidden
= !hasError
;
812 $('create-profile-supervised-signed-in-label').textContent
=
813 loadTimeData
.getStringF(
814 'manageProfilesSupervisedSignedInLabel', email
);
815 $('create-profile-supervised-signed-in-label').hidden
= hasError
;
817 $('create-profile-supervised-sign-in-again-link').hidden
= !hasError
;
818 $('create-profile-supervised-signed-in-learn-more-link').hidden
=
822 this.updateCreateSupervisedUserCheckbox_();
823 // If we're signed in, showing/hiding import-existing-supervised-user-link
824 // is handled in receiveExistingSupervisedUsers_.
825 if (isSignedIn
&& !hasError
)
826 this.requestExistingSupervisedUsers_();
828 $('import-existing-supervised-user-link').hidden
= true;
832 * Sets whether creating supervised users is allowed or not. Called by the
833 * handler in response to the 'requestCreateProfileUpdate' message or a
834 * change in the (policy-controlled) pref that prohibits creating supervised
835 * users, after the signed-in status has been updated.
836 * @param {boolean} allowed True if creating supervised users should be
840 updateSupervisedUsersAllowed_: function(allowed
) {
841 this.supervisedUsersAllowed_
= allowed
;
842 this.updateCreateSupervisedUserCheckbox_();
844 $('create-profile-supervised-sign-in-link').enabled
= allowed
;
846 $('create-profile-supervised-indicator').setAttribute('controlled-by',
849 $('create-profile-supervised-indicator').removeAttribute(
855 * Updates the status of the "create supervised user" checkbox. Called from
856 * updateSupervisedUsersAllowed_() or updateCreateInProgress_().
857 * updateSignedInStatus_() does not call this method directly, because it
858 * will be followed by a call to updateSupervisedUsersAllowed_().
861 updateCreateSupervisedUserCheckbox_: function() {
862 $('create-profile-supervised').disabled
=
863 !this.supervisedUsersAllowed_
|| this.createInProgress_
||
864 this.signedInEmail_
== '' || this.hasError_
;
868 // Forward public APIs to private implementations.
869 cr
.makePublic(CreateProfileOverlay
, [
870 'cancelCreateProfile',
874 'updateCreateInProgress',
875 'updateSignedInStatus',
876 'updateSupervisedUsersAllowed',
881 ManageProfileOverlay
: ManageProfileOverlay
,
882 CreateProfileOverlay
: CreateProfileOverlay
,