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 respresents.
14 * @extends {cr.ui.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 * @type {boolean} whether this profile is managed.
46 return this.profileInfo_.isManaged;
50 decorate: function() {
51 DeletableItem.prototype.decorate.call(this);
53 var profileInfo = this.profileInfo_;
55 var iconEl = this.ownerDocument.createElement('img');
56 iconEl.className = 'profile-img';
57 iconEl.style.content = imageset(profileInfo.iconURL + '@scalefactorx');
58 this.contentElement.appendChild(iconEl);
60 var nameEl = this.ownerDocument.createElement('div');
61 nameEl.className = 'profile-name';
62 if (profileInfo.isCurrentProfile)
63 nameEl.classList.add('profile-item-current');
64 this.contentElement.appendChild(nameEl);
66 var displayName = profileInfo.name;
67 if (profileInfo.isCurrentProfile) {
68 displayName = loadTimeData.getStringF('profilesListItemCurrent',
71 nameEl.textContent = displayName;
73 // Ensure that the button cannot be tabbed to for accessibility reasons.
74 this.closeButtonElement.tabIndex = -1;
78 var ProfileList = cr.ui.define('list');
80 ProfileList.prototype = {
81 __proto__: DeletableItemList.prototype,
84 decorate: function() {
85 DeletableItemList.prototype.decorate.call(this);
86 this.selectionModel = new ListSingleSelectionModel();
90 createItem: function(pageInfo) {
91 var item = new ProfileListItem(pageInfo);
92 item.deletable = this.canDeleteItems_;
97 deleteItemAtIndex: function(index) {
98 if (loadTimeData.getBoolean('profileIsManaged'))
100 ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index));
104 activateItemAtIndex: function(index) {
105 // Don't allow the user to edit a profile that is not current.
106 var profileInfo = this.dataModel.item(index);
107 if (profileInfo.isCurrentProfile)
108 ManageProfileOverlay.showManageDialog(profileInfo);
112 * Sets whether items in this list are deletable.
114 set canDeleteItems(value) {
115 this.canDeleteItems_ = value;
119 * If false, items in this list will not be deltable.
122 canDeleteItems_: true,
126 ProfileList: ProfileList