1 // Copyright (c) 2012 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.browser_options', function() {
6 /** @const */ var DeletableItem = options.DeletableItem;
7 /** @const */ var DeletableItemList = options.DeletableItemList;
8 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel;
11 * Creates a new profile list item.
12 * @param {Object} profileInfo The profile this item represents.
14 * @extends {options.DeletableItem}
16 function ProfileListItem(profileInfo) {
17 var el = cr.doc.createElement('div');
18 el.profileInfo_ = profileInfo;
19 ProfileListItem.decorate(el);
24 * Decorates an element as a profile list item.
25 * @param {!HTMLElement} el The element to decorate.
27 ProfileListItem.decorate = function(el) {
28 el.__proto__ = ProfileListItem.prototype;
32 ProfileListItem.prototype = {
33 __proto__: DeletableItem.prototype,
36 * @type {string} the file path of this profile list item.
39 return this.profileInfo_.filePath;
43 decorate: function() {
44 DeletableItem.prototype.decorate.call(this);
46 var profileInfo = this.profileInfo_;
48 var containerEl = this.ownerDocument.createElement('div');
49 containerEl.className = 'profile-container';
51 var iconEl = this.ownerDocument.createElement('img');
52 iconEl.className = 'profile-img';
53 iconEl.style.content = getProfileAvatarIcon(profileInfo.iconURL);
55 containerEl.appendChild(iconEl);
57 var nameEl = this.ownerDocument.createElement('div');
58 nameEl.className = 'profile-name';
59 if (profileInfo.isCurrentProfile)
60 nameEl.classList.add('profile-item-current');
61 containerEl.appendChild(nameEl);
63 var displayName = profileInfo.name;
64 if (profileInfo.isCurrentProfile) {
65 displayName = loadTimeData.getStringF('profilesListItemCurrent',
68 nameEl.textContent = displayName;
70 if (profileInfo.isSupervised) {
71 var supervisedEl = this.ownerDocument.createElement('div');
72 supervisedEl.className = 'profile-supervised';
73 supervisedEl.textContent = profileInfo.isChild ?
74 loadTimeData.getString('childLabel') :
75 loadTimeData.getString('supervisedUserLabel');
76 containerEl.appendChild(supervisedEl);
79 this.contentElement.appendChild(containerEl);
81 // Ensure that the button cannot be tabbed to for accessibility reasons.
82 this.closeButtonElement.tabIndex = -1;
86 var ProfileList = cr.ui.define('list');
88 ProfileList.prototype = {
89 __proto__: DeletableItemList.prototype,
92 decorate: function() {
93 DeletableItemList.prototype.decorate.call(this);
94 this.selectionModel = new ListSingleSelectionModel();
98 createItem: function(pageInfo) {
99 var item = new ProfileListItem(pageInfo);
100 item.deletable = this.canDeleteItems_;
105 deleteItemAtIndex: function(index) {
106 ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index));
110 activateItemAtIndex: function(index) {
111 // Don't allow the user to edit a profile that is not current.
112 var profileInfo = this.dataModel.item(index);
113 if (profileInfo.isCurrentProfile)
114 ManageProfileOverlay.showManageDialog(profileInfo);
118 * Sets whether items in this list are deletable.
120 set canDeleteItems(value) {
121 this.canDeleteItems_ = value;
125 * @type {boolean} whether the items in this list are deletable.
127 get canDeleteItems() {
128 return this.canDeleteItems_;
132 * If false, items in this list will not be deletable.
135 canDeleteItems_: true,
139 ProfileList: ProfileList