| Index: chrome/browser/resources/md_user_manager/create_profile.js
|
| diff --git a/chrome/browser/resources/md_user_manager/create_profile.js b/chrome/browser/resources/md_user_manager/create_profile.js
|
| index c49d5f52318602c13429a637e76780316e52c346..a6172ee7849fe6e4d0716d33f7b5b7966526f88e 100644
|
| --- a/chrome/browser/resources/md_user_manager/create_profile.js
|
| +++ b/chrome/browser/resources/md_user_manager/create_profile.js
|
| @@ -11,26 +11,19 @@
|
| Polymer({
|
| is: 'create-profile',
|
|
|
| - behaviors: [WebUIListenerBehavior],
|
| + behaviors: [
|
| + I18nBehavior,
|
| + WebUIListenerBehavior
|
| + ],
|
|
|
| properties: {
|
| /**
|
| - * True if supervised user checkbox is disabled.
|
| - * @private {boolean}
|
| - */
|
| - supervisedUserCheckboxDisabled_: {
|
| - type: Boolean,
|
| - computed:
|
| - 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)'
|
| - },
|
| -
|
| - /**
|
| * The current profile name.
|
| * @private {string}
|
| */
|
| profileName_: {
|
| type: String,
|
| - value: '',
|
| + value: ''
|
| },
|
|
|
| /**
|
| @@ -91,9 +84,9 @@ Polymer({
|
| * Index of the selected signed-in user.
|
| * @private {number}
|
| */
|
| - selectedEmail_: {
|
| + signedInUserIndex_: {
|
| type: Number,
|
| - value: 0
|
| + value: -1 // -1 selects the sentinel item. It means no user is selected.
|
| },
|
|
|
| /** @private {!signin.ProfileBrowserProxy} */
|
| @@ -106,9 +99,7 @@ Polymer({
|
| },
|
|
|
| /** @override */
|
| - attached: function() {
|
| - this.resetForm_();
|
| -
|
| + ready: function() {
|
| this.addWebUIListener(
|
| 'create-profile-success', this.handleSuccess_.bind(this));
|
| this.addWebUIListener(
|
| @@ -118,6 +109,8 @@ Polymer({
|
| this.addWebUIListener(
|
| 'profile-icons-received', this.handleProfileIcons_.bind(this));
|
| this.addWebUIListener(
|
| + 'profile-defaults-received', this.handleProfileDefaults_.bind(this));
|
| + this.addWebUIListener(
|
| 'signedin-users-received', this.handleSignedInUsers_.bind(this));
|
|
|
| this.browserProxy_.getAvailableIcons();
|
| @@ -125,21 +118,6 @@ Polymer({
|
| },
|
|
|
| /**
|
| - * Resets the state of the page.
|
| - * @private
|
| - */
|
| - resetForm_: function() {
|
| - this.profileName_ = '';
|
| - this.availableIconUrls_ = [];
|
| - this.profileIconUrl_ = '';
|
| - this.createInProgress_ = false;
|
| - this.message_ = '';
|
| - this.isSupervised_ = false;
|
| - this.signedInUsers_ = [];
|
| - this.selectedEmail_ = 0;
|
| - },
|
| -
|
| - /**
|
| * Handler for when the profile icons are pushed from the browser.
|
| * @param {!Array<string>} iconUrls
|
| * @private
|
| @@ -150,17 +128,34 @@ Polymer({
|
| },
|
|
|
| /**
|
| - * Updates the signed-in users.
|
| + * Handler for when the profile defaults are pushed from the browser.
|
| + * @param {ProfileInfo} profileInfo Default Info for the new profile.
|
| + * @private
|
| + */
|
| + handleProfileDefaults_: function(profileInfo) {
|
| + this.profileName_ = profileInfo.name;
|
| + },
|
| +
|
| + /**
|
| + * Handler for when signed-in users are pushed from the browser.
|
| * @param {!Array<SignedInUser>} signedInUsers
|
| * @private
|
| */
|
| handleSignedInUsers_: function(signedInUsers) {
|
| this.signedInUsers_ = signedInUsers;
|
| - this.signedIn_ = signedInUsers.length > 0;
|
| },
|
|
|
| /**
|
| - * Handler for the 'Learn More' button click event.
|
| + * Returns the currently selected signed-in user.
|
| + * @return {SignedInUser}
|
| + * @private
|
| + */
|
| + signedInUser_: function(signedInUserIndex) {
|
| + return this.signedInUsers_[signedInUserIndex];
|
| + },
|
| +
|
| + /**
|
| + * Handler for the 'Learn More' link tap event.
|
| * @param {!Event} event
|
| * @private
|
| */
|
| @@ -169,19 +164,87 @@ Polymer({
|
| },
|
|
|
| /**
|
| - * Handler for the 'Ok' button click event.
|
| + * Handler for the 'Save' button tap event.
|
| * @param {!Event} event
|
| * @private
|
| */
|
| onSaveTap_: function(event) {
|
| this.createInProgress_ = true;
|
| +
|
| + var signedInUser = this.signedInUser_(this.signedInUserIndex_);
|
| +
|
| + if (!this.isSupervised_) {
|
| + // The new profile is not supervised. Go ahead and create it.
|
| + this.createProfile_();
|
| + } else if (!signedInUser) {
|
| + // If the new profile is supervised, make sure a custodian is selected.
|
| + this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
|
| + this.createInProgress_ = false;
|
| + } else {
|
| + this.browserProxy_.getExistingSupervisedUsers(
|
| + signedInUser.profilePath).then(
|
| + this.createProfileIfValidSupervisedUser_.bind(this),
|
| + /** @param {*} error */
|
| + function(error) { this.handleMessage_(error); }.bind(this));
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Checks if the entered name matches name of an existing supervised user.
|
| + * If yes, the user is prompted to import the existing supervised user.
|
| + * If no, the new supervised profile gets created.
|
| + * @param {Array<SupervisedUser>} supervisedUsers The list of existing
|
| + * supervised users.
|
| + * @private
|
| + */
|
| + createProfileIfValidSupervisedUser_: function(supervisedUsers) {
|
| + for (var i = 0; i < supervisedUsers.length; ++i) {
|
| + if (supervisedUsers[i].name != this.profileName_)
|
| + continue;
|
| + // Check if another supervised user also exists with that name.
|
| + var nameIsUnique = true;
|
| + // Handling the case when multiple supervised users with the same
|
| + // name exist, but not all of them are on the device.
|
| + // If at least one is not imported, we want to offer that
|
| + // option to the user. This could happen due to a bug that allowed
|
| + // creating SUs with the same name (https://crbug.com/557445).
|
| + var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice;
|
| + for (var j = i + 1; j < supervisedUsers.length; ++j) {
|
| + if (supervisedUsers[j].name == this.profileName_) {
|
| + nameIsUnique = false;
|
| + allOnCurrentDevice = allOnCurrentDevice &&
|
| + supervisedUsers[j].onCurrentDevice;
|
| + }
|
| + }
|
| +
|
| + this.handleMessage_(allOnCurrentDevice ?
|
| + this.i18n('managedProfilesExistingLocalSupervisedUser') :
|
| + this.i18n('manageProfilesExistingSupervisedUser',
|
| + HTMLEscape(elide(this.profileName_, /* maxLength */ 50))));
|
| +
|
| + this.createInProgress_ = false;
|
| + return;
|
| + }
|
| + // No existing supervised user's name matches the entered profile name.
|
| + // Continue with creating the new supervised profile.
|
| + this.createProfile_();
|
| + },
|
| +
|
| + /**
|
| + * Creates the new profile.
|
| + * @private
|
| + */
|
| + createProfile_: function() {
|
| + var signedInUser = this.signedInUser_(this.signedInUserIndex_);
|
| + var custodianProfilePath = signedInUser ? signedInUser.profilePath : '';
|
| +
|
| this.browserProxy_.createProfile(
|
| this.profileName_, this.profileIconUrl_, this.isSupervised_,
|
| - this.signedInUsers_[this.selectedEmail_].profilePath);
|
| + custodianProfilePath);
|
| },
|
|
|
| /**
|
| - * Handler for the 'Cancel' button click event.
|
| + * Handler for the 'Cancel' button tap event.
|
| * @param {!Event} event
|
| * @private
|
| */
|
| @@ -230,6 +293,12 @@ Polymer({
|
| handleMessage_: function(message) {
|
| this.createInProgress_ = false;
|
| this.message_ = message;
|
| +
|
| + // TODO(mahmadi): attach handler to '#supervised-user-import-existing'
|
| + // in order to import supervised user with the given name.
|
| +
|
| + // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate
|
| + // custodian.
|
| },
|
|
|
| /**
|
| @@ -244,30 +313,27 @@ Polymer({
|
| },
|
|
|
| /**
|
| - * Computed binding determining whether 'Ok' button is disabled.
|
| + * Computed binding determining whether 'Save' button is disabled.
|
| * @param {boolean} createInProgress Is create in progress?
|
| * @param {string} profileName Profile Name.
|
| - * @param {string} message Existing warning/error message.
|
| * @return {boolean}
|
| * @private
|
| */
|
| - isOkDisabled_: function(createInProgress, profileName, message) {
|
| + isSaveDisabled_: function(createInProgress, profileName) {
|
| // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
|
| // dependency and cast to PaperInputElement instead.
|
| /** @type {{validate: function():boolean}} */
|
| var nameInput = this.$.nameInput;
|
| - return createInProgress || !profileName || message != '' ||
|
| - !nameInput.validate();
|
| + return createInProgress || !profileName || !nameInput.validate();
|
| },
|
|
|
| /**
|
| - * Computed binding determining whether supervised user checkbox is disabled.
|
| - * @param {boolean} createInProgress Is create in progress?
|
| - * @param {boolean} signedIn Are there any signed-in users?
|
| + * Computed binding that returns True if there are any signed-in users.
|
| + * @param {!Array<SignedInUser>} signedInUsers signed-in users.
|
| * @return {boolean}
|
| * @private
|
| */
|
| - isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
|
| - return createInProgress || !signedIn;
|
| + isSignedIn_: function(signedInUsers) {
|
| + return signedInUsers.length > 0;
|
| }
|
| });
|
|
|