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 Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager;
9 /////////////////////////////////////////////////////////////////////////////
10 // AccountsOptions class:
13 * Encapsulated handling of ChromeOS accounts options page.
15 * @extends {cr.ui.pageManager.Page}
17 function AccountsOptions(model) {
18 Page.call(this, 'accounts', loadTimeData.getString('accountsPageTabTitle'),
20 // Whether to show the whitelist.
21 this.showWhitelist_ = false;
24 cr.addSingletonGetter(AccountsOptions);
26 AccountsOptions.prototype = {
27 // Inherit AccountsOptions from Page.
28 __proto__: Page.prototype,
31 initializePage: function() {
32 Page.prototype.initializePage.call(this);
34 // Set up accounts page.
35 var userList = $('userList');
36 userList.addEventListener('remove', this.handleRemoveUser_);
38 var userNameEdit = $('userNameEdit');
39 options.accounts.UserNameEdit.decorate(userNameEdit);
40 userNameEdit.addEventListener('add', this.handleAddUser_);
42 // If the current user is not the owner, do not show the user list.
43 // If the current user is not the owner, or the device is enterprise
44 // managed, show a warning that settings cannot be modified.
45 this.showWhitelist_ = UIAccountTweaks.currentUserIsOwner();
46 if (this.showWhitelist_) {
47 options.accounts.UserList.decorate(userList);
49 $('ownerOnlyWarning').hidden = false;
50 this.managed = AccountsOptions.whitelistIsManaged();
53 this.addEventListener('visibleChange', this.handleVisibleChange_);
55 $('useWhitelistCheck').addEventListener('change',
56 this.handleUseWhitelistCheckChange_.bind(this));
58 Preferences.getInstance().addEventListener(
59 $('useWhitelistCheck').pref,
60 this.handleUseWhitelistPrefChange_.bind(this));
62 $('accounts-options-overlay-confirm').onclick =
63 PageManager.closeOverlay.bind(PageManager);
67 * Update user list control state.
70 updateControls_: function() {
71 $('userList').disabled =
72 $('userNameEdit').disabled = !this.showWhitelist_ ||
73 AccountsOptions.whitelistIsManaged() ||
74 !$('useWhitelistCheck').checked;
78 * Handler for Page's visible property change event.
80 * @param {Event} e Property change event.
82 handleVisibleChange_: function(e) {
84 this.updateControls_();
85 if (this.showWhitelist_)
86 $('userList').redraw();
91 * Handler for allow guest check change.
94 handleUseWhitelistCheckChange_: function(e) {
95 // Whitelist existing users when guest login is being disabled.
96 if ($('useWhitelistCheck').checked) {
97 chrome.send('whitelistExistingUsers');
100 this.updateControls_();
104 * handler for allow guest pref change.
107 handleUseWhitelistPrefChange_: function(e) {
108 this.updateControls_();
112 * Handler for "add" event fired from userNameEdit.
114 * @param {Event} e Add event fired from userNameEdit.
116 handleAddUser_: function(e) {
117 chrome.send('whitelistUser', [e.user.email, e.user.name]);
118 chrome.send('coreOptionsUserMetricsAction',
119 ['Options_WhitelistedUser_Add']);
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]);
129 chrome.send('coreOptionsUserMetricsAction',
130 ['Options_WhitelistedUser_Remove']);
136 * Returns whether the whitelist is managed by policy or not.
138 AccountsOptions.whitelistIsManaged = function() {
139 return loadTimeData.getBoolean('whitelist_is_managed');
143 * Update account picture.
144 * @param {string} username User for which to update the image.
146 AccountsOptions.updateAccountPicture = function(username) {
147 if (this.showWhitelist_)
148 $('userList').updateAccountPicture(username);
153 AccountsOptions: AccountsOptions