// Info about the currently managed/deleted profile.
profileInfo_: null,
- // An object containing all known profile names.
- profileNames_: {},
+ // Whether the currently chosen name for a new profile was assigned
+ // automatically by choosing an avatar. Set on receiveNewProfileDefaults;
+ // cleared on first edit (in onNameChanged_).
+ profileNameIsDefault_: false,
+
+ // List of default profile names corresponding to the respective icons.
+ defaultProfileNames_: [],
+
+ // An object containing all names of existing profiles.
+ existingProfileNames_: {},
// The currently selected icon in the icon grid.
iconGridSelectedURL_: null,
};
$('manage-profile-cancel').onclick =
+ $('disconnect-managed-profile-cancel').onclick =
$('delete-profile-cancel').onclick = function(event) {
OptionsPage.closeOverlay();
};
chrome.send('removeProfileShortcut', [self.profileInfo_.filePath]);
};
+ $('disconnect-managed-profile-ok').onclick = function(event) {
+ OptionsPage.closeOverlay();
+ chrome.send('deleteProfile',
+ [BrowserOptions.getCurrentProfile().filePath]);
+ }
+
$('create-profile-managed-signed-in-learn-more-link').onclick =
function(event) {
OptionsPage.navigateToPage('managedUserLearnMore');
};
$('import-existing-managed-user-link').onclick = function(event) {
+ // Hide the import button to trigger a cursor update. The import button
+ // is shown again when the import overlay loads. TODO(akuegel): Remove
+ // this temporary fix when crbug/246304 is resolved.
+ $('import-existing-managed-user-link').hidden = true;
OptionsPage.navigateToPage('managedUserImport');
};
},
/** @override */
didShowPage: function() {
- chrome.send('requestDefaultProfileIcons');
+ chrome.send('requestDefaultProfileIcons', ['manage']);
// Just ignore the manage profile dialog on Chrome OS, they use /accounts.
if (!cr.isChromeOS && window.location.pathname == '/manageProfile')
$('manage-profile-ok').focus();
else
manageNameField.focus();
+
+ this.profileNameIsDefault_ = false;
},
/**
},
/**
- * Sets the name of the currently edited profile.
+ * Sets the name of the profile being edited or created.
+ * @param {string} name New profile name.
+ * @param {string} mode A label that specifies the type of dialog box which
+ * is currently being viewed (i.e. 'create' or 'manage').
* @private
*/
- setProfileName_: function(name) {
+ setProfileName_: function(name, mode) {
if (this.profileInfo_)
this.profileInfo_.name = name;
- $('manage-profile-name').value = name;
+ $(mode + '-profile-name').value = name;
},
/**
* Set an array of default icon URLs. These will be added to the grid that
* the user will use to choose their profile icon.
+ * @param {string} mode A label that specifies the type of dialog box which
+ * is currently being viewed (i.e. 'create' or 'manage').
* @param {Array.<string>} iconURLs An array of icon URLs.
+ * @param {Array.<string>} names An array of default names
+ * corresponding to the icons.
* @private
*/
- receiveDefaultProfileIcons_: function(iconGrid, iconURLs) {
- $(iconGrid).dataModel = new ArrayDataModel(iconURLs);
+ receiveDefaultProfileIconsAndNames_: function(mode, iconURLs, names) {
+ this.defaultProfileNames_ = names;
+
+ var grid = $(mode + '-profile-icon-grid');
+
+ grid.dataModel = new ArrayDataModel(iconURLs);
if (this.profileInfo_)
- $(iconGrid).selectedItem = this.profileInfo_.iconURL;
+ grid.selectedItem = this.profileInfo_.iconURL;
- var grid = $(iconGrid);
// Recalculate the measured item size.
grid.measured_ = null;
grid.columns = 0;
*/
receiveNewProfileDefaults_: function(profileInfo) {
ManageProfileOverlay.setProfileInfo(profileInfo, 'create');
+ this.profileNameIsDefault_ = true;
$('create-profile-name-label').hidden = false;
$('create-profile-name').hidden = false;
// Trying to change the focus if this isn't the topmost overlay can
* @param {Object} profileNames A dictionary of profile names.
* @private
*/
- receiveProfileNames_: function(profileNames) {
- this.profileNames_ = profileNames;
+ receiveExistingProfileNames_: function(profileNames) {
+ this.existingProfileNames_ = profileNames;
},
/**
* @private
*/
onNameChanged_: function(mode) {
- var newName = $(mode + '-profile-name').value;
- var oldName = this.profileInfo_.name;
+ this.profileNameIsDefault_ = false;
+ this.updateCreateOrImport_(mode);
+ },
- // In 'create' mode, the initial name can be the name of an already
- // existing supervised user.
- if (newName == oldName && mode == 'manage') {
- this.hideErrorBubble_(mode);
- } else if (mode == 'create' &&
- loadTimeData.getBoolean('allowCreateExistingManagedUsers') &&
- $('create-profile-managed').checked) {
+ /**
+ * Called when the profile name is changed or the 'create managed' checkbox
+ * is toggled. Updates the 'ok' button and the 'import existing supervised
+ * user' link.
+ * @param {string} mode A label that specifies the type of dialog box which
+ * is currently being viewed (i.e. 'create' or 'manage').
+ * @private
+ */
+ updateCreateOrImport_: function(mode) {
+ // In 'create' mode, check for existing managed users with the same name.
+ if (mode == 'create' && $('create-profile-managed').checked) {
options.ManagedUserListData.requestExistingManagedUsers().then(
this.receiveExistingManagedUsers_.bind(this),
this.onSigninError_.bind(this));
break;
}
}
+ var self = this;
function getImportHandler(managedUser, nameIsUnique) {
return function() {
if (managedUser.needAvatar || !nameIsUnique) {
OptionsPage.navigateToPage('managedUserImport');
} else {
+ self.hideErrorBubble_('create');
+ CreateProfileOverlay.updateCreateInProgress(true);
chrome.send('createProfile',
[managedUser.name, managedUser.iconURL, false, true,
managedUser.id]);
* @private
*/
updateOkButton_: function(mode) {
+ var oldName = this.profileInfo_.name;
var newName = $(mode + '-profile-name').value;
- if (this.profileNames_[newName] != undefined) {
+ var nameIsDuplicate = this.existingProfileNames_[newName] != undefined;
+ if (mode == 'manage' && oldName == newName)
+ nameIsDuplicate = false;
+ if (nameIsDuplicate) {
var errorHtml =
loadTimeData.getString('manageProfilesDuplicateNameError');
this.showErrorBubble_(errorHtml, mode, true);
if (!iconURL || iconURL == this.iconGridSelectedURL_)
return;
this.iconGridSelectedURL_ = iconURL;
+ if (this.profileNameIsDefault_) {
+ var index = $(mode + '-profile-icon-grid').selectionModel.selectedIndex;
+ var name = this.defaultProfileNames_[index];
+ if (name) {
+ this.setProfileName_(name, mode);
+ }
+ }
if (this.profileInfo_ && this.profileInfo_.filePath) {
chrome.send('profileIconSelectionChanged',
[this.profileInfo_.filePath, iconURL]);
$('manage-profile-overlay-create').hidden = true;
$('manage-profile-overlay-manage').hidden = false;
$('manage-profile-overlay-delete').hidden = true;
+ $('manage-profile-overlay-disconnect-managed').hidden = true;
$('manage-profile-name').disabled = profileInfo.isManaged;
this.hideErrorBubble_('manage');
},
$('manage-profile-overlay-create').hidden = true;
$('manage-profile-overlay-manage').hidden = true;
$('manage-profile-overlay-delete').hidden = false;
+ $('manage-profile-overlay-disconnect-managed').hidden = true;
$('delete-profile-icon').style.content =
- imageset(profileInfo.iconURL + '@scalefactorx');
+ getProfileAvatarIcon(profileInfo.iconURL);
$('delete-profile-text').textContent =
loadTimeData.getStringF('deleteProfileMessage',
elide(profileInfo.name, /* maxLength */ 50));
},
/**
+ * Display the "Disconnect Managed Profile" dialog.
+ * @private
+ */
+ showDisconnectManagedProfileDialog_: function() {
+ $('manage-profile-overlay-create').hidden = true;
+ $('manage-profile-overlay-manage').hidden = true;
+ $('manage-profile-overlay-delete').hidden = true;
+ $('disconnect-managed-profile-domain-information').innerHTML =
+ loadTimeData.getString('disconnectManagedProfileDomainInformation');
+ $('disconnect-managed-profile-text').innerHTML =
+ loadTimeData.getString('disconnectManagedProfileText');
+ $('manage-profile-overlay-disconnect-managed').hidden = false;
+
+ // Because this dialog isn't useful when refreshing or as part of the
+ // history, don't create a history entry for it when showing.
+ OptionsPage.showPageByName('manageProfile', false);
+ },
+
+ /**
* Display the "Create Profile" dialog.
* @private
*/
// Forward public APIs to private implementations.
[
- 'receiveDefaultProfileIcons',
+ 'receiveDefaultProfileIconsAndNames',
'receiveNewProfileDefaults',
- 'receiveProfileNames',
+ 'receiveExistingProfileNames',
'receiveHasProfileShortcuts',
'setProfileInfo',
'setProfileName',
'showManageDialog',
'showDeleteDialog',
+ 'showDisconnectManagedProfileDialog',
'showCreateDialog',
].forEach(function(name) {
ManageProfileOverlay[name] = function() {
*/
didShowPage: function() {
chrome.send('requestCreateProfileUpdate');
- chrome.send('requestDefaultProfileIcons');
+ chrome.send('requestDefaultProfileIcons', ['create']);
chrome.send('requestNewProfileDefaults');
$('manage-profile-overlay-create').hidden = false;
$('manage-profile-overlay-manage').hidden = true;
$('manage-profile-overlay-delete').hidden = true;
+ $('manage-profile-overlay-disconnect-managed').hidden = true;
$('create-profile-instructions').textContent =
loadTimeData.getStringF('createProfileInstructions');
this.hideErrorBubble_();
$('create-profile-ok').disabled = true;
$('create-profile-managed').checked = false;
- if (loadTimeData.getBoolean('allowCreateExistingManagedUsers')) {
- $('import-existing-managed-user-link').hidden = false;
- $('create-profile-managed').onchange = function() {
- ManageProfileOverlay.getInstance().onNameChanged_('create');
- };
- }
+ $('import-existing-managed-user-link').hidden = true;
+ $('create-profile-managed').onchange = function() {
+ ManageProfileOverlay.getInstance().updateCreateOrImport_('create');
+ };
$('create-profile-managed-signed-in').disabled = true;
$('create-profile-managed-signed-in').hidden = true;
$('create-profile-managed-not-signed-in').hidden = true;
+
+ this.profileNameIsDefault_ = false;
},
/** @override */
$('create-profile-name').disabled = inProgress;
$('create-shortcut').disabled = inProgress;
$('create-profile-ok').disabled = inProgress;
+ $('import-existing-managed-user-link').disabled = inProgress;
$('create-profile-throbber').hidden = !inProgress;
},
*/
updateImportExistingManagedUserLink_: function(enable) {
var importManagedUserElement = $('import-existing-managed-user-link');
- importManagedUserElement.disabled = !enable;
+ importManagedUserElement.hidden = false;
+ importManagedUserElement.disabled = !enable || this.createInProgress_;
importManagedUserElement.textContent = enable ?
loadTimeData.getString('importExistingManagedUserLink') :
loadTimeData.getString('signInToImportManagedUsers');