Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/resources/options/supervised_user_import.js

Issue 403343002: Rename "managed (mode|user)" to "supervised user" (part 8) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 OptionsPage = options.OptionsPage; 6 var OptionsPage = options.OptionsPage;
7 var ArrayDataModel = cr.ui.ArrayDataModel; 7 var ArrayDataModel = cr.ui.ArrayDataModel;
8 8
9 /** 9 /**
10 * ManagedUserImportOverlay class. 10 * SupervisedUserImportOverlay class.
11 * Encapsulated handling of the 'Import existing managed user' overlay page. 11 * Encapsulated handling of the 'Import existing supervised user' overlay
12 * page.
12 * @constructor 13 * @constructor
13 * @class 14 * @class
14 */ 15 */
15 function ManagedUserImportOverlay() { 16 function SupervisedUserImportOverlay() {
16 var title = loadTimeData.getString('managedUserImportTitle'); 17 var title = loadTimeData.getString('supervisedUserImportTitle');
17 OptionsPage.call(this, 'managedUserImport', 18 OptionsPage.call(this, 'supervisedUserImport',
18 title, 'managed-user-import'); 19 title, 'supervised-user-import');
19 }; 20 };
20 21
21 cr.addSingletonGetter(ManagedUserImportOverlay); 22 cr.addSingletonGetter(SupervisedUserImportOverlay);
22 23
23 ManagedUserImportOverlay.prototype = { 24 SupervisedUserImportOverlay.prototype = {
24 // Inherit from OptionsPage. 25 // Inherit from OptionsPage.
25 __proto__: OptionsPage.prototype, 26 __proto__: OptionsPage.prototype,
26 27
27 /** @override */ 28 /** @override */
28 canShowPage: function() { 29 canShowPage: function() {
29 return !BrowserOptions.getCurrentProfile().isManaged; 30 return !BrowserOptions.getCurrentProfile().isSupervised;
30 }, 31 },
31 32
32 /** @override */ 33 /** @override */
33 initializePage: function() { 34 initializePage: function() {
34 // Call base class implementation to start preference initialization. 35 // Call base class implementation to start preference initialization.
35 OptionsPage.prototype.initializePage.call(this); 36 OptionsPage.prototype.initializePage.call(this);
36 37
37 var managedUserList = $('managed-user-list'); 38 var supervisedUserList = $('supervised-user-list');
38 options.managedUserOptions.ManagedUserList.decorate(managedUserList); 39 options.supervisedUserOptions.SupervisedUserList.decorate(
40 supervisedUserList);
39 41
40 var avatarGrid = $('select-avatar-grid'); 42 var avatarGrid = $('select-avatar-grid');
41 options.ProfilesIconGrid.decorate(avatarGrid); 43 options.ProfilesIconGrid.decorate(avatarGrid);
42 var avatarIcons = loadTimeData.getValue('avatarIcons'); 44 var avatarIcons = loadTimeData.getValue('avatarIcons');
43 avatarGrid.dataModel = new ArrayDataModel(avatarIcons); 45 avatarGrid.dataModel = new ArrayDataModel(avatarIcons);
44 46
45 managedUserList.addEventListener('change', function(event) { 47 supervisedUserList.addEventListener('change', function(event) {
46 var managedUser = managedUserList.selectedItem; 48 var supervisedUser = supervisedUserList.selectedItem;
47 if (!managedUser) 49 if (!supervisedUser)
48 return; 50 return;
49 51
50 $('managed-user-import-ok').disabled = 52 $('supervised-user-import-ok').disabled =
51 managedUserList.selectedItem.onCurrentDevice; 53 supervisedUserList.selectedItem.onCurrentDevice;
52 }); 54 });
53 55
54 var self = this; 56 var self = this;
55 $('managed-user-import-cancel').onclick = function(event) { 57 $('supervised-user-import-cancel').onclick = function(event) {
56 if (self.inProgress_) { 58 if (self.inProgress_) {
57 self.updateImportInProgress_(false); 59 self.updateImportInProgress_(false);
58 60
59 // 'cancelCreateProfile' is handled by CreateProfileHandler. 61 // 'cancelCreateProfile' is handled by CreateProfileHandler.
60 chrome.send('cancelCreateProfile'); 62 chrome.send('cancelCreateProfile');
61 } 63 }
62 OptionsPage.closeOverlay(); 64 OptionsPage.closeOverlay();
63 }; 65 };
64 66
65 $('managed-user-import-ok').onclick = 67 $('supervised-user-import-ok').onclick =
66 this.showAvatarGridOrSubmit_.bind(this); 68 this.showAvatarGridOrSubmit_.bind(this);
67 $('managed-user-select-avatar-ok').onclick = 69 $('supervised-user-select-avatar-ok').onclick =
68 this.showAvatarGridOrSubmit_.bind(this); 70 this.showAvatarGridOrSubmit_.bind(this);
69 }, 71 },
70 72
71 /** 73 /**
72 * @override 74 * @override
73 */ 75 */
74 didShowPage: function() { 76 didShowPage: function() {
75 // When the import link is clicked to open this overlay, it is hidden in 77 // When the import link is clicked to open this overlay, it is hidden in
76 // order to trigger a cursor update. We can show the import link again 78 // order to trigger a cursor update. We can show the import link again
77 // now. TODO(akuegel): Remove this temporary fix when crbug/246304 is 79 // now. TODO(akuegel): Remove this temporary fix when crbug/246304 is
78 // resolved. 80 // resolved.
79 $('import-existing-managed-user-link').hidden = false; 81 $('import-existing-supervised-user-link').hidden = false;
80 82
81 options.ManagedUserListData.requestExistingManagedUsers().then( 83 options.SupervisedUserListData.requestExistingSupervisedUsers().then(
82 this.receiveExistingManagedUsers_, this.onSigninError_.bind(this)); 84 this.receiveExistingSupervisedUsers_, this.onSigninError_.bind(this));
83 options.ManagedUserListData.addObserver(this); 85 options.SupervisedUserListData.addObserver(this);
84 86
85 this.updateImportInProgress_(false); 87 this.updateImportInProgress_(false);
86 $('managed-user-import-error-bubble').hidden = true; 88 $('supervised-user-import-error-bubble').hidden = true;
87 $('managed-user-import-ok').disabled = true; 89 $('supervised-user-import-ok').disabled = true;
88 this.showAppropriateElements_(/* isSelectAvatarMode */ false); 90 this.showAppropriateElements_(/* isSelectAvatarMode */ false);
89 }, 91 },
90 92
91 /** 93 /**
92 * @override 94 * @override
93 */ 95 */
94 didClosePage: function() { 96 didClosePage: function() {
95 options.ManagedUserListData.removeObserver(this); 97 options.SupervisedUserListData.removeObserver(this);
96 }, 98 },
97 99
98 /** 100 /**
99 * Shows either the managed user import dom elements or the select avatar 101 * Shows either the supervised user import dom elements or the select avatar
100 * dom elements. 102 * dom elements.
101 * @param {boolean} isSelectAvatarMode True if the overlay should show the 103 * @param {boolean} isSelectAvatarMode True if the overlay should show the
102 * select avatar grid, and false if the overlay should show the managed 104 * select avatar grid, and false if the overlay should show the
103 * user list. 105 * supervised user list.
104 * @private 106 * @private
105 */ 107 */
106 showAppropriateElements_: function(isSelectAvatarMode) { 108 showAppropriateElements_: function(isSelectAvatarMode) {
107 var avatarElements = 109 var avatarElements =
108 this.pageDiv.querySelectorAll('.managed-user-select-avatar'); 110 this.pageDiv.querySelectorAll('.supervised-user-select-avatar');
109 for (var i = 0; i < avatarElements.length; i++) 111 for (var i = 0; i < avatarElements.length; i++)
110 avatarElements[i].hidden = !isSelectAvatarMode; 112 avatarElements[i].hidden = !isSelectAvatarMode;
111 var importElements = 113 var importElements =
112 this.pageDiv.querySelectorAll('.managed-user-import'); 114 this.pageDiv.querySelectorAll('.supervised-user-import');
113 for (var i = 0; i < importElements.length; i++) 115 for (var i = 0; i < importElements.length; i++)
114 importElements[i].hidden = isSelectAvatarMode; 116 importElements[i].hidden = isSelectAvatarMode;
115 }, 117 },
116 118
117 /** 119 /**
118 * Called when the user clicks the "OK" button. In case the managed 120 * Called when the user clicks the "OK" button. In case the supervised
119 * user being imported has no avatar in sync, it shows the avatar 121 * user being imported has no avatar in sync, it shows the avatar
120 * icon grid. In case the avatar grid is visible or the managed user 122 * icon grid. In case the avatar grid is visible or the supervised user
121 * already has an avatar stored in sync, it proceeds with importing 123 * already has an avatar stored in sync, it proceeds with importing
122 * the managed user. 124 * the supervised user.
123 * @private 125 * @private
124 */ 126 */
125 showAvatarGridOrSubmit_: function() { 127 showAvatarGridOrSubmit_: function() {
126 var managedUser = $('managed-user-list').selectedItem; 128 var supervisedUser = $('supervised-user-list').selectedItem;
127 if (!managedUser) 129 if (!supervisedUser)
128 return; 130 return;
129 131
130 $('managed-user-import-error-bubble').hidden = true; 132 $('supervised-user-import-error-bubble').hidden = true;
131 133
132 if ($('select-avatar-grid').hidden && managedUser.needAvatar) { 134 if ($('select-avatar-grid').hidden && supervisedUser.needAvatar) {
133 this.showAvatarGridHelper_(); 135 this.showAvatarGridHelper_();
134 return; 136 return;
135 } 137 }
136 138
137 var avatarUrl = managedUser.needAvatar ? 139 var avatarUrl = supervisedUser.needAvatar ?
138 $('select-avatar-grid').selectedItem : managedUser.iconURL; 140 $('select-avatar-grid').selectedItem : supervisedUser.iconURL;
139 141
140 this.updateImportInProgress_(true); 142 this.updateImportInProgress_(true);
141 143
142 // 'createProfile' is handled by CreateProfileHandler. 144 // 'createProfile' is handled by CreateProfileHandler.
143 chrome.send('createProfile', [managedUser.name, avatarUrl, 145 chrome.send('createProfile', [supervisedUser.name, avatarUrl,
144 false, true, managedUser.id]); 146 false, true, supervisedUser.id]);
145 }, 147 },
146 148
147 /** 149 /**
148 * Hides the 'managed user list' and shows the avatar grid instead. 150 * Hides the 'supervised user list' and shows the avatar grid instead.
149 * It also updates the overlay text and title to instruct the user 151 * It also updates the overlay text and title to instruct the user
150 * to choose an avatar for the supervised user. 152 * to choose an avatar for the supervised user.
151 * @private 153 * @private
152 */ 154 */
153 showAvatarGridHelper_: function() { 155 showAvatarGridHelper_: function() {
154 this.showAppropriateElements_(/* isSelectAvatarMode */ true); 156 this.showAppropriateElements_(/* isSelectAvatarMode */ true);
155 $('select-avatar-grid').redraw(); 157 $('select-avatar-grid').redraw();
156 $('select-avatar-grid').selectedItem = 158 $('select-avatar-grid').selectedItem =
157 loadTimeData.getValue('avatarIcons')[0]; 159 loadTimeData.getValue('avatarIcons')[0];
158 }, 160 },
159 161
160 /** 162 /**
161 * Updates the UI according to the importing state. 163 * Updates the UI according to the importing state.
162 * @param {boolean} inProgress True to indicate that 164 * @param {boolean} inProgress True to indicate that
163 * importing is in progress and false otherwise. 165 * importing is in progress and false otherwise.
164 * @private 166 * @private
165 */ 167 */
166 updateImportInProgress_: function(inProgress) { 168 updateImportInProgress_: function(inProgress) {
167 this.inProgress_ = inProgress; 169 this.inProgress_ = inProgress;
168 $('managed-user-import-ok').disabled = inProgress; 170 $('supervised-user-import-ok').disabled = inProgress;
169 $('managed-user-select-avatar-ok').disabled = inProgress; 171 $('supervised-user-select-avatar-ok').disabled = inProgress;
170 $('managed-user-list').disabled = inProgress; 172 $('supervised-user-list').disabled = inProgress;
171 $('select-avatar-grid').disabled = inProgress; 173 $('select-avatar-grid').disabled = inProgress;
172 $('managed-user-import-throbber').hidden = !inProgress; 174 $('supervised-user-import-throbber').hidden = !inProgress;
173 }, 175 },
174 176
175 /** 177 /**
176 * Sets the data model of the managed user list to |managedUsers|. 178 * Sets the data model of the supervised user list to |supervisedUsers|.
177 * @param {Array.<Object>} managedUsers An array of managed user objects. 179 * @param {Array.<Object>} supervisedUsers Array of supervised user objects.
178 * Each object is of the form: 180 * Each object is of the form:
179 * managedUser = { 181 * supervisedUser = {
180 * id: "Managed User ID", 182 * id: "Supervised User ID",
181 * name: "Managed User Name", 183 * name: "Supervised User Name",
182 * iconURL: "chrome://path/to/icon/image", 184 * iconURL: "chrome://path/to/icon/image",
183 * onCurrentDevice: true or false, 185 * onCurrentDevice: true or false,
184 * needAvatar: true or false 186 * needAvatar: true or false
185 * } 187 * }
186 * @private 188 * @private
187 */ 189 */
188 receiveExistingManagedUsers_: function(managedUsers) { 190 receiveExistingSupervisedUsers_: function(supervisedUsers) {
189 managedUsers.sort(function(a, b) { 191 supervisedUsers.sort(function(a, b) {
190 if (a.onCurrentDevice != b.onCurrentDevice) 192 if (a.onCurrentDevice != b.onCurrentDevice)
191 return a.onCurrentDevice ? 1 : -1; 193 return a.onCurrentDevice ? 1 : -1;
192 return a.name.localeCompare(b.name); 194 return a.name.localeCompare(b.name);
193 }); 195 });
194 196
195 $('managed-user-list').dataModel = new ArrayDataModel(managedUsers); 197 $('supervised-user-list').dataModel = new ArrayDataModel(supervisedUsers);
196 if (managedUsers.length == 0) { 198 if (supervisedUsers.length == 0) {
197 this.onError_(loadTimeData.getString('noExistingManagedUsers')); 199 this.onError_(loadTimeData.getString('noExistingSupervisedUsers'));
198 $('managed-user-import-ok').disabled = true; 200 $('supervised-user-import-ok').disabled = true;
199 } else { 201 } else {
200 // Hide the error bubble. 202 // Hide the error bubble.
201 $('managed-user-import-error-bubble').hidden = true; 203 $('supervised-user-import-error-bubble').hidden = true;
202 } 204 }
203 }, 205 },
204 206
205 onSigninError_: function() { 207 onSigninError_: function() {
206 $('managed-user-list').dataModel = null; 208 $('supervised-user-list').dataModel = null;
207 this.onError_(loadTimeData.getString('managedUserImportSigninError')); 209 this.onError_(loadTimeData.getString('supervisedUserImportSigninError'));
208 }, 210 },
209 211
210 /** 212 /**
211 * Displays an error message if an error occurs while 213 * Displays an error message if an error occurs while
212 * importing a managed user. 214 * importing a supervised user.
213 * Called by BrowserOptions via the BrowserOptionsHandler. 215 * Called by BrowserOptions via the BrowserOptionsHandler.
214 * @param {string} error The error message to display. 216 * @param {string} error The error message to display.
215 * @private 217 * @private
216 */ 218 */
217 onError_: function(error) { 219 onError_: function(error) {
218 var errorBubble = $('managed-user-import-error-bubble'); 220 var errorBubble = $('supervised-user-import-error-bubble');
219 errorBubble.hidden = false; 221 errorBubble.hidden = false;
220 errorBubble.textContent = error; 222 errorBubble.textContent = error;
221 this.updateImportInProgress_(false); 223 this.updateImportInProgress_(false);
222 }, 224 },
223 225
224 /** 226 /**
225 * Closes the overlay if importing the managed user was successful. Also 227 * Closes the overlay if importing the supervised user was successful. Also
226 * reset the cached list of managed users in order to get an updated list 228 * reset the cached list of supervised users in order to get an updated list
227 * when the overlay is reopened. 229 * when the overlay is reopened.
228 * @private 230 * @private
229 */ 231 */
230 onSuccess_: function() { 232 onSuccess_: function() {
231 this.updateImportInProgress_(false); 233 this.updateImportInProgress_(false);
232 options.ManagedUserListData.resetPromise(); 234 options.SupervisedUserListData.resetPromise();
233 OptionsPage.closeAllOverlays(); 235 OptionsPage.closeAllOverlays();
234 }, 236 },
235 }; 237 };
236 238
237 // Forward public APIs to private implementations. 239 // Forward public APIs to private implementations.
238 [ 240 [
239 'onSuccess', 241 'onSuccess',
240 ].forEach(function(name) { 242 ].forEach(function(name) {
241 ManagedUserImportOverlay[name] = function() { 243 SupervisedUserImportOverlay[name] = function() {
242 var instance = ManagedUserImportOverlay.getInstance(); 244 var instance = SupervisedUserImportOverlay.getInstance();
243 return instance[name + '_'].apply(instance, arguments); 245 return instance[name + '_'].apply(instance, arguments);
244 }; 246 };
245 }); 247 });
246 248
247 // Export 249 // Export
248 return { 250 return {
249 ManagedUserImportOverlay: ManagedUserImportOverlay, 251 SupervisedUserImportOverlay: SupervisedUserImportOverlay,
250 }; 252 };
251 }); 253 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698