| 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..00d874a09d38dbd94f20294bd158e7ad3d801ec3
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_user_manager/create_profile.js
|
| @@ -0,0 +1,261 @@
|
| +/* 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.
|
| + */
|
| +
|
| +/**
|
| + * @fileoverview
|
| + * 'create-profile' is a page that contains controls for creating a (optionally
|
| + * supervised) profile, including choosing a name, and an avatar.
|
| + *
|
| + * @element create-profile
|
| + */
|
| +Polymer({
|
| + is: 'create-profile',
|
| +
|
| + 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: '',
|
| + },
|
| +
|
| + /**
|
| + * The list of available profile icon URLs.
|
| + * @private {!Array<string>}
|
| + */
|
| + availableIconUrls_: {
|
| + type: Array,
|
| + value: function() { return []; }
|
| + },
|
| +
|
| + /**
|
| + * The currently selected profile icon URL. May be a data URL.
|
| + * @private {string}
|
| + */
|
| + profileIconUrl_: {
|
| + type: String,
|
| + value: ''
|
| + },
|
| +
|
| + /**
|
| + * True if a profile is being created or imported.
|
| + * @private {boolean}
|
| + */
|
| + createInProgress_: {
|
| + type: Boolean,
|
| + value: false
|
| + },
|
| +
|
| + /**
|
| + * The current error/warning message.
|
| + * @private {string}
|
| + */
|
| + message_: {
|
| + type: String,
|
| + value: ''
|
| + },
|
| +
|
| + /**
|
| + * True if the new profile is a supervised profile.
|
| + * @private {boolean}
|
| + */
|
| + isSupervised_: {
|
| + type: Boolean,
|
| + value: false
|
| + }
|
| + },
|
| +
|
| + /** @override */
|
| + attached: function() {
|
| + signin.ProfileApi.setProfileCreateSuccessCallback(
|
| + this.handleSuccess_.bind(this));
|
| + signin.ProfileApi.setProfileCreateWarningCallback(
|
| + this.handleMessage_.bind(this));
|
| + signin.ProfileApi.setProfileCreateErrorCallback(
|
| + this.handleMessage_.bind(this));
|
| +
|
| + this.parentNode.addEventListener('iron-select',
|
| + this.onPageSelect_.bind(this));
|
| + },
|
| +
|
| + /** @override */
|
| + detached: function() {
|
| + signin.ProfileApi.setProfileCreateSuccessCallback(null);
|
| + signin.ProfileApi.setProfileCreateWarningCallback(null);
|
| + signin.ProfileApi.setProfileCreateErrorCallback(null);
|
| + },
|
| +
|
| + /**
|
| + * Handler for |iron-select| events. Resets the form and makes calls to
|
| + * ProfileApi every time the page becomes visible.
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + onPageSelect_: function(event) {
|
| + if (event.target.selected == 'create-user-page') {
|
| + this.resetForm_();
|
| + signin.ProfileApi.getAvailableIcons(
|
| + this.handleAvailableIcons_.bind(this));
|
| + signin.ProfileApi.getSignedInUsers(
|
| + this.handleUpdateSignedInUsers_.bind(this));
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * Resets the state of the page.
|
| + * @private
|
| + */
|
| + resetForm_: function() {
|
| + this.profileName_ = '';
|
| + this.availableIconUrls_ = [];
|
| + this.profileIconUrl_ = '';
|
| + this.createInProgress_ = false;
|
| + this.message_ = '';
|
| + this.isSupervised_ = false;
|
| + },
|
| +
|
| + /**
|
| + * Handler for when the available icons are pushed from ProfileApi.
|
| + * @param {!Array<string>} iconUrls
|
| + * @private
|
| + */
|
| + handleAvailableIcons_: function(iconUrls) {
|
| + this.availableIconUrls_ = iconUrls;
|
| + this.profileIconUrl_ = iconUrls[0];
|
| + },
|
| +
|
| + /**
|
| + * Updates the signed-in email addresses.
|
| + * @private
|
| + */
|
| + handleUpdateSignedInUsers_: function(signedInUsers) {
|
| + this.signedInUsers_ = signedInUsers;
|
| + this.selectedEmail_ = 0;
|
| + this.signedIn_ = signedInUsers.length > 0;
|
| + },
|
| +
|
| + /**
|
| + * Handler for the |Learn More| button click event.
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + onLearnMore_: function(event) {
|
| + this.fire('change-page', {page: 'supervised-learn-more-page'});
|
| + },
|
| +
|
| + /**
|
| + * Handler for the |Ok| button click event.
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + onOk_: function(event) {
|
| + this.createInProgress_ = true;
|
| + chrome.send('createProfile',
|
| + [this.profileName_, this.profileIconUrl_, false,
|
| + this.isSupervised_, '',
|
| + this.signedInUsers_[this.selectedEmail_].profilePath]);
|
| + },
|
| +
|
| + /**
|
| + * Handler for the |Cancel| button click event.
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + onCancel_: function(event) {
|
| + 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.
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + 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.
|
| + * @param {!profileInfo} profileInfo Details of the created/imported profile.
|
| + * @private
|
| + */
|
| + handleSuccess_: function(profileInfo) {
|
| + this.createInProgress_ = false;
|
| + this.fire('change-page', {page: 'user-pods-page'});
|
| + },
|
| +
|
| + /**
|
| + * Handles profile create/import warning/error message pushed by ProfileApi.
|
| + * @param {string} message An HTML warning/error message.
|
| + * @private
|
| + */
|
| + handleMessage_: function(message) {
|
| + this.createInProgress_ = false;
|
| + this.message_ = message;
|
| + },
|
| +
|
| + /**
|
| + * Computed binding determining which profile icon button is toggled on.
|
| + * @param {string} iconUrl icon URL of a given icon button
|
| + * @param {string} profileIconUrl Currently selected icon URL
|
| + * @return {boolean}
|
| + * @private
|
| + */
|
| + isActiveIcon_: function(iconUrl, profileIconUrl) {
|
| + return iconUrl == profileIconUrl;
|
| + },
|
| +
|
| + /**
|
| + * Computed binding determining whether |Ok| 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) {
|
| + /** @type {{validate:(function())}} */
|
| + var nameInput = this.$.nameInput;
|
| + return createInProgress || profileName == '' || !nameInput.validate() ||
|
| + message != '';
|
| + },
|
| +
|
| + /**
|
| + * 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?
|
| + * @return {boolean}
|
| + * @private
|
| + */
|
| + isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
|
| + return createInProgress || !signedIn;
|
| + }
|
| +});
|
|
|