Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / resources / options / browser_options_profile_list.js
blob81a4181ab97c30ff4d5adccc9c318ef24a2750a4
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;
10 /**
11 * Creates a new profile list item.
12 * @param {Object} profileInfo The profile this item represents.
13 * @constructor
14 * @extends {options.DeletableItem}
16 function ProfileListItem(profileInfo) {
17 var el = cr.doc.createElement('div');
18 el.profileInfo_ = profileInfo;
19 ProfileListItem.decorate(el);
20 return el;
23 /**
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;
29 el.decorate();
32 ProfileListItem.prototype = {
33 __proto__: DeletableItem.prototype,
35 /**
36 * @type {string} the file path of this profile list item.
38 get profilePath() {
39 return this.profileInfo_.filePath;
42 /** @override */
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',
65 profileInfo.name);
67 nameEl.textContent = displayName;
69 if (profileInfo.isSupervised) {
70 var supervisedEl = this.ownerDocument.createElement('div');
71 supervisedEl.className = 'profile-supervised';
72 supervisedEl.textContent = profileInfo.isChild ?
73 loadTimeData.getString('childLabel') :
74 loadTimeData.getString('supervisedUserLabel');
75 containerEl.appendChild(supervisedEl);
78 this.contentElement.appendChild(containerEl);
80 // Ensure that the button cannot be tabbed to for accessibility reasons.
81 this.closeButtonElement.tabIndex = -1;
85 var ProfileList = cr.ui.define('list');
87 ProfileList.prototype = {
88 __proto__: DeletableItemList.prototype,
90 /** @override */
91 decorate: function() {
92 DeletableItemList.prototype.decorate.call(this);
93 this.selectionModel = new ListSingleSelectionModel();
96 /** @override */
97 createItem: function(pageInfo) {
98 var item = new ProfileListItem(pageInfo);
99 item.deletable = this.canDeleteItems_;
100 return item;
103 /** @override */
104 deleteItemAtIndex: function(index) {
105 ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index));
108 /** @override */
109 activateItemAtIndex: function(index) {
110 // Don't allow the user to edit a profile that is not current.
111 var profileInfo = this.dataModel.item(index);
112 if (profileInfo.isCurrentProfile)
113 ManageProfileOverlay.showManageDialog(profileInfo);
117 * Sets whether items in this list are deletable.
119 set canDeleteItems(value) {
120 this.canDeleteItems_ = value;
124 * @type {boolean} whether the items in this list are deletable.
126 get canDeleteItems() {
127 return this.canDeleteItems_;
131 * If false, items in this list will not be deletable.
132 * @private
134 canDeleteItems_: true,
137 return {
138 ProfileList: ProfileList