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

Side by Side Diff: chrome/browser/resources/options/chromeos_accounts_user_list.js

Issue 2935011: Initial accounts options page. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: use ListItem directly for now per arv Created 10 years, 5 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.accounts', function() {
6 const List = cr.ui.List;
7 const ListItem = cr.ui.ListItem;
8 const ArrayDataModel = cr.ui.ArrayDataModel;
9
10 /**
11 * Creates a new user list.
12 * @param {Object=} opt_propertyBag Optional properties.
13 * @constructor
14 * @extends {cr.ui.List}
15 */
16 var UserList = cr.ui.define('list');
17
18 UserList.prototype = {
19 __proto__: List.prototype,
20
21 pref: 'cros.accounts.users',
22
23 /** @inheritDoc */
24 decorate: function() {
25 List.prototype.decorate.call(this);
26
27 // HACK(arv): http://crbug.com/40902
28 window.addEventListener('resize', cr.bind(this.redraw, this));
29
30 var self = this;
31 if (!this.boundHandleChange_) {
32 this.boundHandleChange_ =
33 cr.bind(this.handleChange_, this);
34 }
35
36 // Listens to pref changes.
37 Preferences.getInstance().addEventListener(this.pref,
38 function(event) {
39 self.load_(event.value);
40 });
41
42 // Listens to list selection change.
43 this.addEventListener('change', this.boundHandleChange_);
44 },
45
46 createItem: function(user) {
47 return new ListItem({label: user.email});
48 },
49
50 /**
51 * Adds given user to model and update backend.
52 * @param {Object} user A user to be added to user list.
53 */
54 addUser: function(user) {
55 var dataModel = this.dataModel;
56 dataModel.splice(dataModel.length, 0, user);
57
58 this.updateBackend_();
59 },
60
61 /**
62 * Removes currently selected user from model and update backend.
63 */
64 removeSelectedUser: function() {
65 var sm = this.selectionModel;
66 var dataModel = this.dataModel;
67
68 var newUsers = [];
69 for (var i = 0; i < dataModel.length; ++i) {
70 if (!sm.getIndexSelected(i)) {
71 newUsers.push(dataModel.item(i));
72 }
73 }
74 this.load_(newUsers);
75
76 this.updateBackend_();
77 },
78
79 /**
80 * Loads given user list.
81 * @param {Array} users An array of user object.
82 */
83 load_: function(users) {
84 this.dataModel = new ArrayDataModel(users);
85 },
86
87 /**
88 * Updates backend.
89 */
90 updateBackend_: function() {
91 Preferences.setObjectPref(this.pref, this.dataModel.slice());
92 },
93
94 /**
95 * Handles selection change.
96 */
97 handleChange_: function(e) {
98 $('removeUserButton').disabled = this.selectionModel.selectedIndex == -1;
99 }
100 };
101
102 return {
103 UserList: UserList
104 };
105 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos_accounts_options_page.css ('k') | chrome/browser/resources/options/options_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698