Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1446)

Side by Side Diff: chrome/browser/resources/options/chromeos/accounts_options.js

Issue 8773046: [cros] Display emails of users are stored in a separate dictionary in Local State. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('options', function() { 5 cr.define('options', function() {
6
7 var OptionsPage = options.OptionsPage; 6 var OptionsPage = options.OptionsPage;
8 7
9 ///////////////////////////////////////////////////////////////////////////// 8 /////////////////////////////////////////////////////////////////////////////
10 // AccountsOptions class: 9 // AccountsOptions class:
11 10
12 /** 11 /**
13 * Encapsulated handling of ChromeOS accounts options page. 12 * Encapsulated handling of ChromeOS accounts options page.
14 * @constructor 13 * @constructor
15 */ 14 */
16 function AccountsOptions(model) { 15 function AccountsOptions(model) {
17 OptionsPage.call(this, 'accounts', templateData.accountsPageTabTitle, 16 OptionsPage.call(this, 'accounts', templateData.accountsPageTabTitle,
18 'accountsPage'); 17 'accountsPage');
18 // Whether to show the whitelist.
19 this.showWhitelist_ = false;
19 } 20 }
20 21
21 cr.addSingletonGetter(AccountsOptions); 22 cr.addSingletonGetter(AccountsOptions);
22 23
23 AccountsOptions.prototype = { 24 AccountsOptions.prototype = {
24 // Inherit AccountsOptions from OptionsPage. 25 // Inherit AccountsOptions from OptionsPage.
25 __proto__: OptionsPage.prototype, 26 __proto__: OptionsPage.prototype,
26 27
27 /** 28 /**
28 * Initializes AccountsOptions page. 29 * Initializes AccountsOptions page.
29 */ 30 */
30 initializePage: function() { 31 initializePage: function() {
31 // Call base class implementation to starts preference initialization. 32 // Call base class implementation to starts preference initialization.
32 OptionsPage.prototype.initializePage.call(this); 33 OptionsPage.prototype.initializePage.call(this);
33 34
34 // Set up accounts page. 35 // Set up accounts page.
35 var userList = $('userList'); 36 var userList = $('userList');
37 userList.addEventListener('remove', this.handleRemoveUser_);
36 38
37 var userNameEdit = $('userNameEdit'); 39 var userNameEdit = $('userNameEdit');
38 options.accounts.UserNameEdit.decorate(userNameEdit); 40 options.accounts.UserNameEdit.decorate(userNameEdit);
39 userNameEdit.addEventListener('add', this.handleAddUser_); 41 userNameEdit.addEventListener('add', this.handleAddUser_);
40 42
41 // If the current user is not the owner, show some warning, 43 // If the current user is not the owner, show some warning,
42 // and do not show the user list. 44 // and do not show the user list.
43 if (AccountsOptions.currentUserIsOwner()) { 45 this.showWhitelist_ = AccountsOptions.currentUserIsOwner();
46 if (this.showWhitelist_) {
44 options.accounts.UserList.decorate(userList); 47 options.accounts.UserList.decorate(userList);
45 } else { 48 } else {
46 if (!AccountsOptions.whitelistIsManaged()) { 49 if (!AccountsOptions.whitelistIsManaged()) {
47 $('ownerOnlyWarning').hidden = false; 50 $('ownerOnlyWarning').hidden = false;
48 } else { 51 } else {
49 this.managed = true; 52 this.managed = true;
50 } 53 }
51 } 54 }
52 55
53 this.addEventListener('visibleChange', this.handleVisibleChange_); 56 this.addEventListener('visibleChange', this.handleVisibleChange_);
54 57
55 $('useWhitelistCheck').addEventListener('change', 58 $('useWhitelistCheck').addEventListener('change',
56 this.handleUseWhitelistCheckChange_.bind(this)); 59 this.handleUseWhitelistCheckChange_.bind(this));
57 60
58 Preferences.getInstance().addEventListener( 61 Preferences.getInstance().addEventListener(
59 $('useWhitelistCheck').pref, 62 $('useWhitelistCheck').pref,
60 this.handleUseWhitelistPrefChange_.bind(this)); 63 this.handleUseWhitelistPrefChange_.bind(this));
61 }, 64 },
62 65
63 /** 66 /**
64 * Update user list control state. 67 * Update user list control state.
65 * @private 68 * @private
66 */ 69 */
67 updateControls_: function() { 70 updateControls_: function() {
68 $('userList').disabled = 71 $('userList').disabled =
69 $('userNameEdit').disabled = !AccountsOptions.currentUserIsOwner() || 72 $('userNameEdit').disabled = !this.showWhitelist_ ||
70 AccountsOptions.whitelistIsManaged() || 73 AccountsOptions.whitelistIsManaged() ||
71 !$('useWhitelistCheck').checked; 74 !$('useWhitelistCheck').checked;
72 }, 75 },
73 76
74 /** 77 /**
75 * Handler for OptionsPage's visible property change event. 78 * Handler for OptionsPage's visible property change event.
76 * @private 79 * @private
77 * @param {Event} e Property change event. 80 * @param {Event} e Property change event.
78 */ 81 */
79 handleVisibleChange_: function(e) { 82 handleVisibleChange_: function(e) {
80 if (this.visible) { 83 if (this.visible) {
81 this.updateControls_(); 84 this.updateControls_();
82 if (AccountsOptions.currentUserIsOwner()) 85 if (this.showWhitelist_)
83 $('userList').redraw(); 86 $('userList').redraw();
84 } 87 }
85 }, 88 },
86 89
87 /** 90 /**
88 * Handler for allow guest check change. 91 * Handler for allow guest check change.
89 * @private 92 * @private
90 */ 93 */
91 handleUseWhitelistCheckChange_: function(e) { 94 handleUseWhitelistCheckChange_: function(e) {
92 // Whitelist existing users when guest login is being disabled. 95 // Whitelist existing users when guest login is being disabled.
(...skipping 11 matching lines...) Expand all
104 handleUseWhitelistPrefChange_: function(e) { 107 handleUseWhitelistPrefChange_: function(e) {
105 this.updateControls_(); 108 this.updateControls_();
106 }, 109 },
107 110
108 /** 111 /**
109 * Handler for "add" event fired from userNameEdit. 112 * Handler for "add" event fired from userNameEdit.
110 * @private 113 * @private
111 * @param {Event} e Add event fired from userNameEdit. 114 * @param {Event} e Add event fired from userNameEdit.
112 */ 115 */
113 handleAddUser_: function(e) { 116 handleAddUser_: function(e) {
114 AccountsOptions.addUsers([e.user]); 117 chrome.send('whitelistUser', [e.user.email, e.user.name]);
118 },
119
120 /**
121 * Handler for "remove" event fired from userList.
122 * @private
123 * @param {Event} e Remove event fired from userList.
124 */
125 handleRemoveUser_: function(e) {
126 chrome.send('unwhitelistUser', [e.user.username]);
115 } 127 }
116 }; 128 };
117 129
118 /** 130 /**
119 * Returns whether the current user is owner or not. 131 * Returns whether the current user is owner or not.
120 */ 132 */
121 AccountsOptions.currentUserIsOwner = function() { 133 AccountsOptions.currentUserIsOwner = function() {
122 return localStrings.getString('current_user_is_owner') == 'true'; 134 return localStrings.getString('current_user_is_owner') == 'true';
123 }; 135 };
124 136
125 /** 137 /**
126 * Returns whether we're currently in guest mode. 138 * Returns whether we're currently in guest mode.
127 */ 139 */
128 AccountsOptions.loggedInAsGuest = function() { 140 AccountsOptions.loggedInAsGuest = function() {
129 return localStrings.getString('logged_in_as_guest') == 'true'; 141 return localStrings.getString('logged_in_as_guest') == 'true';
130 }; 142 };
131 143
132 /** 144 /**
133 * Returns whether the whitelist is managed by policy or not. 145 * Returns whether the whitelist is managed by policy or not.
134 */ 146 */
135 AccountsOptions.whitelistIsManaged = function() { 147 AccountsOptions.whitelistIsManaged = function() {
136 return localStrings.getString('whitelist_is_managed') == 'true'; 148 return localStrings.getString('whitelist_is_managed') == 'true';
137 }; 149 };
138 150
139 /** 151 /**
140 * Adds given users to userList.
141 */
142 AccountsOptions.addUsers = function(users) {
143 var userList = $('userList');
144 for (var i = 0; i < users.length; ++i) {
145 userList.addUser(users[i]);
146 }
147 };
148
149 /**
150 * Update account picture. 152 * Update account picture.
151 * @param {string} email Email of the user to update. 153 * @param {string} username User for which to update the image.
152 */ 154 */
153 AccountsOptions.updateAccountPicture = function(email) { 155 AccountsOptions.updateAccountPicture = function(username) {
154 if (this.currentUserIsOwner()) 156 if (this.showWhitelist_)
155 $('userList').updateAccountPicture(email); 157 $('userList').updateAccountPicture(username);
156 }; 158 };
157 159
158 // Export 160 // Export
159 return { 161 return {
160 AccountsOptions: AccountsOptions 162 AccountsOptions: AccountsOptions
161 }; 163 };
162 164
163 }); 165 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698