Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / chromeos / accounts_options.js
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.
4
5 cr.define('options', function() {
6   var Page = cr.ui.pageManager.Page;
7   var PageManager = cr.ui.pageManager.PageManager;
8
9   /////////////////////////////////////////////////////////////////////////////
10   // AccountsOptions class:
11
12   /**
13    * Encapsulated handling of ChromeOS accounts options page.
14    * @constructor
15    * @extends {cr.ui.pageManager.Page}
16    */
17   function AccountsOptions(model) {
18     Page.call(this, 'accounts', loadTimeData.getString('accountsPageTabTitle'),
19               'accountsPage');
20     // Whether to show the whitelist.
21     this.showWhitelist_ = false;
22   }
23
24   cr.addSingletonGetter(AccountsOptions);
25
26   AccountsOptions.prototype = {
27     // Inherit AccountsOptions from Page.
28     __proto__: Page.prototype,
29
30     /** @override */
31     initializePage: function() {
32       Page.prototype.initializePage.call(this);
33
34       // Set up accounts page.
35       var userList = $('userList');
36       userList.addEventListener('remove', this.handleRemoveUser_);
37
38       var userNameEdit = $('userNameEdit');
39       options.accounts.UserNameEdit.decorate(userNameEdit);
40       userNameEdit.addEventListener('add', this.handleAddUser_);
41
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);
48       } else {
49         $('ownerOnlyWarning').hidden = false;
50         this.managed = AccountsOptions.whitelistIsManaged();
51       }
52
53       this.addEventListener('visibleChange', this.handleVisibleChange_);
54
55       $('useWhitelistCheck').addEventListener('change',
56           this.handleUseWhitelistCheckChange_.bind(this));
57
58       Preferences.getInstance().addEventListener(
59           $('useWhitelistCheck').pref,
60           this.handleUseWhitelistPrefChange_.bind(this));
61
62       $('accounts-options-overlay-confirm').onclick =
63           PageManager.closeOverlay.bind(PageManager);
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 Page's visible property change event.
79      * @private
80      * @param {Event} e Property change event.
81      */
82     handleVisibleChange_: function(e) {
83       if (this.visible) {
84         chrome.send('updateWhitelist');
85         this.updateControls_();
86         if (this.showWhitelist_)
87           $('userList').redraw();
88       }
89     },
90
91     /**
92      * Handler for allow guest check change.
93      * @private
94      */
95     handleUseWhitelistCheckChange_: function(e) {
96       // Whitelist existing users when guest login is being disabled.
97       if ($('useWhitelistCheck').checked) {
98         chrome.send('updateWhitelist');
99       }
100
101       this.updateControls_();
102     },
103
104     /**
105      * handler for allow guest pref change.
106      * @private
107      */
108     handleUseWhitelistPrefChange_: function(e) {
109       this.updateControls_();
110     },
111
112     /**
113      * Handler for "add" event fired from userNameEdit.
114      * @private
115      * @param {Event} e Add event fired from userNameEdit.
116      */
117     handleAddUser_: function(e) {
118       chrome.send('whitelistUser', [e.user.email, e.user.name]);
119       chrome.send('coreOptionsUserMetricsAction',
120                   ['Options_WhitelistedUser_Add']);
121     },
122
123     /**
124      * Handler for "remove" event fired from userList.
125      * @private
126      * @param {Event} e Remove event fired from userList.
127      */
128     handleRemoveUser_: function(e) {
129       chrome.send('unwhitelistUser', [e.user.username]);
130       chrome.send('coreOptionsUserMetricsAction',
131                   ['Options_WhitelistedUser_Remove']);
132     }
133   };
134
135
136   /**
137    * Returns whether the whitelist is managed by policy or not.
138    */
139   AccountsOptions.whitelistIsManaged = function() {
140     return loadTimeData.getBoolean('whitelist_is_managed');
141   };
142
143   /**
144    * Update account picture.
145    * @param {string} username User for which to update the image.
146    */
147   AccountsOptions.updateAccountPicture = function(username) {
148     if (this.showWhitelist_)
149       $('userList').updateAccountPicture(username);
150   };
151
152   // Export
153   return {
154     AccountsOptions: AccountsOptions
155   };
156
157 });