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

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

Powered by Google App Engine
This is Rietveld 408576698