Chromium Code Reviews| 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({ |
|
tommycli
2016/02/03 01:13:21
Also needs the fileoverview.
Moe
2016/02/05 17:58:39
Done.
|
| + is: 'create-profile', |
| + |
| + properties: { |
| + |
|
tommycli
2016/02/03 01:13:21
extra line
Moe
2016/02/05 17:58:39
Done.
|
| + supervisedUserCheckboxDisabled_: { |
| + type: Boolean, |
| + computed: |
| + 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)' |
| + }, |
| + |
| + errorMessage_: { |
| + type: String, |
| + value: '', |
| + observer: 'errorMessageChanged_' |
| + } |
| + }, |
| + |
| + ready: function() { |
|
tommycli
2016/02/03 01:13:22
This should be on "attached" with the override ann
Moe
2016/02/05 17:58:39
Done.
|
| + cr.ui.ProfileApi.setProfileCreateSuccessCallback( |
|
tommycli
2016/02/03 01:13:21
All of these callbacks should be unset in the corr
Moe
2016/02/05 17:58:39
Done.
|
| + 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. |
|
tommycli
2016/02/03 01:13:21
annotate the param. Here and in all the below func
Moe
2016/02/05 17:58:39
Done.
|
| + */ |
| + 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)); |
| + } |
| + }, |
| + |
| + /* |
|
tommycli
2016/02/03 01:13:22
Two stars to begin these block comments.
Moe
2016/02/05 17:58:39
Done.
|
| + * 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) { |
|
tommycli
2016/02/03 01:13:21
camelCase preferred
Moe
2016/02/05 17:58:39
Done.
|
| + 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; |
| + } |
| +}); |