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

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

Issue 1826903002: updated UI, default profile name, check for existing supervised user before create (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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
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 * @element create-profile 9 * @element create-profile
10 */ 10 */
11 Polymer({ 11 Polymer({
12 is: 'create-profile', 12 is: 'create-profile',
13 13
14 behaviors: [WebUIListenerBehavior], 14 behaviors: [
15 I18nBehavior,
16 WebUIListenerBehavior
17 ],
15 18
16 properties: { 19 properties: {
17 /** 20 /**
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. 21 * The current profile name.
29 * @private {string} 22 * @private {string}
30 */ 23 */
31 profileName_: { 24 profileName_: {
32 type: String, 25 type: String,
33 value: '', 26 value: ''
34 }, 27 },
35 28
36 /** 29 /**
37 * The list of available profile icon URLs. 30 * The list of available profile icon URLs.
38 * @private {!Array<string>} 31 * @private {!Array<string>}
39 */ 32 */
40 availableIconUrls_: { 33 availableIconUrls_: {
41 type: Array, 34 type: Array,
42 value: function() { return []; } 35 value: function() { return []; }
43 }, 36 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 */ 77 */
85 signedInUsers_: { 78 signedInUsers_: {
86 type: Array, 79 type: Array,
87 value: function() { return []; } 80 value: function() { return []; }
88 }, 81 },
89 82
90 /** 83 /**
91 * Index of the selected signed-in user. 84 * Index of the selected signed-in user.
92 * @private {number} 85 * @private {number}
93 */ 86 */
94 selectedEmail_: { 87 signedInUserIndex_: {
95 type: Number, 88 type: Number,
96 value: 0 89 value: -1 // -1 selects the sentinel item. It means no user is selected.
97 }, 90 },
98 91
99 /** @private {!signin.ProfileBrowserProxy} */ 92 /** @private {!signin.ProfileBrowserProxy} */
100 browserProxy_: Object 93 browserProxy_: Object
101 }, 94 },
102 95
103 /** @override */ 96 /** @override */
104 created: function() { 97 created: function() {
105 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance(); 98 this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
106 }, 99 },
107 100
108 /** @override */ 101 /** @override */
109 attached: function() { 102 ready: function() {
110 this.resetForm_();
111
112 this.addWebUIListener( 103 this.addWebUIListener(
113 'create-profile-success', this.handleSuccess_.bind(this)); 104 'create-profile-success', this.handleSuccess_.bind(this));
114 this.addWebUIListener( 105 this.addWebUIListener(
115 'create-profile-warning', this.handleMessage_.bind(this)); 106 'create-profile-warning', this.handleMessage_.bind(this));
116 this.addWebUIListener( 107 this.addWebUIListener(
117 'create-profile-error', this.handleMessage_.bind(this)); 108 'create-profile-error', this.handleMessage_.bind(this));
118 this.addWebUIListener( 109 this.addWebUIListener(
119 'profile-icons-received', this.handleProfileIcons_.bind(this)); 110 'profile-icons-received', this.handleProfileIcons_.bind(this));
120 this.addWebUIListener( 111 this.addWebUIListener(
112 'profile-defaults-received', this.handleProfileDefaults_.bind(this));
113 this.addWebUIListener(
121 'signedin-users-received', this.handleSignedInUsers_.bind(this)); 114 'signedin-users-received', this.handleSignedInUsers_.bind(this));
122 115
123 this.browserProxy_.getAvailableIcons(); 116 this.browserProxy_.getAvailableIcons();
124 this.browserProxy_.getSignedInUsers(); 117 this.browserProxy_.getSignedInUsers();
125 }, 118 },
126 119
127 /** 120 /**
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. 121 * Handler for when the profile icons are pushed from the browser.
144 * @param {!Array<string>} iconUrls 122 * @param {!Array<string>} iconUrls
145 * @private 123 * @private
146 */ 124 */
147 handleProfileIcons_: function(iconUrls) { 125 handleProfileIcons_: function(iconUrls) {
148 this.availableIconUrls_ = iconUrls; 126 this.availableIconUrls_ = iconUrls;
149 this.profileIconUrl_ = iconUrls[0]; 127 this.profileIconUrl_ = iconUrls[0];
150 }, 128 },
151 129
152 /** 130 /**
153 * Updates the signed-in users. 131 * Handler for when the profile defaults are pushed from the browser.
132 * @param {ProfileInfo} profileInfo Default Info for the new profile.
133 * @private
134 */
135 handleProfileDefaults_: function(profileInfo) {
136 this.profileName_ = profileInfo.name;
137 },
138
139 /**
140 * Handler for when signed-in users are pushed from the browser.
154 * @param {!Array<SignedInUser>} signedInUsers 141 * @param {!Array<SignedInUser>} signedInUsers
155 * @private 142 * @private
156 */ 143 */
157 handleSignedInUsers_: function(signedInUsers) { 144 handleSignedInUsers_: function(signedInUsers) {
158 this.signedInUsers_ = signedInUsers; 145 this.signedInUsers_ = signedInUsers;
159 this.signedIn_ = signedInUsers.length > 0;
160 }, 146 },
161 147
162 /** 148 /**
163 * Handler for the 'Learn More' button click event. 149 * Returns the currently selected signed-in user.
150 * @return {SignedInUser}
151 * @private
152 */
153 signedInUser_: function(signedInUserIndex) {
154 return this.signedInUsers_[signedInUserIndex];
155 },
156
157 /**
158 * Handler for the 'Learn More' link tap event.
164 * @param {!Event} event 159 * @param {!Event} event
165 * @private 160 * @private
166 */ 161 */
167 onLearnMoreTap_: function(event) { 162 onLearnMoreTap_: function(event) {
168 // TODO(mahmadi): fire the event to show the 'learn-more-page' 163 // TODO(mahmadi): fire the event to show the 'learn-more-page'
169 }, 164 },
170 165
171 /** 166 /**
172 * Handler for the 'Ok' button click event. 167 * Handler for the 'Save' button tap event.
173 * @param {!Event} event 168 * @param {!Event} event
174 * @private 169 * @private
175 */ 170 */
176 onSaveTap_: function(event) { 171 onSaveTap_: function(event) {
177 this.createInProgress_ = true; 172 this.createInProgress_ = true;
178 this.browserProxy_.createProfile( 173
179 this.profileName_, this.profileIconUrl_, this.isSupervised_, 174 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
180 this.signedInUsers_[this.selectedEmail_].profilePath); 175
176 if (!this.isSupervised_) {
177 // The new profile is not supervised. Go ahead and create it.
178 this.createProfile_();
179 } else if (!signedInUser) {
180 // If the new profile is supervised, make sure a custodian is selected.
181 this.handleMessage_(this.i18n('custodianAccountNotSelectedError'));
182 this.createInProgress_ = false;
183 } else {
184 this.browserProxy_.getExistingSupervisedUsers(
185 signedInUser.profilePath).then(
186 this.createProfileIfValidSupervisedUser_.bind(this),
187 /** @param {*} error */
188 function(error) { this.handleMessage_(error); }.bind(this));
189 }
181 }, 190 },
182 191
183 /** 192 /**
184 * Handler for the 'Cancel' button click event. 193 * Checks if the entered name matches name of an existing supervised user.
194 * If yes, the user is prompted to import the existing supervised user.
195 * If no, the new supervised profile gets created.
196 * @param {Array<SupervisedUser>} supervisedUsers The list of existing
197 * supervised users.
198 * @private
199 */
200 createProfileIfValidSupervisedUser_: function(supervisedUsers) {
201 for (var i = 0; i < supervisedUsers.length; ++i) {
202 if (supervisedUsers[i].name != this.profileName_)
203 continue;
204 // Check if another supervised user also exists with that name.
205 var nameIsUnique = true;
206 // Handling the case when multiple supervised users with the same
207 // name exist, but not all of them are on the device.
208 // If at least one is not imported, we want to offer that
209 // option to the user. This could happen due to a bug that allowed
210 // creating SUs with the same name (https://crbug.com/557445).
211 var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice;
212 for (var j = i + 1; j < supervisedUsers.length; ++j) {
213 if (supervisedUsers[j].name == this.profileName_) {
214 nameIsUnique = false;
215 allOnCurrentDevice = allOnCurrentDevice &&
216 supervisedUsers[j].onCurrentDevice;
217 }
218 }
219
220 this.handleMessage_(allOnCurrentDevice ?
221 this.i18n('managedProfilesExistingLocalSupervisedUser') :
222 this.i18n('manageProfilesExistingSupervisedUser',
223 HTMLEscape(elide(this.profileName_, /* maxLength */ 50))));
224
225 this.createInProgress_ = false;
226 return;
227 }
228 // No existing supervised user's name matches the entered profile name.
229 // Continue with creating the new supervised profile.
230 this.createProfile_();
231 },
232
233 /**
234 * Creates the new profile.
235 * @private
236 */
237 createProfile_: function() {
238 var signedInUser = this.signedInUser_(this.signedInUserIndex_);
239 var custodianProfilePath = signedInUser ? signedInUser.profilePath : '';
240
241 this.browserProxy_.createProfile(
242 this.profileName_, this.profileIconUrl_, this.isSupervised_,
243 custodianProfilePath);
244 },
245
246 /**
247 * Handler for the 'Cancel' button tap event.
185 * @param {!Event} event 248 * @param {!Event} event
186 * @private 249 * @private
187 */ 250 */
188 onCancelTap_: function(event) { 251 onCancelTap_: function(event) {
189 if (this.createInProgress_) { 252 if (this.createInProgress_) {
190 this.createInProgress_ = false; 253 this.createInProgress_ = false;
191 this.browserProxy_.cancelCreateProfile(); 254 this.browserProxy_.cancelCreateProfile();
192 } else { 255 } else {
193 this.fire('change-page', {page: 'user-pods-page'}); 256 this.fire('change-page', {page: 'user-pods-page'});
194 } 257 }
(...skipping 28 matching lines...) Expand all
223 }, 286 },
224 287
225 /** 288 /**
226 * Handles profile create/import warning/error message pushed by the browser. 289 * Handles profile create/import warning/error message pushed by the browser.
227 * @param {string} message An HTML warning/error message. 290 * @param {string} message An HTML warning/error message.
228 * @private 291 * @private
229 */ 292 */
230 handleMessage_: function(message) { 293 handleMessage_: function(message) {
231 this.createInProgress_ = false; 294 this.createInProgress_ = false;
232 this.message_ = message; 295 this.message_ = message;
296
297 // TODO(mahmadi): attach handler to '#supervised-user-import-existing'
298 // in order to import supervised user with the given name.
299
300 // TODO(mahmadi): attach handler to '#reauth' in order to re-authenticate
301 // custodian.
233 }, 302 },
234 303
235 /** 304 /**
236 * Computed binding determining which profile icon button is toggled on. 305 * Computed binding determining which profile icon button is toggled on.
237 * @param {string} iconUrl icon URL of a given icon button. 306 * @param {string} iconUrl icon URL of a given icon button.
238 * @param {string} profileIconUrl Currently selected icon URL. 307 * @param {string} profileIconUrl Currently selected icon URL.
239 * @return {boolean} 308 * @return {boolean}
240 * @private 309 * @private
241 */ 310 */
242 isActiveIcon_: function(iconUrl, profileIconUrl) { 311 isActiveIcon_: function(iconUrl, profileIconUrl) {
243 return iconUrl == profileIconUrl; 312 return iconUrl == profileIconUrl;
244 }, 313 },
245 314
246 /** 315 /**
247 * Computed binding determining whether 'Ok' button is disabled. 316 * Computed binding determining whether 'Save' button is disabled.
248 * @param {boolean} createInProgress Is create in progress? 317 * @param {boolean} createInProgress Is create in progress?
249 * @param {string} profileName Profile Name. 318 * @param {string} profileName Profile Name.
250 * @param {string} message Existing warning/error message.
251 * @return {boolean} 319 * @return {boolean}
252 * @private 320 * @private
253 */ 321 */
254 isOkDisabled_: function(createInProgress, profileName, message) { 322 isSaveDisabled_: function(createInProgress, profileName) {
255 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a 323 // TODO(mahmadi): Figure out a way to add 'paper-input-extracted' as a
256 // dependency and cast to PaperInputElement instead. 324 // dependency and cast to PaperInputElement instead.
257 /** @type {{validate: function():boolean}} */ 325 /** @type {{validate: function():boolean}} */
258 var nameInput = this.$.nameInput; 326 var nameInput = this.$.nameInput;
259 return createInProgress || !profileName || message != '' || 327 return createInProgress || !profileName || !nameInput.validate();
260 !nameInput.validate();
261 }, 328 },
262 329
263 /** 330 /**
264 * Computed binding determining whether supervised user checkbox is disabled. 331 * Computed binding that returns True if there are any signed-in users.
265 * @param {boolean} createInProgress Is create in progress? 332 * @param {!Array<SignedInUser>} signedInUsers signed-in users.
266 * @param {boolean} signedIn Are there any signed-in users?
267 * @return {boolean} 333 * @return {boolean}
268 * @private 334 * @private
269 */ 335 */
270 isSupervisedUserCheckboxDisabled_: function(createInProgress, signedIn) { 336 isSignedIn_: function(signedInUsers) {
271 return createInProgress || !signedIn; 337 return signedInUsers.length > 0;
272 } 338 }
273 }); 339 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698