OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 cr.define('options.personal_options', function() { |
| 6 const DeletableItem = options.DeletableItem; |
| 7 const DeletableItemList = options.DeletableItemList; |
| 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 9 |
| 10 var localStrings = new LocalStrings(); |
| 11 |
| 12 /** |
| 13 * Creates a new profile list item. |
| 14 * @param {Object} profileInfo The profile this item respresents. |
| 15 * @constructor |
| 16 * @extends {cr.ui.DeletableItem} |
| 17 */ |
| 18 function ProfileListItem(profileInfo) { |
| 19 var el = cr.doc.createElement('div'); |
| 20 el.profileInfo_ = profileInfo; |
| 21 ProfileListItem.decorate(el); |
| 22 return el; |
| 23 } |
| 24 |
| 25 /** |
| 26 * Decorates an element as a profile list item. |
| 27 * @param {!HTMLElement} el The element to decorate. |
| 28 */ |
| 29 ProfileListItem.decorate = function(el) { |
| 30 el.__proto__ = ProfileListItem.prototype; |
| 31 el.decorate(); |
| 32 }; |
| 33 |
| 34 ProfileListItem.prototype = { |
| 35 __proto__: DeletableItem.prototype, |
| 36 |
| 37 /** |
| 38 * Get the filepath for this profile list item. |
| 39 * @return the file path of this item. |
| 40 */ |
| 41 get profilePath() { |
| 42 return this.profileInfo_.filePath; |
| 43 }, |
| 44 |
| 45 /** @inheritDoc */ |
| 46 decorate: function() { |
| 47 DeletableItem.prototype.decorate.call(this); |
| 48 |
| 49 var profileInfo = this.profileInfo_; |
| 50 |
| 51 var iconEl = this.ownerDocument.createElement('img'); |
| 52 iconEl.className = 'profile-img'; |
| 53 iconEl.src = profileInfo.iconURL; |
| 54 this.contentElement.appendChild(iconEl); |
| 55 |
| 56 var nameEl = this.ownerDocument.createElement('div'); |
| 57 if (profileInfo.isCurrentProfile) |
| 58 nameEl.classList.add('profile-item-current'); |
| 59 this.contentElement.appendChild(nameEl); |
| 60 |
| 61 var displayName = profileInfo.name; |
| 62 if (profileInfo.isCurrentProfile) |
| 63 displayName = localStrings.getStringF( |
| 64 'profilesListItemCurrent', |
| 65 profileInfo.name) |
| 66 nameEl.textContent = displayName; |
| 67 }, |
| 68 }; |
| 69 |
| 70 var ProfileList = cr.ui.define('list'); |
| 71 |
| 72 ProfileList.prototype = { |
| 73 __proto__: DeletableItemList.prototype, |
| 74 |
| 75 /** @inheritDoc */ |
| 76 decorate: function() { |
| 77 DeletableItemList.prototype.decorate.call(this); |
| 78 this.selectionModel = new ListSingleSelectionModel(); |
| 79 }, |
| 80 |
| 81 /** @inheritDoc */ |
| 82 createItem: function(pageInfo) { |
| 83 var item = new ProfileListItem(pageInfo); |
| 84 return item; |
| 85 }, |
| 86 |
| 87 /** @inheritDoc */ |
| 88 deleteItemAtIndex: function(index) { |
| 89 ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index)); |
| 90 }, |
| 91 |
| 92 /** @inheritDoc */ |
| 93 activateItemAtIndex: function(index) { |
| 94 // Don't allow the user to edit a profile that is not current. |
| 95 var profileInfo = this.dataModel.item(index); |
| 96 if (profileInfo.isCurrentProfile) |
| 97 ManageProfileOverlay.showManageDialog(profileInfo); |
| 98 }, |
| 99 }; |
| 100 |
| 101 return { |
| 102 ProfileList: ProfileList |
| 103 }; |
| 104 }); |
| 105 |
OLD | NEW |