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 chrome.send('updateWhitelist');
85 this.updateControls_();
86 if (this.showWhitelist_)
87 $('userList').redraw();
92 * Handler for allow guest check change.
95 handleUseWhitelistCheckChange_: function(e) {
96 // Whitelist existing users when guest login is being disabled.
97 if ($('useWhitelistCheck').checked) {
98 chrome.send('updateWhitelist');
101 this.updateControls_();
105 * handler for allow guest pref change.
108 handleUseWhitelistPrefChange_: function(e) {
109 this.updateControls_();
113 * Handler for "add" event fired from userNameEdit.
115 * @param {Event} e Add event fired from userNameEdit.
117 handleAddUser_: function(e) {
118 chrome.send('whitelistUser', [e.user.email, e.user.name]);
119 chrome.send('coreOptionsUserMetricsAction',
120 ['Options_WhitelistedUser_Add']);
124 * Handler for "remove" event fired from userList.
126 * @param {Event} e Remove event fired from userList.
128 handleRemoveUser_: function(e) {
129 chrome.send('unwhitelistUser', [e.user.username]);
130 chrome.send('coreOptionsUserMetricsAction',
131 ['Options_WhitelistedUser_Remove']);
137 * Returns whether the whitelist is managed by policy or not.
139 AccountsOptions.whitelistIsManaged = function() {
140 return loadTimeData.getBoolean('whitelist_is_managed');
144 * Update account picture.
145 * @param {string} username User for which to update the image.
147 AccountsOptions.updateAccountPicture = function(username) {
148 if (this.showWhitelist_)
149 $('userList').updateAccountPicture(username);
154 AccountsOptions: AccountsOptions