this.showAvatarGridOrSubmit_.bind(this);
$('create-new-user-link').onclick = function(event) {
- OptionsPage.closeOverlay();
+ options.ManagedUserListData.removeObserver(self);
OptionsPage.navigateToPage('createProfile');
};
},
* @override
*/
didShowPage: function() {
- chrome.send('requestManagedUserImportUpdate');
+ options.ManagedUserListData.requestExistingManagedUsers().then(
+ this.receiveExistingManagedUsers_, this.onSigninError_.bind(this));
+ options.ManagedUserListData.addObserver(this);
this.updateImportInProgress_(false);
$('managed-user-import-error-bubble').hidden = true;
},
/**
+ * @override
+ */
+ didClosePage: function() {
+ options.ManagedUserListData.removeObserver(this);
+ },
+
+ /**
* Called when the user clicks the "OK" button. In case the managed
* user being imported has no avatar in sync, it shows the avatar
* icon grid. In case the avatar grid is visible or the managed user
},
/**
- * 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 = {
* @private
*/
receiveExistingManagedUsers_: function(managedUsers) {
- if (!managedUsers) {
- $('managed-user-list').dataModel = null;
- return;
- }
-
managedUsers.sort(function(a, b) {
+ if (a.onCurrentDevice != b.onCurrentDevice)
+ return a.onCurrentDevice ? 1 : -1;
return a.name.localeCompare(b.name);
});
$('managed-user-list').dataModel = new ArrayDataModel(managedUsers);
- if (managedUsers.length == 0)
+ 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'));
},
/**
},
/**
- * Closes the overlay if importing the managed user was successful.
+ * Closes the overlay if importing the managed user was successful. Also
+ * reset the cached list of managed users in order to get an updated list
+ * when the overlay is reopened.
* @private
*/
onSuccess_: function() {
this.updateImportInProgress_(false);
+ options.ManagedUserListData.resetPromise();
OptionsPage.closeOverlay();
},
};
// Forward public APIs to private implementations.
[
- 'hideErrorBubble',
- 'onError',
'onSuccess',
- 'receiveExistingManagedUsers',
].forEach(function(name) {
ManagedUserImportOverlay[name] = function() {
var instance = ManagedUserImportOverlay.getInstance();