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

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_'
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
tommycli 2016/04/20 18:58:56 In the comment, it would be helpful to call out sp
Moe 2016/04/20 20:10:31 Makes sense. Done.
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 if (element.id == 'supervised-user-import-existing') {
143 this.onImportUserTap_(event);
144 event.preventDefault();
145 }
146 // TODO(mahmadi): handle tap event on '#reauth' to re-auth the custodian.
147 },
148
149 /**
129 * Handler for when the profile icons are pushed from the browser. 150 * Handler for when the profile icons are pushed from the browser.
130 * @param {!Array<string>} iconUrls 151 * @param {!Array<string>} iconUrls
131 * @private 152 * @private
132 */ 153 */
133 handleProfileIcons_: function(iconUrls) { 154 handleProfileIcons_: function(iconUrls) {
134 this.availableIconUrls_ = iconUrls; 155 this.availableIconUrls_ = iconUrls;
135 this.profileIconUrl_ = iconUrls[0]; 156 this.profileIconUrl_ = iconUrls[0];
136 }, 157 },
137 158
138 /** 159 /**
(...skipping 26 matching lines...) Expand all
165 /** 186 /**
166 * Handler for the 'Learn More' link tap event. 187 * Handler for the 'Learn More' link tap event.
167 * @param {!Event} event 188 * @param {!Event} event
168 * @private 189 * @private
169 */ 190 */
170 onLearnMoreTap_: function(event) { 191 onLearnMoreTap_: function(event) {
171 this.fire('change-page', {page: 'supervised-learn-more-page'}); 192 this.fire('change-page', {page: 'supervised-learn-more-page'});
172 }, 193 },
173 194
174 /** 195 /**
196 * Handler for the 'Import Supervised User' link tap event.
197 * @param {!Event} event
198 * @private
199 */
200 onImportUserTap_: function(event) {
201 this.createInProgress_ = true;
202
203 if (this.signedInUserIndex_ == NO_USER_SELECTED) {
204 // A custodian must be selected.
205 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
206 this.createInProgress_ = false;
207 } else {
208 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
209 this.browserProxy_.getExistingSupervisedUsers(
210 signedInUser.profilePath).then(
211 this.showImportSupervisedUserPopup_.bind(this),
212 /** @param {*} error */
213 function(error) { this.handleMessage_(error); }.bind(this));
214 }
215 },
216
217 /**
175 * Handler for the 'Save' button tap event. 218 * Handler for the 'Save' button tap event.
176 * @param {!Event} event 219 * @param {!Event} event
177 * @private 220 * @private
178 */ 221 */
179 onSaveTap_: function(event) { 222 onSaveTap_: function(event) {
180 this.createInProgress_ = true; 223 this.createInProgress_ = true;
181 224
182 if (!this.isSupervised_) { 225 if (!this.isSupervised_) {
183 // The new profile is not supervised. Go ahead and create it. 226 // The new profile is not supervised. Go ahead and create it.
184 this.createProfile_(); 227 this.createProfile_();
185 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) { 228 } else if (this.signedInUserIndex_ == NO_USER_SELECTED) {
186 // If the new profile is supervised, a custodian must be selected. 229 // If the new profile is supervised, a custodian must be selected.
187 this.handleMessage_(this.i18n('custodianAccountNotSelectedError')); 230 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
188 this.createInProgress_ = false; 231 this.createInProgress_ = false;
189 } else { 232 } else {
190 var signedInUser = this.signedInUser_(this.signedInUserIndex_); 233 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
191 this.browserProxy_.getExistingSupervisedUsers( 234 this.browserProxy_.getExistingSupervisedUsers(
192 signedInUser.profilePath).then( 235 signedInUser.profilePath).then(
193 this.createProfileIfValidSupervisedUser_.bind(this), 236 this.createProfileIfValidSupervisedUser_.bind(this),
194 /** @param {*} error */ 237 /** @param {*} error */
195 function(error) { this.handleMessage_(error); }.bind(this)); 238 function(error) { this.handleMessage_(error); }.bind(this));
196 } 239 }
197 }, 240 },
198 241
199 /** 242 /**
243 * Displays the import supervised user popup.
244 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
245 * supervised users.
246 * @private
247 */
248 showImportSupervisedUserPopup_: function(supervisedUsers) {
249 this.createInProgress_ = false;
250 this.$.importUserPopup.show(this.signedInUser_(this.signedInUserIndex_),
251 supervisedUsers);
252 },
253
254 /**
200 * Checks if the entered name matches name of an existing supervised user. 255 * 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. 256 * If yes, the user is prompted to import the existing supervised user.
202 * If no, the new supervised profile gets created. 257 * If no, the new supervised profile gets created.
203 * @param {Array<SupervisedUser>} supervisedUsers The list of existing 258 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
204 * supervised users. 259 * supervised users.
205 * @private 260 * @private
206 */ 261 */
207 createProfileIfValidSupervisedUser_: function(supervisedUsers) { 262 createProfileIfValidSupervisedUser_: function(supervisedUsers) {
208 for (var i = 0; i < supervisedUsers.length; ++i) { 263 for (var i = 0; i < supervisedUsers.length; ++i) {
209 if (supervisedUsers[i].name != this.profileName_) 264 if (supervisedUsers[i].name != this.profileName_)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 * @private 297 * @private
243 */ 298 */
244 createProfile_: function() { 299 createProfile_: function() {
245 var custodianProfilePath = ''; 300 var custodianProfilePath = '';
246 if (this.signedInUserIndex_ != NO_USER_SELECTED) { 301 if (this.signedInUserIndex_ != NO_USER_SELECTED) {
247 custodianProfilePath = 302 custodianProfilePath =
248 this.signedInUser_(this.signedInUserIndex_).profilePath; 303 this.signedInUser_(this.signedInUserIndex_).profilePath;
249 } 304 }
250 305
251 this.browserProxy_.createProfile( 306 this.browserProxy_.createProfile(
252 this.profileName_, this.profileIconUrl_, this.isSupervised_, 307 this.profileName_, this.profileIconUrl_, this.isSupervised_, '',
253 custodianProfilePath); 308 custodianProfilePath);
254 }, 309 },
255 310
256 /** 311 /**
312 * Handler for the 'import' event fired by #importUserPopup once a supervised
313 * user is selected to be imported and the popup closes.
314 * @param {!{detail: {supervisedUser: !SupervisedUser,
315 signedInUser: !SignedInUser}}} event
316 * @private
317 */
318 onImportUserPopupImport_: function(event) {
319 this.createInProgress_ = true;
320 var supervisedUser = event.detail.supervisedUser;
321 var signedInUser = event.detail.signedInUser;
322 this.browserProxy_.createProfile(
323 supervisedUser.name, supervisedUser.iconURL, true, supervisedUser.id,
324 signedInUser.profilePath);
325 },
326
327 /**
257 * Handler for the 'Cancel' button tap event. 328 * Handler for the 'Cancel' button tap event.
258 * @param {!Event} event 329 * @param {!Event} event
259 * @private 330 * @private
260 */ 331 */
261 onCancelTap_: function(event) { 332 onCancelTap_: function(event) {
262 if (this.createInProgress_) { 333 if (this.createInProgress_) {
263 this.createInProgress_ = false; 334 this.createInProgress_ = false;
264 this.browserProxy_.cancelCreateProfile(); 335 this.browserProxy_.cancelCreateProfile();
265 } else { 336 } else {
266 this.fire('change-page', {page: 'user-pods-page'}); 337 this.fire('change-page', {page: 'user-pods-page'});
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }, 372 },
302 373
303 /** 374 /**
304 * Handles profile create/import warning/error message pushed by the browser. 375 * Handles profile create/import warning/error message pushed by the browser.
305 * @param {string} message An HTML warning/error message. 376 * @param {string} message An HTML warning/error message.
306 * @private 377 * @private
307 */ 378 */
308 handleMessage_: function(message) { 379 handleMessage_: function(message) {
309 this.createInProgress_ = false; 380 this.createInProgress_ = false;
310 this.message_ = message; 381 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 }, 382 },
318 383
319 /** 384 /**
320 * Computed binding determining which profile icon button is toggled on. 385 * Computed binding determining which profile icon button is toggled on.
321 * @param {string} iconUrl icon URL of a given icon button. 386 * @param {string} iconUrl icon URL of a given icon button.
322 * @param {string} profileIconUrl Currently selected icon URL. 387 * @param {string} profileIconUrl Currently selected icon URL.
323 * @return {boolean} 388 * @return {boolean}
324 * @private 389 * @private
325 */ 390 */
326 isActiveIcon_: function(iconUrl, profileIconUrl) { 391 isActiveIcon_: function(iconUrl, profileIconUrl) {
327 return iconUrl == profileIconUrl; 392 return iconUrl == profileIconUrl;
328 }, 393 },
329 394
330 /** 395 /**
331 * Computed binding determining whether 'Save' button is disabled. 396 * Computed binding determining whether 'Save' button is disabled.
332 * @param {boolean} createInProgress Is create in progress? 397 * @param {boolean} createInProgress Is create in progress?
333 * @param {string} profileName Profile Name. 398 * @param {string} profileName Profile Name.
334 * @return {boolean} 399 * @return {boolean}
335 * @private 400 * @private
336 */ 401 */
337 isSaveDisabled_: function(createInProgress, profileName) { 402 isSaveDisabled_: function(createInProgress, profileName) {
338 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a 403 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
339 // dependency and cast to PaperInputElement instead. 404 // dependency and cast to PaperInputElement instead.
340 /** @type {{validate: function():boolean}} */ 405 /** @type {{validate: function():boolean}} */
341 var nameInput = this.$.nameInput; 406 var nameInput = this.$.nameInput;
342 return createInProgress || !profileName || !nameInput.validate(); 407 return createInProgress || !profileName || !nameInput.validate();
343 }, 408 },
344 409
345 /** 410 /**
411 * Returns True if the import supervised user link should be hidden.
412 * @param {boolean} createInProgress True if create/import is in progress
413 * @param {number} signedInUserIndex Index of the selected signed-in user.
414 * @return {boolean}
415 * @private
416 */
417 isImportUserLinkHidden_: function(createInProgress, signedInUserIndex) {
418 return createInProgress || !this.signedInUser_(signedInUserIndex);
419 },
420
421 /**
346 * Computed binding that returns True if there are any signed-in users. 422 * Computed binding that returns True if there are any signed-in users.
347 * @param {!Array<!SignedInUser>} signedInUsers signed-in users. 423 * @param {!Array<!SignedInUser>} signedInUsers signed-in users.
348 * @return {boolean} 424 * @return {boolean}
349 * @private 425 * @private
350 */ 426 */
351 isSignedIn_: function(signedInUsers) { 427 isSignedIn_: function(signedInUsers) {
352 return signedInUsers.length > 0; 428 return signedInUsers.length > 0;
353 } 429 }
354 }); 430 });
355 }()); 431 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698