1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('options', function() {
var OptionsPage = options.OptionsPage;
var ArrayDataModel = cr.ui.ArrayDataModel;
/**
* ManagedUserImportOverlay class.
* Encapsulated handling of the 'Import existing managed user' overlay page.
* @constructor
* @class
*/
function ManagedUserImportOverlay() {
var title = loadTimeData.getString('managedUserImportTitle');
OptionsPage.call(this, 'managedUserImport',
title, 'managed-user-import');
};
cr.addSingletonGetter(ManagedUserImportOverlay);
ManagedUserImportOverlay.prototype = {
// Inherit from OptionsPage.
__proto__: OptionsPage.prototype,
/** @override */
canShowPage: function() {
return !BrowserOptions.getCurrentProfile().isManaged;
},
/**
* Initialize the page.
*/
initializePage: function() {
// Call base class implementation to start preference initialization.
OptionsPage.prototype.initializePage.call(this);
var managedUserList = $('managed-user-list');
options.managedUserOptions.ManagedUserList.decorate(managedUserList);
var avatarGrid = $('select-avatar-grid');
options.ProfilesIconGrid.decorate(avatarGrid);
var avatarIcons = loadTimeData.getValue('avatarIcons');
avatarGrid.dataModel = new ArrayDataModel(avatarIcons);
managedUserList.addEventListener('change', function(event) {
var managedUser = managedUserList.selectedItem;
if (!managedUser)
return;
$('managed-user-import-ok').disabled =
managedUserList.selectedItem.onCurrentDevice;
});
var self = this;
$('managed-user-import-cancel').onclick = function(event) {
OptionsPage.closeOverlay();
self.updateImportInProgress_(false);
// 'cancelCreateProfile' is handled by CreateProfileHandler.
chrome.send('cancelCreateProfile');
};
$('managed-user-import-ok').onclick =
this.showAvatarGridOrSubmit_.bind(this);
$('create-new-user-link').onclick = function(event) {
OptionsPage.closeOverlay();
OptionsPage.navigateToPage('createProfile');
};
},
/**
* @override
*/
didShowPage: function() {
options.ManagedUserListData.requestExistingManagedUsers().then(
this.receiveExistingManagedUsers_, this.onSigninError_.bind(this));
this.updateImportInProgress_(false);
$('managed-user-import-error-bubble').hidden = true;
$('managed-user-import-ok').disabled = true;
$('select-avatar-grid').hidden = true;
$('managed-user-list').hidden = false;
$('managed-user-import-ok').textContent =
loadTimeData.getString('managedUserImportOk');
$('managed-user-import-text').textContent =
loadTimeData.getString('managedUserImportText');
$('managed-user-import-title').textContent =
loadTimeData.getString('managedUserImportTitle');
},
/**
* 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
* already has an avatar stored in sync, it proceeds with importing
* the managed user.
* @private
*/
showAvatarGridOrSubmit_: function() {
var managedUser = $('managed-user-list').selectedItem;
if (!managedUser)
return;
$('managed-user-import-error-bubble').hidden = true;
if ($('select-avatar-grid').hidden && managedUser.needAvatar) {
this.showAvatarGridHelper_();
return;
}
var avatarUrl = managedUser.needAvatar ?
$('select-avatar-grid').selectedItem : managedUser.iconURL;
this.updateImportInProgress_(true);
// 'createProfile' is handled by CreateProfileHandler.
chrome.send('createProfile', [managedUser.name, avatarUrl,
false, true, managedUser.id]);
options.ManagedUserListData.reloadExistingManagedUsers();
},
/**
* Hides the 'managed user list' and shows the avatar grid instead.
* It also updates the overlay text and title to instruct the user
* to choose an avatar for the supervised user.
* @private
*/
showAvatarGridHelper_: function() {
$('managed-user-list').hidden = true;
$('select-avatar-grid').hidden = false;
$('select-avatar-grid').redraw();
$('select-avatar-grid').selectedItem =
loadTimeData.getValue('avatarIcons')[0];
$('managed-user-import-ok').textContent =
loadTimeData.getString('managedUserSelectAvatarOk');
$('managed-user-import-text').textContent =
loadTimeData.getString('managedUserSelectAvatarText');
$('managed-user-import-title').textContent =
loadTimeData.getString('managedUserSelectAvatarTitle');
},
/**
* Updates the UI according to the importing state.
* @param {boolean} inProgress True to indicate that
* importing is in progress and false otherwise.
* @private
*/
updateImportInProgress_: function(inProgress) {
$('managed-user-import-ok').disabled = inProgress;
$('managed-user-list').disabled = inProgress;
$('select-avatar-grid').disabled = inProgress;
$('create-new-user-link').disabled = inProgress;
$('managed-user-import-throbber').hidden = !inProgress;
},
/**
* 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 = {
* id: "Managed User ID",
* name: "Managed User Name",
* iconURL: "chrome://path/to/icon/image",
* onCurrentDevice: true or false,
* needAvatar: true or false
* }
* @private
*/
receiveExistingManagedUsers_: function(managedUsers) {
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) {
this.onError_(loadTimeData.getString('noExistingManagedUsers'));
$('managed-user-import-ok').disabled = true;
} else {
// Hide the error bubble.
$('managed-user-import-error-bubble').hidden = true;
}
},
onSigninError_: function() {
$('managed-user-list').dataModel = null;
this.onError_(loadTimeData.getString('managedUserImportSigninError'));
},
/**
* Displays an error message if an error occurs while
* importing a managed user.
* Called by BrowserOptions via the BrowserOptionsHandler.
* @param {string} error The error message to display.
* @private
*/
onError_: function(error) {
var errorBubble = $('managed-user-import-error-bubble');
errorBubble.hidden = false;
errorBubble.textContent = error;
this.updateImportInProgress_(false);
},
/**
* Closes the overlay if importing the managed user was successful.
* @private
*/
onSuccess_: function() {
this.updateImportInProgress_(false);
OptionsPage.closeOverlay();
},
};
// Forward public APIs to private implementations.
[
'onSuccess',
].forEach(function(name) {
ManagedUserImportOverlay[name] = function() {
var instance = ManagedUserImportOverlay.getInstance();
return instance[name + '_'].apply(instance, arguments);
};
});
// Export
return {
ManagedUserImportOverlay: ManagedUserImportOverlay,
};
});
|