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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options/chromeos_accounts_user_list.js
diff --git a/chrome/browser/resources/options/chromeos_accounts_user_list.js b/chrome/browser/resources/options/chromeos_accounts_user_list.js
new file mode 100644
index 0000000000000000000000000000000000000000..2f654cc71adad9777a73785329568ad5bc849741
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos_accounts_user_list.js
@@ -0,0 +1,105 @@
+// Copyright (c) 2010 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.accounts', function() {
+ const List = cr.ui.List;
+ const ListItem = cr.ui.ListItem;
+ const ArrayDataModel = cr.ui.ArrayDataModel;
+
+ /**
+ * Creates a new user list.
+ * @param {Object=} opt_propertyBag Optional properties.
+ * @constructor
+ * @extends {cr.ui.List}
+ */
+ var UserList = cr.ui.define('list');
+
+ UserList.prototype = {
+ __proto__: List.prototype,
+
+ pref: 'cros.accounts.users',
+
+ /** @inheritDoc */
+ decorate: function() {
+ List.prototype.decorate.call(this);
+
+ // HACK(arv): http://crbug.com/40902
+ window.addEventListener('resize', cr.bind(this.redraw, this));
+
+ var self = this;
+ if (!this.boundHandleChange_) {
+ this.boundHandleChange_ =
+ cr.bind(this.handleChange_, this);
+ }
+
+ // Listens to pref changes.
+ Preferences.getInstance().addEventListener(this.pref,
+ function(event) {
+ self.load_(event.value);
+ });
+
+ // Listens to list selection change.
+ this.addEventListener('change', this.boundHandleChange_);
+ },
+
+ createItem: function(user) {
+ return new ListItem({label: user.email});
+ },
+
+ /**
+ * Adds given user to model and update backend.
+ * @param {Object} user A user to be added to user list.
+ */
+ addUser: function(user) {
+ var dataModel = this.dataModel;
+ dataModel.splice(dataModel.length, 0, user);
+
+ this.updateBackend_();
+ },
+
+ /**
+ * Removes currently selected user from model and update backend.
+ */
+ removeSelectedUser: function() {
+ var sm = this.selectionModel;
+ var dataModel = this.dataModel;
+
+ var newUsers = [];
+ for (var i = 0; i < dataModel.length; ++i) {
+ if (!sm.getIndexSelected(i)) {
+ newUsers.push(dataModel.item(i));
+ }
+ }
+ this.load_(newUsers);
+
+ this.updateBackend_();
+ },
+
+ /**
+ * Loads given user list.
+ * @param {Array} users An array of user object.
+ */
+ load_: function(users) {
+ this.dataModel = new ArrayDataModel(users);
+ },
+
+ /**
+ * Updates backend.
+ */
+ updateBackend_: function() {
+ Preferences.setObjectPref(this.pref, this.dataModel.slice());
+ },
+
+ /**
+ * Handles selection change.
+ */
+ handleChange_: function(e) {
+ $('removeUserButton').disabled = this.selectionModel.selectedIndex == -1;
+ }
+ };
+
+ return {
+ UserList: UserList
+ };
+});
« 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