| Index: chrome/browser/resources/options/managed_user_import.js
|
| diff --git a/chrome/browser/resources/options/managed_user_import.js b/chrome/browser/resources/options/managed_user_import.js
|
| index 70a54dd2cabfc54e54649f882a613e911981fca3..9f36a77ed081f920c51455d8286eee255fe5ce7b 100644
|
| --- a/chrome/browser/resources/options/managed_user_import.js
|
| +++ b/chrome/browser/resources/options/managed_user_import.js
|
| @@ -7,6 +7,95 @@ cr.define('options', function() {
|
| var ArrayDataModel = cr.ui.ArrayDataModel;
|
|
|
| /**
|
| + * ManagedUserList class.
|
| + * Handles requests for retrieving a list of existing managed users which are
|
| + * supervised by the current profile. This list is cached in order to make it
|
| + * possible to serve future requests immediately. The first request will be
|
| + * handled asynchronously.
|
| + * @constructor
|
| + * @class
|
| + */
|
| + function ManagedUserList() {
|
| + this.callbacks_ = [];
|
| + this.errbacks_ = [];
|
| + this.requestInProgress_ = false;
|
| + this.managedUsers = null;
|
| + };
|
| +
|
| + cr.addSingletonGetter(ManagedUserList);
|
| +
|
| + /**
|
| + * Resets to the initial state of no pending requests.
|
| + * @private
|
| + */
|
| + ManagedUserList.prototype.reset_ = function() {
|
| + this.callbacks_ = [];
|
| + this.errbacks_ = [];
|
| + this.requestInProgress_ = false;
|
| + }
|
| +
|
| + /**
|
| + * Receives a list of managed users and passes the list to each of the
|
| + * callbacks.
|
| + * @param {Array.<Object>} managedUsers An array of managed user objects.
|
| + * Each object is of the form:
|
| + * managedUser = {
|
| + * id: "Managed User ID",
|
| + * name: "Managed User Name",
|
| + * iconURL: "chrome://path/to/icon/image",
|
| + * onCurrentDevice: true or false,
|
| + * needAvatar: true or false
|
| + * }
|
| + */
|
| + ManagedUserList.receiveExistingManagedUsers = function(managedUsers) {
|
| + var instance = ManagedUserList.getInstance();
|
| + var i;
|
| + for (i = 0; i < instance.callbacks_.length; i++) {
|
| + instance.callbacks_[i](managedUsers);
|
| + }
|
| + this.managedUsers = managedUsers;
|
| + instance.reset_();
|
| + };
|
| +
|
| + /**
|
| + * Called when there is a signin error when retrieving the list of managed
|
| + * users. Calls the error callbacks which will display an appropriate error
|
| + * message to the user.
|
| + */
|
| + ManagedUserList.onSigninError = function() {
|
| + var instance = ManagedUserList.getInstance();
|
| + var i;
|
| + for (i = 0; i < instance.errbacks_.length; i++) {
|
| + instance.errbacks_[i]();
|
| + }
|
| + // Reset the list of managed users in order to avoid showing stale data.
|
| + instance.managedUsers = null;
|
| + instance.reset_();
|
| + };
|
| +
|
| + /**
|
| + * Handles the request for the list of existing managed users. If the data is
|
| + * already available, it will call |callback| immediately. Otherwise, it
|
| + * retrieves the list of existing managed users which is then processed in
|
| + * receiveExistingManagedUsers().
|
| + * @param {Object} callback The callback function which is called on success.
|
| + * @param {Object} errback the callback function which is called on error.
|
| + */
|
| + ManagedUserList.requestExistingManagedUsers = function(callback, errback) {
|
| + var instance = ManagedUserList.getInstance();
|
| + instance.callbacks_.push(callback);
|
| + instance.errbacks_.push(errback);
|
| + if (!instance.requestInProgress_) {
|
| + if (instance.managedUsers != null) {
|
| + ManagedUserList.receiveExistingManagedUsers(instance.managedUsers);
|
| + return;
|
| + }
|
| + instance.requestInProgress_ = true;
|
| + chrome.send('requestManagedUserImportUpdate');
|
| + }
|
| + };
|
| +
|
| + /**
|
| * ManagedUserImportOverlay class.
|
| * Encapsulated handling of the 'Import existing managed user' overlay page.
|
| * @constructor
|
| @@ -75,7 +164,8 @@ cr.define('options', function() {
|
| * @override
|
| */
|
| didShowPage: function() {
|
| - chrome.send('requestManagedUserImportUpdate');
|
| + ManagedUserList.requestExistingManagedUsers(
|
| + this.receiveExistingManagedUsers_, this.onSigninError_.bind(this));
|
|
|
| this.updateImportInProgress_(false);
|
| $('managed-user-import-error-bubble').hidden = true;
|
| @@ -157,8 +247,7 @@ cr.define('options', function() {
|
| },
|
|
|
| /**
|
| - * Adds all the existing |managedUsers| to the list. If |managedUsers|
|
| - * is undefined, then the list is cleared.
|
| + * Sets the data model of the managed user list to |managedUsers|.
|
| * @param {Array.<Object>} managedUsers An array of managed user objects.
|
| * Each object is of the form:
|
| * managedUser = {
|
| @@ -171,11 +260,6 @@ cr.define('options', function() {
|
| * @private
|
| */
|
| receiveExistingManagedUsers_: function(managedUsers) {
|
| - if (!managedUsers) {
|
| - $('managed-user-list').dataModel = null;
|
| - return;
|
| - }
|
| -
|
| managedUsers.sort(function(a, b) {
|
| return a.name.localeCompare(b.name);
|
| });
|
| @@ -184,14 +268,15 @@ cr.define('options', function() {
|
| if (managedUsers.length == 0) {
|
| this.onError_(loadTimeData.getString('noExistingManagedUsers'));
|
| $('managed-user-import-ok').disabled = true;
|
| + } else {
|
| + // Hide the error bubble.
|
| + $('managed-user-import-error-bubble').hidden = true;
|
| }
|
| },
|
|
|
| - /**
|
| - * @private
|
| - */
|
| - hideErrorBubble_: function() {
|
| - $('managed-user-import-error-bubble').hidden = true;
|
| + onSigninError_: function() {
|
| + $('managed-user-list').dataModel = null;
|
| + this.onError_(loadTimeData.getString('managedUserImportSigninError'));
|
| },
|
|
|
| /**
|
| @@ -220,10 +305,7 @@ cr.define('options', function() {
|
|
|
| // Forward public APIs to private implementations.
|
| [
|
| - 'hideErrorBubble',
|
| - 'onError',
|
| 'onSuccess',
|
| - 'receiveExistingManagedUsers',
|
| ].forEach(function(name) {
|
| ManagedUserImportOverlay[name] = function() {
|
| var instance = ManagedUserImportOverlay.getInstance();
|
| @@ -234,5 +316,6 @@ cr.define('options', function() {
|
| // Export
|
| return {
|
| ManagedUserImportOverlay: ManagedUserImportOverlay,
|
| + ManagedUserList: ManagedUserList,
|
| };
|
| });
|
|
|