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

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 #6 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 /** @private {!signin.ProfileBrowserProxy} */
100 browserProxy_: Object
101 },
102
103 /** @override */
104 created: function() {
105 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
106 },
107
108 /** @override */
109 attached: function() {
110 this.resetForm_();
111
112 this.addWebUIListener(
113 'create-profile-success', this.handleSuccess_.bind(this));
114 this.addWebUIListener(
115 'create-profile-warning', this.handleMessage_.bind(this));
116 this.addWebUIListener(
117 'create-profile-error', this.handleMessage_.bind(this));
118 this.addWebUIListener(
119 'profile-icons-received', this.handleProfileIcons_.bind(this));
120 this.addWebUIListener(
121 'signedin-users-received', this.handleSignedInUsers_.bind(this));
122
123 this.browserProxy_.getAvailableIcons();
124 this.browserProxy_.getSignedInUsers();
125 },
126
127 /**
128 * Resets the state of the page.
129 * @private
130 */
131 resetForm_: function() {
132 this.profileName_ = '';
133 this.availableIconUrls_ = [];
134 this.profileIconUrl_ = '';
135 this.createInProgress_ = false;
136 this.message_ = '';
137 this.isSupervised_ = false;
138 this.signedInUsers_ = [];
139 this.selectedEmail_ = 0;
140 },
141
142 /**
143 * Handler for when the profile icons are pushed from the browser.
144 * @param {!Array<string>} iconUrls
145 * @private
146 */
147 handleProfileIcons_: function(iconUrls) {
148 this.availableIconUrls_ = iconUrls;
149 this.profileIconUrl_ = iconUrls[0];
150 },
151
152 /**
153 * Updates the signed-in users.
154 * @param {!Array<SignedInUser>} signedInUsers
155 * @private
156 */
157 handleSignedInUsers_: function(signedInUsers) {
158 this.signedInUsers_ = signedInUsers;
159 this.signedIn_ = signedInUsers.length > 0;
160 },
161
162 /**
163 * Handler for the 'Learn More' button click event.
164 * @param {!Event} event
165 * @private
166 */
167 onLearnMoreTap_: function(event) {
168 // TODO(mahmadi): fire the event to show the 'learn-more-page'
169 },
170
171 /**
172 * Handler for the 'Ok' button click event.
173 * @param {!Event} event
174 * @private
175 */
176 onSaveTap_: function(event) {
177 this.createInProgress_ = true;
178 this.browserProxy_.createProfile(
179 this.profileName_, this.profileIconUrl_, this.isSupervised_,
180 this.signedInUsers_[this.selectedEmail_].profilePath);
181 },
182
183 /**
184 * Handler for the 'Cancel' button click event.
185 * @param {!Event} event
186 * @private
187 */
188 onCancelTap_: function(event) {
189 if (this.createInProgress_) {
190 this.createInProgress_ = false;
191 this.browserProxy_.cancelCreateProfile();
192 } else {
193 this.fire('change-page', {page: 'user-pods-page'});
194 }
195 },
196
197 /**
198 * Handler for when the user clicks a new profile icon.
199 * @param {!Event} event
200 * @private
201 */
202 onIconTap_: function(event) {
203 var element = Polymer.dom(event).rootTarget;
204
205 if (element.nodeName == 'IMG')
206 this.profileIconUrl_ = element.src;
207 else if (element.dataset && element.dataset.iconUrl)
208 this.profileIconUrl_ = element.dataset.iconUrl;
209
210 // Button toggle state is controlled by the selected icon URL. Prevent
211 // tap events from changing the toggle state.
212 event.preventDefault();
213 },
214
215 /**
216 * Handles profile create/import success message pushed by the browser.
217 * @param {!ProfileInfo} profileInfo Details of the created/imported profile.
218 * @private
219 */
220 handleSuccess_: function(profileInfo) {
221 this.createInProgress_ = false;
222 this.fire('change-page', {page: 'user-pods-page'});
223 },
224
225 /**
226 * Handles profile create/import warning/error message pushed by the browser.
227 * @param {string} message An HTML warning/error message.
228 * @private
229 */
230 handleMessage_: function(message) {
231 this.createInProgress_ = false;
232 this.message_ = message;
233 },
234
235 /**
236 * Computed binding determining which profile icon button is toggled on.
237 * @param {string} iconUrl icon URL of a given icon button.
238 * @param {string} profileIconUrl Currently selected icon URL.
239 * @return {boolean}
240 * @private
241 */
242 isActiveIcon_: function(iconUrl, profileIconUrl) {
243 return iconUrl == profileIconUrl;
244 },
245
246 /**
247 * Computed binding determining whether 'Ok' button is disabled.
248 * @param {boolean} createInProgress Is create in progress?
249 * @param {string} profileName Profile Name.
250 * @param {string} message Existing warning/error message.
251 * @return {boolean}
252 * @private
253 */
254 isOkDisabled_: function(createInProgress, profileName, message) {
255 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
256 // dependency and cast to PaperInputElement instead.
257 /** @type {{validate: function():boolean}} */
258 var nameInput = this.$.nameInput;
259 return createInProgress || !profileName || message != '' ||
260 !nameInput.validate();
261 },
262
263 /**
264 * Computed binding determining whether supervised user checkbox is disabled.
265 * @param {boolean} createInProgress Is create in progress?
266 * @param {boolean} signedIn Are there any signed-in users?
267 * @return {boolean}
268 * @private
269 */
270 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) {
271 return createInProgress || !signedIn;
272 }
273 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698