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