Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/resources/md_user_manager/create_profile.js

Issue 1722843002: MD user manager (html/js/css for create profile flow) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments #3 Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview 'create-profile' is a page that contains controls for creating
7 * a (optionally supervised) profile, including choosing a name, and an avatar.
8 *
9 * @element create-profile
10 */
11 Polymer({
12 is: 'create-profile',
13
14 behaviors: [WebUIListenerBehavior],
15
16 properties: {
17 /**
18 * True if supervised user checkbox is disabled.
19 * @private {boolean}
20 */
21 supervisedUserCheckboxDisabled_: {
22 type: Boolean,
23 computed:
24 'isSupervisedUserCheckboxDisabled_(createInProgress_, signedIn_)'
25 },
26
27 /**
28 * The current profile name.
29 * @private {string}
30 */
31 profileName_: {
32 type: String,
33 value: '',
34 },
35
36 /**
37 * The list of available profile icon URLs.
38 * @private {!Array<string>}
39 */
40 availableIconUrls_: {
41 type: Array,
42 value: function() { return []; }
43 },
44
45 /**
46 * The currently selected profile icon URL. May be a data URL.
47 * @private {string}
48 */
49 profileIconUrl_: {
50 type: String,
51 value: ''
52 },
53
54 /**
55 * True if a profile is being created or imported.
56 * @private {boolean}
57 */
58 createInProgress_: {
59 type: Boolean,
60 value: false
61 },
62
63 /**
64 * The current error/warning message.
65 * @private {string}
66 */
67 message_: {
68 type: String,
69 value: ''
70 },
71
72 /**
73 * True if the new profile is a supervised profile.
74 * @private {boolean}
75 */
76 isSupervised_: {
77 type: Boolean,
78 value: false
79 },
80
81 /**
82 * The list of usernames and profile paths for currently signed-in users.
83 * @private {!Array<SignedInUser>}
84 */
85 signedInUsers_: {
86 type: Array,
87 value: function() { return []; }
88 },
89
90 /**
91 * Index of the selected signed-in user.
92 * @private {number}
93 */
94 selectedEmail_: {
95 type: Number,
96 value: 0
97 },
98 },
99
100 /** @override */
101 attached: function() {
102 this.resetForm_();
103
104 this.addWebUIListener(
105 'create-profile-success', this.handleSuccess_.bind(this));
106 this.addWebUIListener(
107 'create-profile-warning', this.handleMessage_.bind(this));
108 this.addWebUIListener(
109 'create-profile-error', this.handleMessage_.bind(this));
110 this.addWebUIListener(
111 'profile-icons-received', this.handleProfileIcons_.bind(this));
112 this.addWebUIListener(
113 'signedin-users-received', this.handleSignedInUsers_.bind(this));
114
115 signin.ProfileApi.getAvailableIcons();
116 signin.ProfileApi.getSignedInUsers();
117 },
118
119 /**
120 * Resets the state of the page.
121 * @private
122 */
123 resetForm_: function() {
124 this.profileName_ = '';
125 this.availableIconUrls_ = [];
126 this.profileIconUrl_ = '';
127 this.createInProgress_ = false;
128 this.message_ = '';
129 this.isSupervised_ = false;
130 this.signedInUsers_ = [];
131 this.selectedEmail_ = 0;
132 },
133
134 /**
135 * Handler for when the available icons are pushed from ProfileApi.
136 * @param {!Array<string>} iconUrls
137 * @private
138 */
139 handleProfileIcons_: function(iconUrls) {
140 this.availableIconUrls_ = iconUrls;
141 this.profileIconUrl_ = iconUrls[0];
142 },
143
144 /**
145 * Updates the signed-in users.
146 * @param {!Array<SignedInUser>} signedInUsers
147 * @private
148 */
149 handleSignedInUsers_: function(signedInUsers) {
150 this.signedInUsers_ = signedInUsers;
151 this.signedIn_ = signedInUsers.length > 0;
152 },
153
154 /**
155 * Handler for the 'Learn More' button click event.
156 * @param {!Event} event
157 * @private
158 */
159 onLearnMore_: function(event) {
160 // TODO(mahmadi): fire the event to show the 'learn-more-page'
161 },
162
163 /**
164 * Handler for the 'Ok' button click event.
165 * @param {!Event} event
166 * @private
167 */
168 onOk_: function(event) {
169 this.createInProgress_ = true;
170 signin.ProfileApi.createProfile(
171 this.profileName_, this.profileIconUrl_, this.isSupervised_,
172 this.signedInUsers_[this.selectedEmail_].profilePath);
173 },
174
175 /**
176 * Handler for the 'Cancel' button click event.
177 * @param {!Event} event
178 * @private
179 */
180 onCancel_: function(event) {
181 if (this.createInProgress_) {
182 this.createInProgress_ = false;
183 signin.ProfileApi.cancelCreateProfile();
184 } else {
185 this.fire('change-page', {page: 'user-pods-page'});
186 }
187 },
188
189 /**
190 * Handler for when the user clicks a new profile icon.
191 * @param {!Event} event
192 * @private
193 */
194 onIconTap_: function(event) {
195 var element = Polymer.dom(event).rootTarget;
196
197 if (element.nodeName == 'IMG')
198 this.profileIconUrl_ = element.src;
199 else if (element.dataset && element.dataset.iconUrl)
200 this.profileIconUrl_ = element.dataset.iconUrl;
201
202 // Button toggle state is controlled by the selected icon URL. Prevent
203 // tap events from changing the toggle state.
204 event.preventDefault();
205 },
206
207 /**
208 * Handles profile create/import success message pushed by ProfileApi.
209 * @param {!ProfileInfo} profileInfo Details of the created/imported profile.
210 * @private
211 */
212 handleSuccess_: function(profileInfo) {
213 this.createInProgress_ = false;
214 this.fire('change-page', {page: 'user-pods-page'});
215 },
216
217 /**
218 * Handles profile create/import warning/error message pushed by ProfileApi.
219 * @param {string} message An HTML warning/error message.
220 * @private
221 */
222 handleMessage_: function(message) {
223 this.createInProgress_ = false;
224 this.message_ = message;
225 },
226
227 /**
228 * Computed binding determining which profile icon button is toggled on.
229 * @param {string} iconUrl icon URL of a given icon button
230 * @param {string} profileIconUrl Currently selected icon URL
231 * @return {boolean}
232 * @private
233 */
234 isActiveIcon_: function(iconUrl, profileIconUrl) {
235 return iconUrl == profileIconUrl;
236 },
237
238 /**
239 * Computed binding determining whether 'Ok' button is disabled.
240 * @param {boolean} createInProgress Is create in progress?
241 * @param {string} profileName Profile Name
242 * @param {string} message Existing warning/error message
243 * @return {boolean}
244 * @private
245 */
246 isOkDisabled_: function(createInProgress, profileName, message) {
247 /** @type {{validate:(function())}} */
248 var nameInput = this.$.nameInput;
249 return createInProgress || !profileName || message != '' ||
250 !nameInput.validate();
251 },
252
253 /**
254 * Computed binding determining whether supervised user checkbox is disabled.
255 * @param {boolean} createInProgress Is create in progress?
256 * @param {boolean} signedIn Are there any signed-in users?
257 * @return {boolean}
258 * @private
259 */
260 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
261 return createInProgress || !signedIn;
262 }
263 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698