| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('options', function() { | |
| 6 var OptionsPage = options.OptionsPage; | |
| 7 | |
| 8 ///////////////////////////////////////////////////////////////////////////// | |
| 9 // AccountsOptions class: | |
| 10 | |
| 11 /** | |
| 12 * Encapsulated handling of ChromeOS accounts options page. | |
| 13 * @constructor | |
| 14 */ | |
| 15 function AccountsOptions(model) { | |
| 16 OptionsPage.call(this, 'accounts', templateData.accountsPageTabTitle, | |
| 17 'accountsPage'); | |
| 18 // Whether to show the whitelist. | |
| 19 this.showWhitelist_ = false; | |
| 20 } | |
| 21 | |
| 22 cr.addSingletonGetter(AccountsOptions); | |
| 23 | |
| 24 AccountsOptions.prototype = { | |
| 25 // Inherit AccountsOptions from OptionsPage. | |
| 26 __proto__: OptionsPage.prototype, | |
| 27 | |
| 28 /** | |
| 29 * Initializes AccountsOptions page. | |
| 30 */ | |
| 31 initializePage: function() { | |
| 32 // Call base class implementation to starts preference initialization. | |
| 33 OptionsPage.prototype.initializePage.call(this); | |
| 34 | |
| 35 // Set up accounts page. | |
| 36 var userList = $('userList'); | |
| 37 userList.addEventListener('remove', this.handleRemoveUser_); | |
| 38 | |
| 39 var userNameEdit = $('userNameEdit'); | |
| 40 options.accounts.UserNameEdit.decorate(userNameEdit); | |
| 41 userNameEdit.addEventListener('add', this.handleAddUser_); | |
| 42 | |
| 43 // If the current user is not the owner, show some warning, | |
| 44 // and do not show the user list. | |
| 45 this.showWhitelist_ = AccountsOptions.currentUserIsOwner(); | |
| 46 if (this.showWhitelist_) { | |
| 47 options.accounts.UserList.decorate(userList); | |
| 48 } else { | |
| 49 if (!AccountsOptions.whitelistIsManaged()) { | |
| 50 $('ownerOnlyWarning').hidden = false; | |
| 51 } else { | |
| 52 this.managed = true; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 this.addEventListener('visibleChange', this.handleVisibleChange_); | |
| 57 | |
| 58 $('useWhitelistCheck').addEventListener('change', | |
| 59 this.handleUseWhitelistCheckChange_.bind(this)); | |
| 60 | |
| 61 Preferences.getInstance().addEventListener( | |
| 62 $('useWhitelistCheck').pref, | |
| 63 this.handleUseWhitelistPrefChange_.bind(this)); | |
| 64 }, | |
| 65 | |
| 66 /** | |
| 67 * Update user list control state. | |
| 68 * @private | |
| 69 */ | |
| 70 updateControls_: function() { | |
| 71 $('userList').disabled = | |
| 72 $('userNameEdit').disabled = !this.showWhitelist_ || | |
| 73 AccountsOptions.whitelistIsManaged() || | |
| 74 !$('useWhitelistCheck').checked; | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * Handler for OptionsPage's visible property change event. | |
| 79 * @private | |
| 80 * @param {Event} e Property change event. | |
| 81 */ | |
| 82 handleVisibleChange_: function(e) { | |
| 83 if (this.visible) { | |
| 84 this.updateControls_(); | |
| 85 if (this.showWhitelist_) | |
| 86 $('userList').redraw(); | |
| 87 } | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * Handler for allow guest check change. | |
| 92 * @private | |
| 93 */ | |
| 94 handleUseWhitelistCheckChange_: function(e) { | |
| 95 // Whitelist existing users when guest login is being disabled. | |
| 96 if ($('useWhitelistCheck').checked) { | |
| 97 chrome.send('whitelistExistingUsers', []); | |
| 98 } | |
| 99 | |
| 100 this.updateControls_(); | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * handler for allow guest pref change. | |
| 105 * @private | |
| 106 */ | |
| 107 handleUseWhitelistPrefChange_: function(e) { | |
| 108 this.updateControls_(); | |
| 109 }, | |
| 110 | |
| 111 /** | |
| 112 * Handler for "add" event fired from userNameEdit. | |
| 113 * @private | |
| 114 * @param {Event} e Add event fired from userNameEdit. | |
| 115 */ | |
| 116 handleAddUser_: function(e) { | |
| 117 chrome.send('whitelistUser', [e.user.email, e.user.name]); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * Handler for "remove" event fired from userList. | |
| 122 * @private | |
| 123 * @param {Event} e Remove event fired from userList. | |
| 124 */ | |
| 125 handleRemoveUser_: function(e) { | |
| 126 chrome.send('unwhitelistUser', [e.user.username]); | |
| 127 } | |
| 128 }; | |
| 129 | |
| 130 /** | |
| 131 * Returns whether the current user is owner or not. | |
| 132 */ | |
| 133 AccountsOptions.currentUserIsOwner = function() { | |
| 134 return localStrings.getString('current_user_is_owner') == 'true'; | |
| 135 }; | |
| 136 | |
| 137 /** | |
| 138 * Returns whether we're currently in guest mode. | |
| 139 */ | |
| 140 AccountsOptions.loggedInAsGuest = function() { | |
| 141 return localStrings.getString('logged_in_as_guest') == 'true'; | |
| 142 }; | |
| 143 | |
| 144 /** | |
| 145 * Returns whether the whitelist is managed by policy or not. | |
| 146 */ | |
| 147 AccountsOptions.whitelistIsManaged = function() { | |
| 148 return localStrings.getString('whitelist_is_managed') == 'true'; | |
| 149 }; | |
| 150 | |
| 151 /** | |
| 152 * Update account picture. | |
| 153 * @param {string} username User for which to update the image. | |
| 154 */ | |
| 155 AccountsOptions.updateAccountPicture = function(username) { | |
| 156 if (this.showWhitelist_) | |
| 157 $('userList').updateAccountPicture(username); | |
| 158 }; | |
| 159 | |
| 160 // Export | |
| 161 return { | |
| 162 AccountsOptions: AccountsOptions | |
| 163 }; | |
| 164 | |
| 165 }); | |
| OLD | NEW |