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

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

Powered by Google App Engine
This is Rietveld 408576698