| OLD | NEW |
| 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 * ManagedUserImportOverlay class. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 $('create-new-user-link').onclick = function(event) { | 68 $('create-new-user-link').onclick = function(event) { |
| 69 OptionsPage.closeOverlay(); | 69 OptionsPage.closeOverlay(); |
| 70 OptionsPage.navigateToPage('createProfile'); | 70 OptionsPage.navigateToPage('createProfile'); |
| 71 }; | 71 }; |
| 72 }, | 72 }, |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @override | 75 * @override |
| 76 */ | 76 */ |
| 77 didShowPage: function() { | 77 didShowPage: function() { |
| 78 chrome.send('requestManagedUserImportUpdate'); | 78 options.ManagedUserListData.requestExistingManagedUsers( |
| 79 this.receiveExistingManagedUsers_, this.onSigninError_.bind(this)); |
| 79 | 80 |
| 80 this.updateImportInProgress_(false); | 81 this.updateImportInProgress_(false); |
| 81 $('managed-user-import-error-bubble').hidden = true; | 82 $('managed-user-import-error-bubble').hidden = true; |
| 82 $('managed-user-import-ok').disabled = true; | 83 $('managed-user-import-ok').disabled = true; |
| 83 $('select-avatar-grid').hidden = true; | 84 $('select-avatar-grid').hidden = true; |
| 84 $('managed-user-list').hidden = false; | 85 $('managed-user-list').hidden = false; |
| 85 | 86 |
| 86 $('managed-user-import-ok').textContent = | 87 $('managed-user-import-ok').textContent = |
| 87 loadTimeData.getString('managedUserImportOk'); | 88 loadTimeData.getString('managedUserImportOk'); |
| 88 $('managed-user-import-text').textContent = | 89 $('managed-user-import-text').textContent = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 112 } | 113 } |
| 113 | 114 |
| 114 var avatarUrl = managedUser.needAvatar ? | 115 var avatarUrl = managedUser.needAvatar ? |
| 115 $('select-avatar-grid').selectedItem : managedUser.iconURL; | 116 $('select-avatar-grid').selectedItem : managedUser.iconURL; |
| 116 | 117 |
| 117 this.updateImportInProgress_(true); | 118 this.updateImportInProgress_(true); |
| 118 | 119 |
| 119 // 'createProfile' is handled by CreateProfileHandler. | 120 // 'createProfile' is handled by CreateProfileHandler. |
| 120 chrome.send('createProfile', [managedUser.name, avatarUrl, | 121 chrome.send('createProfile', [managedUser.name, avatarUrl, |
| 121 false, true, managedUser.id]); | 122 false, true, managedUser.id]); |
| 123 options.ManagedUserListData.reloadExistingManagedUsers(); |
| 122 }, | 124 }, |
| 123 | 125 |
| 124 /** | 126 /** |
| 125 * Hides the 'managed user list' and shows the avatar grid instead. | 127 * Hides the 'managed user list' and shows the avatar grid instead. |
| 126 * It also updates the overlay text and title to instruct the user | 128 * It also updates the overlay text and title to instruct the user |
| 127 * to choose an avatar for the supervised user. | 129 * to choose an avatar for the supervised user. |
| 128 * @private | 130 * @private |
| 129 */ | 131 */ |
| 130 showAvatarGridHelper_: function() { | 132 showAvatarGridHelper_: function() { |
| 131 $('managed-user-list').hidden = true; | 133 $('managed-user-list').hidden = true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 150 */ | 152 */ |
| 151 updateImportInProgress_: function(inProgress) { | 153 updateImportInProgress_: function(inProgress) { |
| 152 $('managed-user-import-ok').disabled = inProgress; | 154 $('managed-user-import-ok').disabled = inProgress; |
| 153 $('managed-user-list').disabled = inProgress; | 155 $('managed-user-list').disabled = inProgress; |
| 154 $('select-avatar-grid').disabled = inProgress; | 156 $('select-avatar-grid').disabled = inProgress; |
| 155 $('create-new-user-link').disabled = inProgress; | 157 $('create-new-user-link').disabled = inProgress; |
| 156 $('managed-user-import-throbber').hidden = !inProgress; | 158 $('managed-user-import-throbber').hidden = !inProgress; |
| 157 }, | 159 }, |
| 158 | 160 |
| 159 /** | 161 /** |
| 160 * Adds all the existing |managedUsers| to the list. If |managedUsers| | 162 * Sets the data model of the managed user list to |managedUsers|. |
| 161 * is undefined, then the list is cleared. | |
| 162 * @param {Array.<Object>} managedUsers An array of managed user objects. | 163 * @param {Array.<Object>} managedUsers An array of managed user objects. |
| 163 * Each object is of the form: | 164 * Each object is of the form: |
| 164 * managedUser = { | 165 * managedUser = { |
| 165 * id: "Managed User ID", | 166 * id: "Managed User ID", |
| 166 * name: "Managed User Name", | 167 * name: "Managed User Name", |
| 167 * iconURL: "chrome://path/to/icon/image", | 168 * iconURL: "chrome://path/to/icon/image", |
| 168 * onCurrentDevice: true or false, | 169 * onCurrentDevice: true or false, |
| 169 * needAvatar: true or false | 170 * needAvatar: true or false |
| 170 * } | 171 * } |
| 171 * @private | 172 * @private |
| 172 */ | 173 */ |
| 173 receiveExistingManagedUsers_: function(managedUsers) { | 174 receiveExistingManagedUsers_: function(managedUsers) { |
| 174 if (!managedUsers) { | |
| 175 $('managed-user-list').dataModel = null; | |
| 176 return; | |
| 177 } | |
| 178 | |
| 179 managedUsers.sort(function(a, b) { | 175 managedUsers.sort(function(a, b) { |
| 180 return a.name.localeCompare(b.name); | 176 return a.name.localeCompare(b.name); |
| 181 }); | 177 }); |
| 182 | 178 |
| 183 $('managed-user-list').dataModel = new ArrayDataModel(managedUsers); | 179 $('managed-user-list').dataModel = new ArrayDataModel(managedUsers); |
| 184 if (managedUsers.length == 0) { | 180 if (managedUsers.length == 0) { |
| 185 this.onError_(loadTimeData.getString('noExistingManagedUsers')); | 181 this.onError_(loadTimeData.getString('noExistingManagedUsers')); |
| 186 $('managed-user-import-ok').disabled = true; | 182 $('managed-user-import-ok').disabled = true; |
| 183 } else { |
| 184 // Hide the error bubble. |
| 185 $('managed-user-import-error-bubble').hidden = true; |
| 187 } | 186 } |
| 188 }, | 187 }, |
| 189 | 188 |
| 190 /** | 189 onSigninError_: function() { |
| 191 * @private | 190 $('managed-user-list').dataModel = null; |
| 192 */ | 191 this.onError_(loadTimeData.getString('managedUserImportSigninError')); |
| 193 hideErrorBubble_: function() { | |
| 194 $('managed-user-import-error-bubble').hidden = true; | |
| 195 }, | 192 }, |
| 196 | 193 |
| 197 /** | 194 /** |
| 198 * Displays an error message if an error occurs while | 195 * Displays an error message if an error occurs while |
| 199 * importing a managed user. | 196 * importing a managed user. |
| 200 * Called by BrowserOptions via the BrowserOptionsHandler. | 197 * Called by BrowserOptions via the BrowserOptionsHandler. |
| 201 * @param {string} error The error message to display. | 198 * @param {string} error The error message to display. |
| 202 * @private | 199 * @private |
| 203 */ | 200 */ |
| 204 onError_: function(error) { | 201 onError_: function(error) { |
| 205 var errorBubble = $('managed-user-import-error-bubble'); | 202 var errorBubble = $('managed-user-import-error-bubble'); |
| 206 errorBubble.hidden = false; | 203 errorBubble.hidden = false; |
| 207 errorBubble.textContent = error; | 204 errorBubble.textContent = error; |
| 208 this.updateImportInProgress_(false); | 205 this.updateImportInProgress_(false); |
| 209 }, | 206 }, |
| 210 | 207 |
| 211 /** | 208 /** |
| 212 * Closes the overlay if importing the managed user was successful. | 209 * Closes the overlay if importing the managed user was successful. |
| 213 * @private | 210 * @private |
| 214 */ | 211 */ |
| 215 onSuccess_: function() { | 212 onSuccess_: function() { |
| 216 this.updateImportInProgress_(false); | 213 this.updateImportInProgress_(false); |
| 217 OptionsPage.closeOverlay(); | 214 OptionsPage.closeOverlay(); |
| 218 }, | 215 }, |
| 219 }; | 216 }; |
| 220 | 217 |
| 221 // Forward public APIs to private implementations. | 218 // Forward public APIs to private implementations. |
| 222 [ | 219 [ |
| 223 'hideErrorBubble', | |
| 224 'onError', | |
| 225 'onSuccess', | 220 'onSuccess', |
| 226 'receiveExistingManagedUsers', | |
| 227 ].forEach(function(name) { | 221 ].forEach(function(name) { |
| 228 ManagedUserImportOverlay[name] = function() { | 222 ManagedUserImportOverlay[name] = function() { |
| 229 var instance = ManagedUserImportOverlay.getInstance(); | 223 var instance = ManagedUserImportOverlay.getInstance(); |
| 230 return instance[name + '_'].apply(instance, arguments); | 224 return instance[name + '_'].apply(instance, arguments); |
| 231 }; | 225 }; |
| 232 }); | 226 }); |
| 233 | 227 |
| 234 // Export | 228 // Export |
| 235 return { | 229 return { |
| 236 ManagedUserImportOverlay: ManagedUserImportOverlay, | 230 ManagedUserImportOverlay: ManagedUserImportOverlay, |
| 237 }; | 231 }; |
| 238 }); | 232 }); |
| OLD | NEW |