Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 6 |
|
James Hawkins
2011/12/02 18:12:01
Remove blank line while you're here.
Ivan Korotkov
2011/12/02 18:30:30
Done.
| |
| 7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
| 8 | 8 |
| 9 ///////////////////////////////////////////////////////////////////////////// | 9 ///////////////////////////////////////////////////////////////////////////// |
| 10 // AccountsOptions class: | 10 // AccountsOptions class: |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * Encapsulated handling of ChromeOS accounts options page. | 13 * Encapsulated handling of ChromeOS accounts options page. |
| 14 * @constructor | 14 * @constructor |
| 15 */ | 15 */ |
| 16 function AccountsOptions(model) { | 16 function AccountsOptions(model) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 // Set up accounts page. | 34 // Set up accounts page. |
| 35 var userList = $('userList'); | 35 var userList = $('userList'); |
| 36 | 36 |
| 37 var userNameEdit = $('userNameEdit'); | 37 var userNameEdit = $('userNameEdit'); |
| 38 options.accounts.UserNameEdit.decorate(userNameEdit); | 38 options.accounts.UserNameEdit.decorate(userNameEdit); |
| 39 userNameEdit.addEventListener('add', this.handleAddUser_); | 39 userNameEdit.addEventListener('add', this.handleAddUser_); |
| 40 | 40 |
| 41 // If the current user is not the owner, show some warning, | 41 // If the current user is not the owner, show some warning, |
| 42 // and do not show the user list. | 42 // and do not show the user list. |
| 43 if (AccountsOptions.currentUserIsOwner()) { | 43 this.allowWhitelist_ = AccountsOptions.currentUserIsOwner(); |
|
James Hawkins
2011/12/02 18:12:01
"Forward declare" and document this variable.
Ivan Korotkov
2011/12/02 18:30:30
Done.
| |
| 44 if (this.allowWhitelist_) { | |
| 44 options.accounts.UserList.decorate(userList); | 45 options.accounts.UserList.decorate(userList); |
| 45 } else { | 46 } else { |
| 46 if (!AccountsOptions.whitelistIsManaged()) { | 47 if (!AccountsOptions.whitelistIsManaged()) { |
| 47 $('ownerOnlyWarning').hidden = false; | 48 $('ownerOnlyWarning').hidden = false; |
| 48 } else { | 49 } else { |
| 49 this.managed = true; | 50 this.managed = true; |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 | 53 |
| 53 this.addEventListener('visibleChange', this.handleVisibleChange_); | 54 this.addEventListener('visibleChange', this.handleVisibleChange_); |
| 54 | 55 |
| 55 $('useWhitelistCheck').addEventListener('change', | 56 $('useWhitelistCheck').addEventListener('change', |
| 56 this.handleUseWhitelistCheckChange_.bind(this)); | 57 this.handleUseWhitelistCheckChange_.bind(this)); |
| 57 | 58 |
| 58 Preferences.getInstance().addEventListener( | 59 Preferences.getInstance().addEventListener( |
| 59 $('useWhitelistCheck').pref, | 60 $('useWhitelistCheck').pref, |
| 60 this.handleUseWhitelistPrefChange_.bind(this)); | 61 this.handleUseWhitelistPrefChange_.bind(this)); |
| 61 }, | 62 }, |
| 62 | 63 |
| 63 /** | 64 /** |
| 64 * Update user list control state. | 65 * Update user list control state. |
| 65 * @private | 66 * @private |
| 66 */ | 67 */ |
| 67 updateControls_: function() { | 68 updateControls_: function() { |
| 68 $('userList').disabled = | 69 $('userList').disabled = |
| 69 $('userNameEdit').disabled = !AccountsOptions.currentUserIsOwner() || | 70 $('userNameEdit').disabled = !this.allowWhitelist_ || |
| 70 AccountsOptions.whitelistIsManaged() || | 71 AccountsOptions.whitelistIsManaged() || |
| 71 !$('useWhitelistCheck').checked; | 72 !$('useWhitelistCheck').checked; |
| 72 }, | 73 }, |
| 73 | 74 |
| 74 /** | 75 /** |
| 75 * Handler for OptionsPage's visible property change event. | 76 * Handler for OptionsPage's visible property change event. |
| 76 * @private | 77 * @private |
| 77 * @param {Event} e Property change event. | 78 * @param {Event} e Property change event. |
| 78 */ | 79 */ |
| 79 handleVisibleChange_: function(e) { | 80 handleVisibleChange_: function(e) { |
| 80 if (this.visible) { | 81 if (this.visible) { |
| 81 this.updateControls_(); | 82 this.updateControls_(); |
| 82 if (AccountsOptions.currentUserIsOwner()) | 83 if (this.allowWhitelist_) |
| 83 $('userList').redraw(); | 84 $('userList').redraw(); |
| 84 } | 85 } |
| 85 }, | 86 }, |
| 86 | 87 |
| 87 /** | 88 /** |
| 88 * Handler for allow guest check change. | 89 * Handler for allow guest check change. |
| 89 * @private | 90 * @private |
| 90 */ | 91 */ |
| 91 handleUseWhitelistCheckChange_: function(e) { | 92 handleUseWhitelistCheckChange_: function(e) { |
| 92 // Whitelist existing users when guest login is being disabled. | 93 // Whitelist existing users when guest login is being disabled. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 104 handleUseWhitelistPrefChange_: function(e) { | 105 handleUseWhitelistPrefChange_: function(e) { |
| 105 this.updateControls_(); | 106 this.updateControls_(); |
| 106 }, | 107 }, |
| 107 | 108 |
| 108 /** | 109 /** |
| 109 * Handler for "add" event fired from userNameEdit. | 110 * Handler for "add" event fired from userNameEdit. |
| 110 * @private | 111 * @private |
| 111 * @param {Event} e Add event fired from userNameEdit. | 112 * @param {Event} e Add event fired from userNameEdit. |
| 112 */ | 113 */ |
| 113 handleAddUser_: function(e) { | 114 handleAddUser_: function(e) { |
| 114 AccountsOptions.addUsers([e.user]); | 115 console.log('Chrome -> whitelist "' + e.user.name + '" ' + e.user.email); |
|
James Hawkins
2011/12/02 18:12:01
Remove console spam.
Ivan Korotkov
2011/12/02 18:30:30
Oops, done.
| |
| 116 chrome.send('whitelistUser', [e.user.email, e.user.name]); | |
| 115 } | 117 } |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 /** | 120 /** |
| 119 * Returns whether the current user is owner or not. | 121 * Returns whether the current user is owner or not. |
| 120 */ | 122 */ |
| 121 AccountsOptions.currentUserIsOwner = function() { | 123 AccountsOptions.currentUserIsOwner = function() { |
| 122 return localStrings.getString('current_user_is_owner') == 'true'; | 124 return localStrings.getString('current_user_is_owner') == 'true'; |
| 123 }; | 125 }; |
| 124 | 126 |
| 125 /** | 127 /** |
| 126 * Returns whether we're currently in guest mode. | 128 * Returns whether we're currently in guest mode. |
| 127 */ | 129 */ |
| 128 AccountsOptions.loggedInAsGuest = function() { | 130 AccountsOptions.loggedInAsGuest = function() { |
| 129 return localStrings.getString('logged_in_as_guest') == 'true'; | 131 return localStrings.getString('logged_in_as_guest') == 'true'; |
| 130 }; | 132 }; |
| 131 | 133 |
| 132 /** | 134 /** |
| 133 * Returns whether the whitelist is managed by policy or not. | 135 * Returns whether the whitelist is managed by policy or not. |
| 134 */ | 136 */ |
| 135 AccountsOptions.whitelistIsManaged = function() { | 137 AccountsOptions.whitelistIsManaged = function() { |
| 136 return localStrings.getString('whitelist_is_managed') == 'true'; | 138 return localStrings.getString('whitelist_is_managed') == 'true'; |
| 137 }; | 139 }; |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * Adds given users to userList. | 142 * Adds given users to userList. |
| 143 * @param {Array.<Object>} users Array of user info objects. | |
| 141 */ | 144 */ |
| 142 AccountsOptions.addUsers = function(users) { | 145 AccountsOptions.addUsers = function(users) { |
| 143 var userList = $('userList'); | 146 var userList = $('userList'); |
| 144 for (var i = 0; i < users.length; ++i) { | 147 for (var i = 0; i < users.length; ++i) { |
| 145 userList.addUser(users[i]); | 148 userList.addUser(users[i]); |
| 146 } | 149 } |
| 147 }; | 150 }; |
| 148 | 151 |
| 149 /** | 152 /** |
| 150 * Update account picture. | 153 * Update account picture. |
| 151 * @param {string} email Email of the user to update. | 154 * @param {string} username User for which to update the image. |
| 152 */ | 155 */ |
| 153 AccountsOptions.updateAccountPicture = function(email) { | 156 AccountsOptions.updateAccountPicture = function(username) { |
| 154 if (this.currentUserIsOwner()) | 157 if (this.allowWhitelist_) |
| 155 $('userList').updateAccountPicture(email); | 158 $('userList').updateAccountPicture(username); |
| 156 }; | 159 }; |
| 157 | 160 |
| 158 // Export | 161 // Export |
| 159 return { | 162 return { |
| 160 AccountsOptions: AccountsOptions | 163 AccountsOptions: AccountsOptions |
| 161 }; | 164 }; |
| 162 | 165 |
| 163 }); | 166 }); |
| OLD | NEW |