OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 var Page = cr.ui.pageManager.Page; | 6 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | 7 var PageManager = cr.ui.pageManager.PageManager; |
8 var ArrayDataModel = cr.ui.ArrayDataModel; | 8 var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 */ | 372 */ |
373 receiveExistingSupervisedUsers_: function(supervisedUsers) { | 373 receiveExistingSupervisedUsers_: function(supervisedUsers) { |
374 $('import-existing-supervised-user-link').hidden = | 374 $('import-existing-supervised-user-link').hidden = |
375 supervisedUsers.length === 0; | 375 supervisedUsers.length === 0; |
376 if (!$('create-profile-supervised').checked) | 376 if (!$('create-profile-supervised').checked) |
377 return; | 377 return; |
378 | 378 |
379 var newName = $('create-profile-name').value; | 379 var newName = $('create-profile-name').value; |
380 var i; | 380 var i; |
381 for (i = 0; i < supervisedUsers.length; ++i) { | 381 for (i = 0; i < supervisedUsers.length; ++i) { |
382 if (supervisedUsers[i].name == newName && | 382 if (supervisedUsers[i].name != newName) |
383 !supervisedUsers[i].onCurrentDevice) { | 383 continue; |
384 var errorHtml = loadTimeData.getStringF( | 384 // Check if another supervised user also exists with that name. |
385 'manageProfilesExistingSupervisedUser', | 385 var nameIsUnique = true; |
386 HTMLEscape(elide(newName, /* maxLength */ 50))); | 386 // Handling the case when multiple supervised users with the same |
387 this.showErrorBubble_(errorHtml, 'create', true); | 387 // name exist, but not all of them are on the device. |
| 388 // If at least one is not imported, we want to offer that |
| 389 // option to the user. This could happen due to a bug that allowed |
| 390 // creating SUs with the same name (https://crbug.com/557445). |
| 391 var allOnCurrentDevice = supervisedUsers[i].onCurrentDevice; |
| 392 var j; |
| 393 for (j = i + 1; j < supervisedUsers.length; ++j) { |
| 394 if (supervisedUsers[j].name == newName) { |
| 395 nameIsUnique = false; |
| 396 allOnCurrentDevice = allOnCurrentDevice && |
| 397 supervisedUsers[j].onCurrentDevice; |
| 398 } |
| 399 } |
388 | 400 |
389 // Check if another supervised user also exists with that name. | 401 var errorHtml = allOnCurrentDevice ? |
390 var nameIsUnique = true; | 402 loadTimeData.getStringF( |
391 var j; | 403 'managedProfilesExistingLocalSupervisedUser') : |
392 for (j = i + 1; j < supervisedUsers.length; ++j) { | 404 loadTimeData.getStringF( |
393 if (supervisedUsers[j].name == newName) { | 405 'manageProfilesExistingSupervisedUser', |
394 nameIsUnique = false; | 406 HTMLEscape(elide(newName, /* maxLength */ 50))); |
395 break; | 407 this.showErrorBubble_(errorHtml, 'create', true); |
396 } | 408 |
397 } | 409 $('supervised-user-import-existing').onclick = |
398 $('supervised-user-import-existing').onclick = | 410 this.getImportHandler_(supervisedUsers[i], nameIsUnique); |
399 this.getImportHandler_(supervisedUsers[i], nameIsUnique); | 411 $('create-profile-ok').disabled = true; |
400 $('create-profile-ok').disabled = true; | 412 return; |
401 return; | |
402 } | |
403 } | 413 } |
404 }, | 414 }, |
405 | 415 |
406 /** | 416 /** |
407 * Called in case the request for the list of supervised users fails because | 417 * Called in case the request for the list of supervised users fails because |
408 * of a signin error. | 418 * of a signin error. |
409 * @private | 419 * @private |
410 */ | 420 */ |
411 onSigninError_: function() { | 421 onSigninError_: function() { |
412 this.updateSignedInStatus(this.signedInEmail_, true); | 422 this.updateSignedInStatus(this.signedInEmail_, true); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 'updateSignedInStatus', | 871 'updateSignedInStatus', |
862 'updateSupervisedUsersAllowed', | 872 'updateSupervisedUsersAllowed', |
863 ]); | 873 ]); |
864 | 874 |
865 // Export | 875 // Export |
866 return { | 876 return { |
867 ManageProfileOverlay: ManageProfileOverlay, | 877 ManageProfileOverlay: ManageProfileOverlay, |
868 CreateProfileOverlay: CreateProfileOverlay, | 878 CreateProfileOverlay: CreateProfileOverlay, |
869 }; | 879 }; |
870 }); | 880 }); |
OLD | NEW |