| 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 /** |
| 11 * ManageProfileOverlay class | 11 * ManageProfileOverlay class |
| 12 * Encapsulated handling of the 'Manage profile...' overlay page. | 12 * Encapsulated handling of the 'Manage profile...' overlay page. |
| 13 * @constructor | 13 * @constructor |
| 14 * @class | 14 * @extends {cr.ui.pageManager.Page} |
| 15 */ | 15 */ |
| 16 function ManageProfileOverlay() { | 16 function ManageProfileOverlay() { |
| 17 Page.call(this, 'manageProfile', | 17 Page.call(this, 'manageProfile', |
| 18 loadTimeData.getString('manageProfileTabTitle'), | 18 loadTimeData.getString('manageProfileTabTitle'), |
| 19 'manage-profile-overlay'); | 19 'manage-profile-overlay'); |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 cr.addSingletonGetter(ManageProfileOverlay); | 22 cr.addSingletonGetter(ManageProfileOverlay); |
| 23 | 23 |
| 24 ManageProfileOverlay.prototype = { | 24 ManageProfileOverlay.prototype = { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 * accordingly. | 345 * accordingly. |
| 346 * @private | 346 * @private |
| 347 */ | 347 */ |
| 348 requestExistingSupervisedUsers_: function() { | 348 requestExistingSupervisedUsers_: function() { |
| 349 options.SupervisedUserListData.requestExistingSupervisedUsers().then( | 349 options.SupervisedUserListData.requestExistingSupervisedUsers().then( |
| 350 this.receiveExistingSupervisedUsers_.bind(this), | 350 this.receiveExistingSupervisedUsers_.bind(this), |
| 351 this.onSigninError_.bind(this)); | 351 this.onSigninError_.bind(this)); |
| 352 }, | 352 }, |
| 353 | 353 |
| 354 /** | 354 /** |
| 355 * @param {Object} supervisedUser |
| 356 * @param {boolean} nameIsUnique |
| 357 */ |
| 358 getImportHandler_: function(supervisedUser, nameIsUnique) { |
| 359 return (function() { |
| 360 if (supervisedUser.needAvatar || !nameIsUnique) { |
| 361 PageManager.showPageByName('supervisedUserImport'); |
| 362 } else { |
| 363 this.hideErrorBubble_('create'); |
| 364 CreateProfileOverlay.updateCreateInProgress(true); |
| 365 chrome.send('createProfile', |
| 366 [supervisedUser.name, supervisedUser.iconURL, false, true, |
| 367 supervisedUser.id]); |
| 368 } |
| 369 }).bind(this); |
| 370 }, |
| 371 |
| 372 /** |
| 355 * Callback which receives the list of existing supervised users. Checks if | 373 * Callback which receives the list of existing supervised users. Checks if |
| 356 * the currently entered name is the name of an already existing supervised | 374 * the currently entered name is the name of an already existing supervised |
| 357 * user. If yes, the user is prompted to import the existing supervised | 375 * user. If yes, the user is prompted to import the existing supervised |
| 358 * user, and the create button is disabled. | 376 * user, and the create button is disabled. |
| 359 * If the received list is empty, hides the "import" link. | 377 * If the received list is empty, hides the "import" link. |
| 360 * @param {Array.<Object>} supervisedUsers The list of existing supervised | 378 * @param {Array.<Object>} supervisedUsers The list of existing supervised |
| 361 * users. | 379 * users. |
| 362 * @private | 380 * @private |
| 363 */ | 381 */ |
| 364 receiveExistingSupervisedUsers_: function(supervisedUsers) { | 382 receiveExistingSupervisedUsers_: function(supervisedUsers) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 379 | 397 |
| 380 // Check if another supervised user also exists with that name. | 398 // Check if another supervised user also exists with that name. |
| 381 var nameIsUnique = true; | 399 var nameIsUnique = true; |
| 382 var j; | 400 var j; |
| 383 for (j = i + 1; j < supervisedUsers.length; ++j) { | 401 for (j = i + 1; j < supervisedUsers.length; ++j) { |
| 384 if (supervisedUsers[j].name == newName) { | 402 if (supervisedUsers[j].name == newName) { |
| 385 nameIsUnique = false; | 403 nameIsUnique = false; |
| 386 break; | 404 break; |
| 387 } | 405 } |
| 388 } | 406 } |
| 389 var self = this; | |
| 390 function getImportHandler(supervisedUser, nameIsUnique) { | |
| 391 return function() { | |
| 392 if (supervisedUser.needAvatar || !nameIsUnique) { | |
| 393 PageManager.showPageByName('supervisedUserImport'); | |
| 394 } else { | |
| 395 self.hideErrorBubble_('create'); | |
| 396 CreateProfileOverlay.updateCreateInProgress(true); | |
| 397 chrome.send('createProfile', | |
| 398 [supervisedUser.name, supervisedUser.iconURL, false, true, | |
| 399 supervisedUser.id]); | |
| 400 } | |
| 401 } | |
| 402 }; | |
| 403 $('supervised-user-import-existing').onclick = | 407 $('supervised-user-import-existing').onclick = |
| 404 getImportHandler(supervisedUsers[i], nameIsUnique); | 408 this.getImportHandler_(supervisedUsers[i], nameIsUnique); |
| 405 $('create-profile-ok').disabled = true; | 409 $('create-profile-ok').disabled = true; |
| 406 return; | 410 return; |
| 407 } | 411 } |
| 408 } | 412 } |
| 409 }, | 413 }, |
| 410 | 414 |
| 411 /** | 415 /** |
| 412 * Called in case the request for the list of supervised users fails because | 416 * Called in case the request for the list of supervised users fails because |
| 413 * of a signin error. | 417 * of a signin error. |
| 414 * @private | 418 * @private |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 return instance[name + '_'].apply(instance, arguments); | 867 return instance[name + '_'].apply(instance, arguments); |
| 864 }; | 868 }; |
| 865 }); | 869 }); |
| 866 | 870 |
| 867 // Export | 871 // Export |
| 868 return { | 872 return { |
| 869 ManageProfileOverlay: ManageProfileOverlay, | 873 ManageProfileOverlay: ManageProfileOverlay, |
| 870 CreateProfileOverlay: CreateProfileOverlay, | 874 CreateProfileOverlay: CreateProfileOverlay, |
| 871 }; | 875 }; |
| 872 }); | 876 }); |
| OLD | NEW |