| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 managedUserList.addEventListener('change', function(event) { | 47 managedUserList.addEventListener('change', function(event) { |
| 48 var managedUser = managedUserList.selectedItem; | 48 var managedUser = managedUserList.selectedItem; |
| 49 if (!managedUser) | 49 if (!managedUser) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 $('managed-user-import-ok').disabled = | 52 $('managed-user-import-ok').disabled = |
| 53 managedUserList.selectedItem.onCurrentDevice; | 53 managedUserList.selectedItem.onCurrentDevice; |
| 54 }); | 54 }); |
| 55 | 55 |
| 56 var self = this; |
| 56 $('managed-user-import-cancel').onclick = function(event) { | 57 $('managed-user-import-cancel').onclick = function(event) { |
| 57 OptionsPage.closeOverlay(); | 58 OptionsPage.closeOverlay(); |
| 59 self.updateImportInProgress_(false); |
| 60 |
| 58 // 'cancelCreateProfile' is handled by BrowserOptionsHandler. | 61 // 'cancelCreateProfile' is handled by BrowserOptionsHandler. |
| 59 chrome.send('cancelCreateProfile'); | 62 chrome.send('cancelCreateProfile'); |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 $('managed-user-import-ok').onclick = | 65 $('managed-user-import-ok').onclick = |
| 63 this.showAvatarGridOrSubmit_.bind(this); | 66 this.showAvatarGridOrSubmit_.bind(this); |
| 64 | 67 |
| 65 $('create-new-user-link').onclick = function(event) { | 68 $('create-new-user-link').onclick = function(event) { |
| 66 OptionsPage.closeOverlay(); | 69 OptionsPage.closeOverlay(); |
| 67 OptionsPage.navigateToPage('createProfile'); | 70 OptionsPage.navigateToPage('createProfile'); |
| 68 }; | 71 }; |
| 69 }, | 72 }, |
| 70 | 73 |
| 71 /** | 74 /** |
| 72 * @override | 75 * @override |
| 73 */ | 76 */ |
| 74 didShowPage: function() { | 77 didShowPage: function() { |
| 75 chrome.send('requestExistingManagedUsers'); | 78 chrome.send('requestExistingManagedUsers'); |
| 79 |
| 80 this.updateImportInProgress_(false); |
| 76 $('managed-user-import-error-bubble').hidden = true; | 81 $('managed-user-import-error-bubble').hidden = true; |
| 77 $('managed-user-import-ok').disabled = true; | 82 $('managed-user-import-ok').disabled = true; |
| 78 $('select-avatar-grid').hidden = true; | 83 $('select-avatar-grid').hidden = true; |
| 79 $('managed-user-list').hidden = false; | 84 $('managed-user-list').hidden = false; |
| 80 | 85 |
| 81 $('managed-user-import-ok').textContent = | 86 $('managed-user-import-ok').textContent = |
| 82 loadTimeData.getString('managedUserImportOk'); | 87 loadTimeData.getString('managedUserImportOk'); |
| 83 $('managed-user-import-text').textContent = | 88 $('managed-user-import-text').textContent = |
| 84 loadTimeData.getString('managedUserImportText'); | 89 loadTimeData.getString('managedUserImportText'); |
| 85 $('managed-user-import-title').textContent = | 90 $('managed-user-import-title').textContent = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 99 if (!managedUser) | 104 if (!managedUser) |
| 100 return; | 105 return; |
| 101 | 106 |
| 102 $('managed-user-import-error-bubble').hidden = true; | 107 $('managed-user-import-error-bubble').hidden = true; |
| 103 | 108 |
| 104 if ($('select-avatar-grid').hidden && managedUser.needAvatar) { | 109 if ($('select-avatar-grid').hidden && managedUser.needAvatar) { |
| 105 this.showAvatarGridHelper_(); | 110 this.showAvatarGridHelper_(); |
| 106 return; | 111 return; |
| 107 } | 112 } |
| 108 | 113 |
| 109 $('managed-user-import-ok').disabled = true; | |
| 110 var avatarUrl = managedUser.needAvatar ? | 114 var avatarUrl = managedUser.needAvatar ? |
| 111 $('select-avatar-grid').selectedItem : managedUser.iconURL; | 115 $('select-avatar-grid').selectedItem : managedUser.iconURL; |
| 112 | 116 |
| 117 this.updateImportInProgress_(true); |
| 118 |
| 113 // 'createProfile' is handled by BrowserOptionsHandler. | 119 // 'createProfile' is handled by BrowserOptionsHandler. |
| 114 chrome.send('createProfile', [managedUser.name, avatarUrl, | 120 chrome.send('createProfile', [managedUser.name, avatarUrl, |
| 115 false, true, managedUser.id]); | 121 false, true, managedUser.id]); |
| 116 }, | 122 }, |
| 117 | 123 |
| 118 /** | 124 /** |
| 119 * Hides the 'managed user list' and shows the avatar grid instead. | 125 * Hides the 'managed user list' and shows the avatar grid instead. |
| 120 * It also updates the overlay text and title to instruct the user | 126 * It also updates the overlay text and title to instruct the user |
| 121 * to choose an avatar for the supervised user. | 127 * to choose an avatar for the supervised user. |
| 122 * @private | 128 * @private |
| 123 */ | 129 */ |
| 124 showAvatarGridHelper_: function() { | 130 showAvatarGridHelper_: function() { |
| 125 $('managed-user-list').hidden = true; | 131 $('managed-user-list').hidden = true; |
| 126 $('select-avatar-grid').hidden = false; | 132 $('select-avatar-grid').hidden = false; |
| 127 $('select-avatar-grid').redraw(); | 133 $('select-avatar-grid').redraw(); |
| 128 $('select-avatar-grid').selectedItem = | 134 $('select-avatar-grid').selectedItem = |
| 129 loadTimeData.getValue('avatarIcons')[0]; | 135 loadTimeData.getValue('avatarIcons')[0]; |
| 130 | 136 |
| 131 $('managed-user-import-ok').textContent = | 137 $('managed-user-import-ok').textContent = |
| 132 loadTimeData.getString('managedUserSelectAvatarOk'); | 138 loadTimeData.getString('managedUserSelectAvatarOk'); |
| 133 $('managed-user-import-text').textContent = | 139 $('managed-user-import-text').textContent = |
| 134 loadTimeData.getString('managedUserSelectAvatarText'); | 140 loadTimeData.getString('managedUserSelectAvatarText'); |
| 135 $('managed-user-import-title').textContent = | 141 $('managed-user-import-title').textContent = |
| 136 loadTimeData.getString('managedUserSelectAvatarTitle'); | 142 loadTimeData.getString('managedUserSelectAvatarTitle'); |
| 137 }, | 143 }, |
| 138 | 144 |
| 139 /** | 145 /** |
| 146 * Updates the UI according to the importing state. |
| 147 * @param {boolean} inProgress True to indicate that |
| 148 * importing is in progress and false otherwise. |
| 149 * @private |
| 150 */ |
| 151 updateImportInProgress_: function(inProgress) { |
| 152 $('managed-user-import-ok').disabled = inProgress; |
| 153 $('managed-user-list').disabled = inProgress; |
| 154 $('select-avatar-grid').disabled = inProgress; |
| 155 $('create-new-user-link').disabled = inProgress; |
| 156 $('managed-user-import-throbber').hidden = !inProgress; |
| 157 }, |
| 158 |
| 159 /** |
| 140 * Adds all the existing |managedUsers| to the list. | 160 * Adds all the existing |managedUsers| to the list. |
| 141 * @param {Array.<Object>} managedUsers An array of managed user objects. | 161 * @param {Array.<Object>} managedUsers An array of managed user objects. |
| 142 * Each object is of the form: | 162 * Each object is of the form: |
| 143 * managedUser = { | 163 * managedUser = { |
| 144 * id: "Managed User ID", | 164 * id: "Managed User ID", |
| 145 * name: "Managed User Name", | 165 * name: "Managed User Name", |
| 146 * iconURL: "chrome://path/to/icon/image", | 166 * iconURL: "chrome://path/to/icon/image", |
| 147 * onCurrentDevice: true or false, | 167 * onCurrentDevice: true or false, |
| 148 * needAvatar: true or false | 168 * needAvatar: true or false |
| 149 * } | 169 * } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 163 * Displays an error message if an error occurs while | 183 * Displays an error message if an error occurs while |
| 164 * importing a managed user. | 184 * importing a managed user. |
| 165 * Called by BrowserOptions via the BrowserOptionsHandler. | 185 * Called by BrowserOptions via the BrowserOptionsHandler. |
| 166 * @param {string} error The error message to display. | 186 * @param {string} error The error message to display. |
| 167 * @private | 187 * @private |
| 168 */ | 188 */ |
| 169 onError_: function(error) { | 189 onError_: function(error) { |
| 170 var errorBubble = $('managed-user-import-error-bubble'); | 190 var errorBubble = $('managed-user-import-error-bubble'); |
| 171 errorBubble.hidden = false; | 191 errorBubble.hidden = false; |
| 172 errorBubble.textContent = error; | 192 errorBubble.textContent = error; |
| 193 this.updateImportInProgress_(false); |
| 173 }, | 194 }, |
| 174 | 195 |
| 175 /** | 196 /** |
| 176 * Closes the overlay if importing the managed user was successful. | 197 * Closes the overlay if importing the managed user was successful. |
| 177 * @private | 198 * @private |
| 178 */ | 199 */ |
| 179 onSuccess_: function() { | 200 onSuccess_: function() { |
| 201 this.updateImportInProgress_(false); |
| 180 OptionsPage.closeOverlay(); | 202 OptionsPage.closeOverlay(); |
| 181 }, | 203 }, |
| 182 }; | 204 }; |
| 183 | 205 |
| 184 // Forward public APIs to private implementations. | 206 // Forward public APIs to private implementations. |
| 185 [ | 207 [ |
| 186 'onError', | 208 'onError', |
| 187 'onSuccess', | 209 'onSuccess', |
| 188 'receiveExistingManagedUsers', | 210 'receiveExistingManagedUsers', |
| 189 ].forEach(function(name) { | 211 ].forEach(function(name) { |
| 190 ManagedUserImportOverlay[name] = function() { | 212 ManagedUserImportOverlay[name] = function() { |
| 191 var instance = ManagedUserImportOverlay.getInstance(); | 213 var instance = ManagedUserImportOverlay.getInstance(); |
| 192 return instance[name + '_'].apply(instance, arguments); | 214 return instance[name + '_'].apply(instance, arguments); |
| 193 }; | 215 }; |
| 194 }); | 216 }); |
| 195 | 217 |
| 196 // Export | 218 // Export |
| 197 return { | 219 return { |
| 198 ManagedUserImportOverlay: ManagedUserImportOverlay, | 220 ManagedUserImportOverlay: ManagedUserImportOverlay, |
| 199 }; | 221 }; |
| 200 }); | 222 }); |
| OLD | NEW |