OLD | NEW |
---|---|
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.accounts', function() { | 5 cr.define('options.accounts', function() { |
6 const List = cr.ui.List; | 6 const List = cr.ui.List; |
7 const ListItem = cr.ui.ListItem; | 7 const ListItem = cr.ui.ListItem; |
8 const ArrayDataModel = cr.ui.ArrayDataModel; | 8 const ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
(...skipping 25 matching lines...) Expand all Loading... | |
36 function(event) { | 36 function(event) { |
37 self.load_(event.value); | 37 self.load_(event.value); |
38 }); | 38 }); |
39 }, | 39 }, |
40 | 40 |
41 createItem: function(user) { | 41 createItem: function(user) { |
42 return new UserListItem(user); | 42 return new UserListItem(user); |
43 }, | 43 }, |
44 | 44 |
45 /** | 45 /** |
46 * Finds the index of user by given email. | 46 * Finds the index of user by given username (canonicalized email). |
47 * @private | 47 * @private |
48 * @param {string} email The email address to look for. | 48 * @param {string} username The username to look for. |
49 * @return {number} The index of the found user or -1 if not found. | 49 * @return {number} The index of the found user or -1 if not found. |
50 */ | 50 */ |
51 findUserByEmail_: function(email) { | 51 indexOf_: function(username) { |
52 var dataModel = this.dataModel; | 52 var dataModel = this.dataModel; |
53 if (!dataModel) | 53 if (!dataModel) |
54 return -1; | 54 return -1; |
55 | 55 |
56 var length = dataModel.length; | 56 var length = dataModel.length; |
57 for (var i = 0; i < length; ++i) { | 57 for (var i = 0; i < length; ++i) { |
58 var user = dataModel.item(i); | 58 var user = dataModel.item(i); |
59 if (user.email == email) { | 59 if (user.username == username) { |
60 return i; | 60 return i; |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 return -1; | 64 return -1; |
65 }, | 65 }, |
66 | 66 |
67 /** | 67 /** |
68 * Adds given user to model and update backend. | 68 * Adds given user to the model (this comes from the backend so there is no |
69 * @param {Object} user A user to be added to user list. | 69 * need to update it). |
70 * @param {Object} user User info object to be added to user list. | |
70 */ | 71 */ |
71 addUser: function(user) { | 72 addUser: function(user) { |
72 var index = this.findUserByEmail_(user.email); | 73 this.dataModel.push(user); |
73 if (index == -1) { | |
74 this.dataModel.push(user); | |
75 chrome.send('whitelistUser', [user.email]); | |
76 } | |
77 }, | 74 }, |
78 | 75 |
79 /** | 76 /** |
80 * Removes given user from model and update backend. | 77 * Removes given user from the tmodel and updates backend. |
James Hawkins
2011/12/02 18:12:01
tmodel: is this a spelling mistake?
Ivan Korotkov
2011/12/02 18:30:30
Yep, fixed.
| |
78 * @param {Object} user User info object to be removed from user list. | |
81 */ | 79 */ |
82 removeUser: function(user) { | 80 removeUser: function(user) { |
83 var dataModel = this.dataModel; | 81 var dataModel = this.dataModel; |
84 | |
85 var index = dataModel.indexOf(user); | 82 var index = dataModel.indexOf(user); |
86 if (index >= 0) { | 83 if (index >= 0) { |
87 dataModel.splice(index, 1); | 84 dataModel.splice(index, 1); |
88 chrome.send('unwhitelistUser', [user.email]); | 85 chrome.send('unwhitelistUser', [user.username]); |
89 } | 86 } |
90 }, | 87 }, |
91 | 88 |
92 /** | 89 /** |
93 * Update given user's account picture. | 90 * Update given user's account picture. |
94 * @param {string} email Email of the user to update. | 91 * @param {string} username User for which to update the image. |
95 */ | 92 */ |
96 updateAccountPicture: function(email) { | 93 updateAccountPicture: function(username) { |
97 var index = this.findUserByEmail_(email); | 94 var index = this.indexOf_(username); |
98 if (index >= 0) { | 95 if (index >= 0) { |
99 var item = this.getListItemByIndex(index); | 96 var item = this.getListItemByIndex(index); |
100 if (item) | 97 if (item) |
101 item.updatePicture(); | 98 item.updatePicture(); |
102 } | 99 } |
103 }, | 100 }, |
104 | 101 |
105 /** | 102 /** |
106 * Handles the clicks on the list and triggers user removal if the click | 103 * Handles the clicks on the list and triggers user removal if the click |
107 * is on the remove user button. | 104 * is on the remove user button. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 removeButton.className = | 191 removeButton.className = |
195 'raw-button remove-user-button custom-appearance'; | 192 'raw-button remove-user-button custom-appearance'; |
196 this.appendChild(removeButton); | 193 this.appendChild(removeButton); |
197 } | 194 } |
198 }, | 195 }, |
199 | 196 |
200 /** | 197 /** |
201 * Reloads user picture. | 198 * Reloads user picture. |
202 */ | 199 */ |
203 updatePicture: function() { | 200 updatePicture: function() { |
204 this.icon_.src = 'chrome://userimage/' + this.user.email + | 201 this.icon_.src = 'chrome://userimage/' + this.user.username + |
205 '?id=' + (new Date()).getTime(); | 202 '?id=' + (new Date()).getTime(); |
206 } | 203 } |
207 }; | 204 }; |
208 | 205 |
209 return { | 206 return { |
210 UserList: UserList | 207 UserList: UserList |
211 }; | 208 }; |
212 }); | 209 }); |
OLD | NEW |