1 // Copyright 2013 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.
5 cr.define('options.managedUserOptions', function() {
6 /** @const */ var List = cr.ui.List;
7 /** @const */ var ListItem = cr.ui.ListItem;
8 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel;
11 * Create a new managed user list item.
12 * @param {Object} entry The managed user this item represents.
13 * It has the following form:
15 * id: "Managed User ID",
16 * name: "Managed User Name",
17 * iconURL: "chrome://path/to/icon/image",
18 * onCurrentDevice: true or false,
19 * needAvatar: true or false
22 * @extends {cr.ui.ListItem}
24 function ManagedUserListItem(entry) {
25 var el = cr.doc.createElement('div');
26 el.managedUser_ = entry;
27 el.__proto__ = ManagedUserListItem.prototype;
32 ManagedUserListItem.prototype = {
33 __proto__: ListItem.prototype,
36 * @type {string} the ID of this managed user list item.
39 return this.managedUser_.id;
43 * @type {string} the name of this managed user list item.
46 return this.managedUser_.name;
50 * @type {string} the path to the avatar icon of this managed
54 return this.managedUser_.iconURL;
58 decorate: function() {
59 ListItem.prototype.decorate.call(this);
60 var managedUser = this.managedUser_;
63 var iconElement = this.ownerDocument.createElement('img');
64 iconElement.className = 'profile-img';
65 iconElement.style.content =
66 imageset(managedUser.iconURL + '@scalefactorx');
67 this.appendChild(iconElement);
69 // Add the profile name.
70 var nameElement = this.ownerDocument.createElement('div');
71 nameElement.className = 'profile-name';
72 nameElement.textContent = managedUser.name;
73 this.appendChild(nameElement);
75 if (managedUser.onCurrentDevice) {
76 iconElement.className += ' profile-img-disabled';
77 nameElement.className += ' profile-name-disabled';
79 // Add "(already on this device)" message.
80 var alreadyOnDeviceElement = this.ownerDocument.createElement('div');
81 alreadyOnDeviceElement.className =
82 'profile-name-disabled already-on-this-device';
83 alreadyOnDeviceElement.textContent =
84 loadTimeData.getString('managedUserAlreadyOnThisDevice');
85 this.appendChild(alreadyOnDeviceElement);
91 * Create a new managed users list.
93 * @extends {cr.ui.List}
95 var ManagedUserList = cr.ui.define('list');
97 ManagedUserList.prototype = {
98 __proto__: List.prototype,
101 createItem: function(entry) {
102 return new ManagedUserListItem(entry);
106 decorate: function() {
107 List.prototype.decorate.call(this);
108 this.selectionModel = new ListSingleSelectionModel();
109 this.autoExpands = true;
114 ManagedUserListItem: ManagedUserListItem,
115 ManagedUserList: ManagedUserList,