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

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

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

Powered by Google App Engine
This is Rietveld 408576698