| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..14a9e1b74b94aff9a0260a6a4a4d4f5295efec99
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_user_manager/create_profile.js
|
| @@ -0,0 +1,180 @@
|
| +/* Copyright 2016 The Chromium Authors. All rights reserved.
|
| + * Use of this source code is governed by a BSD-style license that can be
|
| + * found in the LICENSE file.
|
| + */
|
| +
|
| +Polymer({
|
| + is: 'create-profile',
|
| +
|
| + properties: {
|
| +
|
| + supervisedUserCheckboxDisabled_: {
|
| + type: Boolean,
|
| + computed:
|
| + 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)'
|
| + },
|
| +
|
| + errorMessage_: {
|
| + type: String,
|
| + value: '',
|
| + observer: 'errorMessageChanged_'
|
| + }
|
| + },
|
| +
|
| + ready: function() {
|
| + cr.ui.ProfileApi.setProfileCreateSuccessCallback(
|
| + this.handleSuccess_.bind(this));
|
| + cr.ui.ProfileApi.setProfileCreateWarningCallback(
|
| + this.handleWarning_.bind(this));
|
| + cr.ui.ProfileApi.setProfileCreateErrorCallback(
|
| + this.handleError_.bind(this));
|
| +
|
| + this.parentNode.addEventListener('iron-select',
|
| + this.onPageSelect_.bind(this));
|
| + },
|
| +
|
| + /*
|
| + * Handler for |iron-select| events. Resets the form and makes calls to
|
| + * ProfileApi every time the page becomes visible.
|
| + */
|
| + onPageSelect_: function(e) {
|
| + if (e.target.selected == 'create-user-page') {
|
| + this.resetForm_();
|
| + cr.ui.ProfileApi.getAvailableIcons(this.handleAvailableIcons_.bind(this));
|
| + cr.ui.ProfileApi.getSignedInUsers(
|
| + this.handleUpdateSignedInUsers_.bind(this));
|
| + }
|
| + },
|
| +
|
| + /*
|
| + * Resets the form.
|
| + */
|
| + resetForm_: function() {
|
| + // The current profile name.
|
| + this.profileName = '';
|
| + // The currently selected profile icon URL. May be a data URL.
|
| + this.profileIconUrl = '';
|
| + // Whether a profile is being created or imported.
|
| + this.createInProgress_ = false;
|
| + // The current error/warning message.
|
| + this.errorMessage_ = '';
|
| + // Whether the new profile is a supervised profile.
|
| + this.isSupervised_ = false;
|
| + },
|
| +
|
| + /**
|
| + * Handler for when the available icons are pushed from ProfileApi.
|
| + */
|
| + handleAvailableIcons_: function(iconUrls) {
|
| + this.availableIconUrls = iconUrls;
|
| + this.profileIconUrl = iconUrls[0];
|
| + },
|
| +
|
| + /**
|
| + * Updates the signed-in email addresses.
|
| + */
|
| + handleUpdateSignedInUsers_: function(signedIn_users) {
|
| + this.signedInUsers_ = signedIn_users;
|
| + this.selectedEmail_ = 0;
|
| + this.signedIn_ = signedIn_users.length > 0;
|
| + },
|
| +
|
| + /**
|
| + * |Learn More| button click handler.
|
| + */
|
| + onLearnMore_: function(e) {
|
| + this.fire('change-page', {page: 'supervised-learn-more-page'});
|
| + },
|
| +
|
| + /**
|
| + * |Ok| button click handler.
|
| + */
|
| + onOk_: function() {
|
| + this.createInProgress_ = true;
|
| + chrome.send('createProfile',
|
| + [this.profileName, this.profileIconUrl, false,
|
| + this.isSupervised_, '',
|
| + this.signedInUsers_[this.selectedEmail_].profile_path]);
|
| + },
|
| +
|
| + /**
|
| + * |Cancel| button click handler.
|
| + */
|
| + onCancel_: function() {
|
| + if (this.createInProgress_) {
|
| + this.createInProgress_ = false;
|
| + chrome.send('cancelCreateProfile');
|
| + } else {
|
| + this.fire('change-page', {page: 'user-pods-page'});
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Handler for when the user clicks a new profile icon.
|
| + */
|
| + onIconTap_: function(event) {
|
| + var element = Polymer.dom(event).rootTarget;
|
| +
|
| + if (element.nodeName == 'IMG')
|
| + this.profileIconUrl = element.src;
|
| + else if (element.dataset && element.dataset.iconUrl)
|
| + this.profileIconUrl = element.dataset.iconUrl;
|
| +
|
| + // Button toggle state is controlled by the selected icon URL. Prevent
|
| + // tap events from changing the toggle state.
|
| + event.preventDefault();
|
| + },
|
| +
|
| + /**
|
| + * Handles profile create/import success message pushed by ProfileApi.
|
| + */
|
| + handleSuccess_: function(profileInfo) {
|
| + this.createInProgress_ = false;
|
| + this.fire('change-page', {page: 'user-pods-page'});
|
| + },
|
| +
|
| + /**
|
| + * Handles profile create/import warning message pushed by ProfileApi.
|
| + */
|
| + handleWarning_: function(warningHTML) {
|
| + this.createInProgress_ = false;
|
| + this.errorMessage_ = warningHTML;
|
| + },
|
| +
|
| + /**
|
| + * Handles profile create/import error message pushed by ProfileApi.
|
| + */
|
| + handleError_: function(errorHTML) {
|
| + this.createInProgress_ = false;
|
| + this.errorMessage_ = errorHTML;
|
| + },
|
| +
|
| + /**
|
| + * Observer for |errorMessage_|. Updates the content of |messageBubble|.
|
| + */
|
| + errorMessageChanged_: function(newValue, oldValue) {
|
| + this.$.messageBubble.innerHTML = newValue;
|
| + },
|
| +
|
| + /**
|
| + * Computed binding determining which profile icon button is toggled on.
|
| + */
|
| + isActiveIcon_: function(iconUrl, profileIconUrl) {
|
| + return iconUrl == profileIconUrl;
|
| + },
|
| +
|
| + /**
|
| + * Computed binding determining whether |Ok| button is disabled.
|
| + */
|
| + isOkDisabled_: function(createInProgress, profileName, errorMessage) {
|
| + return createInProgress || profileName == '' ||
|
| + !this.$.nameInput.validate() || errorMessage != '';
|
| + },
|
| +
|
| + /**
|
| + * Computed binding determining whether supervised user checkbox is disabled.
|
| + */
|
| + isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
|
| + return createInProgress || !signedIn;
|
| + }
|
| +});
|
|
|