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