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);
54 containerEl.appendChild(iconEl);
56 var nameEl = this.ownerDocument.createElement('div');
57 nameEl.className = 'profile-name';
58 if (profileInfo.isCurrentProfile)
59 nameEl.classList.add('profile-item-current');
60 containerEl.appendChild(nameEl);
62 var displayName = profileInfo.name;
63 if (profileInfo.isCurrentProfile) {
64 displayName = loadTimeData.getStringF('profilesListItemCurrent',
67 nameEl.textContent = displayName;
69 if (profileInfo.isSupervised) {
70 var supervisedEl = this.ownerDocument.createElement('div');
71 supervisedEl.className = 'profile-supervised';
72 supervisedEl.textContent =
73 loadTimeData.getString('supervisedUserLabel');
74 containerEl.appendChild(supervisedEl);
77 this.contentElement.appendChild(containerEl);
79 // Ensure that the button cannot be tabbed to for accessibility reasons.
80 this.closeButtonElement.tabIndex = -1;
84 var ProfileList = cr.ui.define('list');
86 ProfileList.prototype = {
87 __proto__: DeletableItemList.prototype,
90 decorate: function() {
91 DeletableItemList.prototype.decorate.call(this);
92 this.selectionModel = new ListSingleSelectionModel();
96 createItem: function(pageInfo) {
97 var item = new ProfileListItem(pageInfo);
98 item.deletable = this.canDeleteItems_;
103 deleteItemAtIndex: function(index) {
104 if (loadTimeData.getBoolean('profileIsSupervised'))
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 * If false, items in this list will not be deletable.
128 canDeleteItems_: true,
132 ProfileList: ProfileList