1 // Copyright (c) 2012 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.
5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage;
8 /////////////////////////////////////////////////////////////////////////////
9 // AccountsOptions class:
12 * Encapsulated handling of ChromeOS accounts options page.
15 function AccountsOptions(model) {
16 OptionsPage.call(this, 'accounts',
17 loadTimeData.getString('accountsPageTabTitle'),
19 // Whether to show the whitelist.
20 this.showWhitelist_ = false;
23 cr.addSingletonGetter(AccountsOptions);
25 AccountsOptions.prototype = {
26 // Inherit AccountsOptions from OptionsPage.
27 __proto__: OptionsPage.prototype,
30 * Initializes AccountsOptions page.
32 initializePage: function() {
33 // Call base class implementation to starts preference initialization.
34 OptionsPage.prototype.initializePage.call(this);
36 // Set up accounts page.
37 var userList = $('userList');
38 userList.addEventListener('remove', this.handleRemoveUser_);
40 var userNameEdit = $('userNameEdit');
41 options.accounts.UserNameEdit.decorate(userNameEdit);
42 userNameEdit.addEventListener('add', this.handleAddUser_);
44 // If the current user is not the owner, do not show the user list.
45 // If the current user is not the owner, or the device is enterprise
46 // managed, show a warning that settings cannot be modified.
47 this.showWhitelist_ = UIAccountTweaks.currentUserIsOwner();
48 if (this.showWhitelist_) {
49 options.accounts.UserList.decorate(userList);
51 $('ownerOnlyWarning').hidden = false;
52 this.managed = AccountsOptions.whitelistIsManaged();
55 this.addEventListener('visibleChange', this.handleVisibleChange_);
57 $('useWhitelistCheck').addEventListener('change',
58 this.handleUseWhitelistCheckChange_.bind(this));
60 Preferences.getInstance().addEventListener(
61 $('useWhitelistCheck').pref,
62 this.handleUseWhitelistPrefChange_.bind(this));
64 $('accounts-options-overlay-confirm').onclick =
65 OptionsPage.closeOverlay.bind(OptionsPage);
69 * Update user list control state.
72 updateControls_: function() {
73 $('userList').disabled =
74 $('userNameEdit').disabled = !this.showWhitelist_ ||
75 AccountsOptions.whitelistIsManaged() ||
76 !$('useWhitelistCheck').checked;
80 * Handler for OptionsPage's visible property change event.
82 * @param {Event} e Property change event.
84 handleVisibleChange_: function(e) {
86 this.updateControls_();
87 if (this.showWhitelist_)
88 $('userList').redraw();
93 * Handler for allow guest check change.
96 handleUseWhitelistCheckChange_: function(e) {
97 // Whitelist existing users when guest login is being disabled.
98 if ($('useWhitelistCheck').checked) {
99 chrome.send('whitelistExistingUsers');
102 this.updateControls_();
106 * handler for allow guest pref change.
109 handleUseWhitelistPrefChange_: function(e) {
110 this.updateControls_();
114 * Handler for "add" event fired from userNameEdit.
116 * @param {Event} e Add event fired from userNameEdit.
118 handleAddUser_: function(e) {
119 chrome.send('whitelistUser', [e.user.email, e.user.name]);
123 * Handler for "remove" event fired from userList.
125 * @param {Event} e Remove event fired from userList.
127 handleRemoveUser_: function(e) {
128 chrome.send('unwhitelistUser', [e.user.username]);
134 * Returns whether the whitelist is managed by policy or not.
136 AccountsOptions.whitelistIsManaged = function() {
137 return loadTimeData.getBoolean('whitelist_is_managed');
141 * Update account picture.
142 * @param {string} username User for which to update the image.
144 AccountsOptions.updateAccountPicture = function(username) {
145 if (this.showWhitelist_)
146 $('userList').updateAccountPicture(username);
151 AccountsOptions: AccountsOptions