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 | |
| 7 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
| 8 | 7 |
| 9 ///////////////////////////////////////////////////////////////////////////// | 8 ///////////////////////////////////////////////////////////////////////////// |
| 10 // AccountsOptions class: | 9 // AccountsOptions class: |
| 11 | 10 |
| 12 /** | 11 /** |
| 13 * Encapsulated handling of ChromeOS accounts options page. | 12 * Encapsulated handling of ChromeOS accounts options page. |
| 14 * @constructor | 13 * @constructor |
| 15 */ | 14 */ |
| 16 function AccountsOptions(model) { | 15 function AccountsOptions(model) { |
| 17 OptionsPage.call(this, 'accounts', templateData.accountsPageTabTitle, | 16 OptionsPage.call(this, 'accounts', templateData.accountsPageTabTitle, |
| 18 'accountsPage'); | 17 'accountsPage'); |
| 18 // Whether to show the whitelist. | |
| 19 this.allowWhitelist_ = false; | |
|
whywhat
2011/12/05 12:14:49
nit: rename to showWhitelist
Ivan Korotkov
2011/12/05 14:12:48
Done.
| |
| 19 } | 20 } |
| 20 | 21 |
| 21 cr.addSingletonGetter(AccountsOptions); | 22 cr.addSingletonGetter(AccountsOptions); |
| 22 | 23 |
| 23 AccountsOptions.prototype = { | 24 AccountsOptions.prototype = { |
| 24 // Inherit AccountsOptions from OptionsPage. | 25 // Inherit AccountsOptions from OptionsPage. |
| 25 __proto__: OptionsPage.prototype, | 26 __proto__: OptionsPage.prototype, |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Initializes AccountsOptions page. | 29 * Initializes AccountsOptions page. |
| 29 */ | 30 */ |
| 30 initializePage: function() { | 31 initializePage: function() { |
| 31 // Call base class implementation to starts preference initialization. | 32 // Call base class implementation to starts preference initialization. |
| 32 OptionsPage.prototype.initializePage.call(this); | 33 OptionsPage.prototype.initializePage.call(this); |
| 33 | 34 |
| 34 // Set up accounts page. | 35 // Set up accounts page. |
| 35 var userList = $('userList'); | 36 var userList = $('userList'); |
| 36 | 37 |
| 37 var userNameEdit = $('userNameEdit'); | 38 var userNameEdit = $('userNameEdit'); |
| 38 options.accounts.UserNameEdit.decorate(userNameEdit); | 39 options.accounts.UserNameEdit.decorate(userNameEdit); |
| 39 userNameEdit.addEventListener('add', this.handleAddUser_); | 40 userNameEdit.addEventListener('add', this.handleAddUser_); |
| 40 | 41 |
| 41 // If the current user is not the owner, show some warning, | 42 // If the current user is not the owner, show some warning, |
| 42 // and do not show the user list. | 43 // and do not show the user list. |
| 43 if (AccountsOptions.currentUserIsOwner()) { | 44 this.allowWhitelist_ = AccountsOptions.currentUserIsOwner(); |
| 45 if (this.allowWhitelist_) { | |
| 44 options.accounts.UserList.decorate(userList); | 46 options.accounts.UserList.decorate(userList); |
| 45 } else { | 47 } else { |
| 46 if (!AccountsOptions.whitelistIsManaged()) { | 48 if (!AccountsOptions.whitelistIsManaged()) { |
| 47 $('ownerOnlyWarning').hidden = false; | 49 $('ownerOnlyWarning').hidden = false; |
| 48 } else { | 50 } else { |
| 49 this.managed = true; | 51 this.managed = true; |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 this.addEventListener('visibleChange', this.handleVisibleChange_); | 55 this.addEventListener('visibleChange', this.handleVisibleChange_); |
| 54 | 56 |
| 55 $('useWhitelistCheck').addEventListener('change', | 57 $('useWhitelistCheck').addEventListener('change', |
| 56 this.handleUseWhitelistCheckChange_.bind(this)); | 58 this.handleUseWhitelistCheckChange_.bind(this)); |
| 57 | 59 |
| 58 Preferences.getInstance().addEventListener( | 60 Preferences.getInstance().addEventListener( |
| 59 $('useWhitelistCheck').pref, | 61 $('useWhitelistCheck').pref, |
| 60 this.handleUseWhitelistPrefChange_.bind(this)); | 62 this.handleUseWhitelistPrefChange_.bind(this)); |
| 61 }, | 63 }, |
| 62 | 64 |
| 63 /** | 65 /** |
| 64 * Update user list control state. | 66 * Update user list control state. |
| 65 * @private | 67 * @private |
| 66 */ | 68 */ |
| 67 updateControls_: function() { | 69 updateControls_: function() { |
| 68 $('userList').disabled = | 70 $('userList').disabled = |
| 69 $('userNameEdit').disabled = !AccountsOptions.currentUserIsOwner() || | 71 $('userNameEdit').disabled = !this.allowWhitelist_ || |
| 70 AccountsOptions.whitelistIsManaged() || | 72 AccountsOptions.whitelistIsManaged() || |
| 71 !$('useWhitelistCheck').checked; | 73 !$('useWhitelistCheck').checked; |
| 72 }, | 74 }, |
| 73 | 75 |
| 74 /** | 76 /** |
| 75 * Handler for OptionsPage's visible property change event. | 77 * Handler for OptionsPage's visible property change event. |
| 76 * @private | 78 * @private |
| 77 * @param {Event} e Property change event. | 79 * @param {Event} e Property change event. |
| 78 */ | 80 */ |
| 79 handleVisibleChange_: function(e) { | 81 handleVisibleChange_: function(e) { |
| 80 if (this.visible) { | 82 if (this.visible) { |
| 81 this.updateControls_(); | 83 this.updateControls_(); |
| 82 if (AccountsOptions.currentUserIsOwner()) | 84 if (this.allowWhitelist_) |
| 83 $('userList').redraw(); | 85 $('userList').redraw(); |
| 84 } | 86 } |
| 85 }, | 87 }, |
| 86 | 88 |
| 87 /** | 89 /** |
| 88 * Handler for allow guest check change. | 90 * Handler for allow guest check change. |
| 89 * @private | 91 * @private |
| 90 */ | 92 */ |
| 91 handleUseWhitelistCheckChange_: function(e) { | 93 handleUseWhitelistCheckChange_: function(e) { |
| 92 // Whitelist existing users when guest login is being disabled. | 94 // Whitelist existing users when guest login is being disabled. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 104 handleUseWhitelistPrefChange_: function(e) { | 106 handleUseWhitelistPrefChange_: function(e) { |
| 105 this.updateControls_(); | 107 this.updateControls_(); |
| 106 }, | 108 }, |
| 107 | 109 |
| 108 /** | 110 /** |
| 109 * Handler for "add" event fired from userNameEdit. | 111 * Handler for "add" event fired from userNameEdit. |
| 110 * @private | 112 * @private |
| 111 * @param {Event} e Add event fired from userNameEdit. | 113 * @param {Event} e Add event fired from userNameEdit. |
| 112 */ | 114 */ |
| 113 handleAddUser_: function(e) { | 115 handleAddUser_: function(e) { |
| 114 AccountsOptions.addUsers([e.user]); | 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 |