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

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

Issue 1901853002: Import supervised user dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md-user-manager-confirmation-page
Patch Set: Addressed comments Created 4 years, 8 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'create-profile' is a page that contains controls for creating 6 * @fileoverview 'create-profile' is a page that contains controls for creating
7 * a (optionally supervised) profile, including choosing a name, and an avatar. 7 * a (optionally supervised) profile, including choosing a name, and an avatar.
8 */ 8 */
9 (function() { 9 (function() {
10 /** 10 /**
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 */ 91 */
92 signedInUserIndex_: { 92 signedInUserIndex_: {
93 type: Number, 93 type: Number,
94 value: NO_USER_SELECTED 94 value: NO_USER_SELECTED
95 }, 95 },
96 96
97 /** @private {!signin.ProfileBrowserProxy} */ 97 /** @private {!signin.ProfileBrowserProxy} */
98 browserProxy_: Object 98 browserProxy_: Object
99 }, 99 },
100 100
101 listeners: {
102 'tap': 'onTap_',
103 'importUserPopup.import': 'onImportUserPopupImport_'
tommycli 2016/04/19 23:33:37 This is pretty awesome. Thanks for the tip!
104 },
105
101 /** @override */ 106 /** @override */
102 created: function() { 107 created: function() {
103 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); 108 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
104 }, 109 },
105 110
106 /** @override */ 111 /** @override */
107 ready: function() { 112 ready: function() {
108 this.addWebUIListener( 113 this.addWebUIListener(
109 'create-profile-success', this.handleSuccess_.bind(this)); 114 'create-profile-success', this.handleSuccess_.bind(this));
110 this.addWebUIListener( 115 this.addWebUIListener(
111 'create-profile-warning', this.handleMessage_.bind(this)); 116 'create-profile-warning', this.handleMessage_.bind(this));
112 this.addWebUIListener( 117 this.addWebUIListener(
113 'create-profile-error', this.handleMessage_.bind(this)); 118 'create-profile-error', this.handleMessage_.bind(this));
114 this.addWebUIListener( 119 this.addWebUIListener(
115 'profile-icons-received', this.handleProfileIcons_.bind(this)); 120 'profile-icons-received', this.handleProfileIcons_.bind(this));
116 this.addWebUIListener( 121 this.addWebUIListener(
117 'profile-defaults-received', this.handleProfileDefaults_.bind(this)); 122 'profile-defaults-received', this.handleProfileDefaults_.bind(this));
118 this.addWebUIListener( 123 this.addWebUIListener(
119 'signedin-users-received', this.handleSignedInUsers_.bind(this)); 124 'signedin-users-received', this.handleSignedInUsers_.bind(this));
120 125
121 this.browserProxy_.getAvailableIcons(); 126 this.browserProxy_.getAvailableIcons();
122 this.browserProxy_.getSignedInUsers(); 127 this.browserProxy_.getSignedInUsers();
123 128
124 // Alias on 'this' to use in html. 129 // Alias on 'this' to use in html.
125 this.NO_USER_SELECTED = NO_USER_SELECTED; 130 this.NO_USER_SELECTED = NO_USER_SELECTED;
126 }, 131 },
127 132
128 /** 133 /**
134 * General handler for tap event on the host, used to handle tap events for
135 * dynamically added '<a>' elements.
136 * @param {!Event} event
137 * @private
138 */
139 onTap_: function(event) {
140 var element = Polymer.dom(event).rootTarget;
141
142 // Handle the tap event only if the target is a '<a>' element.
143 if (element.nodeName == 'A') {
144 if (element.id == 'supervised-user-import-existing') {
145 this.onImportUserTap_(event);
146 }
147 // TODO(mahmadi): handle tap event on '#reauth' to re-auth the custodian.
148 }
149 },
150
151 /**
129 * Handler for when the profile icons are pushed from the browser. 152 * Handler for when the profile icons are pushed from the browser.
130 * @param {!Array<string>} iconUrls 153 * @param {!Array<string>} iconUrls
131 * @private 154 * @private
132 */ 155 */
133 handleProfileIcons_: function(iconUrls) { 156 handleProfileIcons_: function(iconUrls) {
134 this.availableIconUrls_ = iconUrls; 157 this.availableIconUrls_ = iconUrls;
135 this.profileIconUrl_ = iconUrls[0]; 158 this.profileIconUrl_ = iconUrls[0];
136 }, 159 },
137 160
138 /** 161 /**
(...skipping 26 matching lines...) Expand all
165 /** 188 /**
166 * Handler for the 'Learn More' link tap event. 189 * Handler for the 'Learn More' link tap event.
167 * @param {!Event} event 190 * @param {!Event} event
168 * @private 191 * @private
169 */ 192 */
170 onLearnMoreTap_: function(event) { 193 onLearnMoreTap_: function(event) {
171 this.fire('change-page', {page: 'supervised-learn-more-page'}); 194 this.fire('change-page', {page: 'supervised-learn-more-page'});
172 }, 195 },
173 196
174 /** 197 /**
198 * Handler for the 'Import Supervised User' link tap event.
199 * @param {!Event} event
200 * @private
201 */
202 onImportUserTap_: function(event) {
203 this.createInProgress_ = true;
204
205 if (this.signedInUserIndex_ == NO_USER_SELECTED) {
206 // A custodian must be selected.
207 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
208 this.createInProgress_ = false;
209 } else {
210 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
211 this.browserProxy_.getExistingSupervisedUsers(
212 signedInUser.profilePath).then(
213 this.showImportSupervisedUserPopup_.bind(this),
214 /** @param {*} error */
215 function(error) { this.handleMessage_(error); }.bind(this));
216 }
217 },
218
219 /**
175 * Handler for the 'Save' button tap event. 220 * Handler for the 'Save' button tap event.
176 * @param {!Event} event 221 * @param {!Event} event
177 * @private 222 * @private
178 */ 223 */
179 onSaveTap_: function(event) { 224 onSaveTap_: function(event) {
180 this.createInProgress_ = true; 225 this.createInProgress_ = true;
181 226
182 if (!this.isSupervised_) { 227 if (!this.isSupervised_) {
183 // The new profile is not supervised. Go ahead and create it. 228 // The new profile is not supervised. Go ahead and create it.
184 this.createProfile_(); 229 this.createProfile_();
185 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) { 230 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) {
186 // If the new profile is supervised, a custodian must be selected. 231 // If the new profile is supervised, a custodian must be selected.
187 this.handleMessage_(this.i18n('custodianAccountNotSelectedError')); 232 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
188 this.createInProgress_ = false; 233 this.createInProgress_ = false;
189 } else { 234 } else {
190 var signedInUser = this.signedInUser_(this.signedInUserIndex_); 235 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
191 this.browserProxy_.getExistingSupervisedUsers( 236 this.browserProxy_.getExistingSupervisedUsers(
192 signedInUser.profilePath).then( 237 signedInUser.profilePath).then(
193 this.createProfileIfValidSupervisedUser_.bind(this), 238 this.createProfileIfValidSupervisedUser_.bind(this),
194 /** @param {*} error */ 239 /** @param {*} error */
195 function(error) { this.handleMessage_(error); }.bind(this)); 240 function(error) { this.handleMessage_(error); }.bind(this));
196 } 241 }
197 }, 242 },
198 243
199 /** 244 /**
245 * Displays the import supervised user popup.
246 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
247 * supervised users.
248 * @private
249 */
250 showImportSupervisedUserPopup_: function(supervisedUsers) {
251 this.createInProgress_ = false;
252 this.$.importUserPopup.show(this.signedInUser_(this.signedInUserIndex_),
253 supervisedUsers);
254 },
255
256 /**
200 * Checks if the entered name matches name of an existing supervised user. 257 * Checks if the entered name matches name of an existing supervised user.
201 * If yes, the user is prompted to import the existing supervised user. 258 * If yes, the user is prompted to import the existing supervised user.
202 * If no, the new supervised profile gets created. 259 * If no, the new supervised profile gets created.
203 * @param {Array<SupervisedUser>} supervisedUsers The list of existing 260 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
204 * supervised users. 261 * supervised users.
205 * @private 262 * @private
206 */ 263 */
207 createProfileIfValidSupervisedUser_: function(supervisedUsers) { 264 createProfileIfValidSupervisedUser_: function(supervisedUsers) {
208 for (var i = 0; i < supervisedUsers.length; ++i) { 265 for (var i = 0; i < supervisedUsers.length; ++i) {
209 if (supervisedUsers[i].name != this.profileName_) 266 if (supervisedUsers[i].name != this.profileName_)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 * @private 299 * @private
243 */ 300 */
244 createProfile_: function() { 301 createProfile_: function() {
245 var custodianProfilePath = ''; 302 var custodianProfilePath = '';
246 if (this.signedInUserIndex_ != NO_USER_SELECTED) { 303 if (this.signedInUserIndex_ != NO_USER_SELECTED) {
247 custodianProfilePath = 304 custodianProfilePath =
248 this.signedInUser_(this.signedInUserIndex_).profilePath; 305 this.signedInUser_(this.signedInUserIndex_).profilePath;
249 } 306 }
250 307
251 this.browserProxy_.createProfile( 308 this.browserProxy_.createProfile(
252 this.profileName_, this.profileIconUrl_, this.isSupervised_, 309 this.profileName_, this.profileIconUrl_, this.isSupervised_, '',
253 custodianProfilePath); 310 custodianProfilePath);
254 }, 311 },
255 312
256 /** 313 /**
314 * Handler for the 'import' event fired by #importUserPopup once a supervised
315 * user is selected to be imported and the popup closes.
316 * @param {!{detail: {supervisedUser: !SupervisedUser,
317 signedInUser: !SignedInUser}}} event
318 * @private
319 */
320 onImportUserPopupImport_: function(event) {
321 this.createInProgress_ = true;
322 var supervisedUser = event.detail.supervisedUser;
323 var signedInUser = event.detail.signedInUser;
324 this.browserProxy_.createProfile(
325 supervisedUser.name, supervisedUser.iconURL, true, supervisedUser.id,
326 signedInUser.profilePath);
327 },
328
329 /**
257 * Handler for the 'Cancel' button tap event. 330 * Handler for the 'Cancel' button tap event.
258 * @param {!Event} event 331 * @param {!Event} event
259 * @private 332 * @private
260 */ 333 */
261 onCancelTap_: function(event) { 334 onCancelTap_: function(event) {
262 if (this.createInProgress_) { 335 if (this.createInProgress_) {
263 this.createInProgress_ = false; 336 this.createInProgress_ = false;
264 this.browserProxy_.cancelCreateProfile(); 337 this.browserProxy_.cancelCreateProfile();
265 } else { 338 } else {
266 this.fire('change-page', {page: 'user-pods-page'}); 339 this.fire('change-page', {page: 'user-pods-page'});
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }, 374 },
302 375
303 /** 376 /**
304 * Handles profile create/import warning/error message pushed by the browser. 377 * Handles profile create/import warning/error message pushed by the browser.
305 * @param {string} message An HTML warning/error message. 378 * @param {string} message An HTML warning/error message.
306 * @private 379 * @private
307 */ 380 */
308 handleMessage_: function(message) { 381 handleMessage_: function(message) {
309 this.createInProgress_ = false; 382 this.createInProgress_ = false;
310 this.message_ = message; 383 this.message_ = message;
311
312 // TODO(mahmadi): attach handler to '#supervised-user-import-existing'
313 // in order to import supervised user with the given name.
314
315 // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate
316 // custodian.
317 }, 384 },
318 385
319 /** 386 /**
320 * Computed binding determining which profile icon button is toggled on. 387 * Computed binding determining which profile icon button is toggled on.
321 * @param {string} iconUrl icon URL of a given icon button. 388 * @param {string} iconUrl icon URL of a given icon button.
322 * @param {string} profileIconUrl Currently selected icon URL. 389 * @param {string} profileIconUrl Currently selected icon URL.
323 * @return {boolean} 390 * @return {boolean}
324 * @private 391 * @private
325 */ 392 */
326 isActiveIcon_: function(iconUrl, profileIconUrl) { 393 isActiveIcon_: function(iconUrl, profileIconUrl) {
327 return iconUrl == profileIconUrl; 394 return iconUrl == profileIconUrl;
328 }, 395 },
329 396
330 /** 397 /**
331 * Computed binding determining whether 'Save' button is disabled. 398 * Computed binding determining whether 'Save' button is disabled.
332 * @param {boolean} createInProgress Is create in progress? 399 * @param {boolean} createInProgress Is create in progress?
333 * @param {string} profileName Profile Name. 400 * @param {string} profileName Profile Name.
334 * @return {boolean} 401 * @return {boolean}
335 * @private 402 * @private
336 */ 403 */
337 isSaveDisabled_: function(createInProgress, profileName) { 404 isSaveDisabled_: function(createInProgress, profileName) {
338 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a 405 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
339 // dependency and cast to PaperInputElement instead. 406 // dependency and cast to PaperInputElement instead.
340 /** @type {{validate: function():boolean}} */ 407 /** @type {{validate: function():boolean}} */
341 var nameInput = this.$.nameInput; 408 var nameInput = this.$.nameInput;
342 return createInProgress || !profileName || !nameInput.validate(); 409 return createInProgress || !profileName || !nameInput.validate();
343 }, 410 },
344 411
345 /** 412 /**
413 * Returns True if the import supervised user link should be hidden.
414 * @param {boolean} createInProgress True if create/import is in progress
415 * @param {number} signedInUserIndex Index of the selected signed-in user.
416 * @return {boolean}
417 * @private
418 */
419 isImportUserLinkHidden_: function(createInProgress, signedInUserIndex) {
420 return createInProgress || !this.signedInUser_(signedInUserIndex);
421 },
422
423 /**
346 * Computed binding that returns True if there are any signed-in users. 424 * Computed binding that returns True if there are any signed-in users.
347 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. 425 * @param {!Array<!SignedInUser>} signedInUsers signed-in users.
348 * @return {boolean} 426 * @return {boolean}
349 * @private 427 * @private
350 */ 428 */
351 isSignedIn_: function(signedInUsers) { 429 isSignedIn_: function(signedInUsers) {
352 return signedInUsers.length > 0; 430 return signedInUsers.length > 0;
353 } 431 }
354 }); 432 });
355 }()); 433 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698