- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / options / browser_options_profile_list.js
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.
4
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;
9
10   /**
11    * Creates a new profile list item.
12    * @param {Object} profileInfo The profile this item respresents.
13    * @constructor
14    * @extends {cr.ui.DeletableItem}
15    */
16   function ProfileListItem(profileInfo) {
17     var el = cr.doc.createElement('div');
18     el.profileInfo_ = profileInfo;
19     ProfileListItem.decorate(el);
20     return el;
21   }
22
23   /**
24    * Decorates an element as a profile list item.
25    * @param {!HTMLElement} el The element to decorate.
26    */
27   ProfileListItem.decorate = function(el) {
28     el.__proto__ = ProfileListItem.prototype;
29     el.decorate();
30   };
31
32   ProfileListItem.prototype = {
33     __proto__: DeletableItem.prototype,
34
35     /**
36      * @type {string} the file path of this profile list item.
37      */
38     get profilePath() {
39       return this.profileInfo_.filePath;
40     },
41
42     /**
43      * @type {boolean} whether this profile is managed.
44      */
45     get isManaged() {
46       return this.profileInfo_.isManaged;
47     },
48
49     /** @override */
50     decorate: function() {
51       DeletableItem.prototype.decorate.call(this);
52
53       var profileInfo = this.profileInfo_;
54
55       var iconEl = this.ownerDocument.createElement('img');
56       iconEl.className = 'profile-img';
57       iconEl.src = profileInfo.iconURL;
58       this.contentElement.appendChild(iconEl);
59
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);
65
66       var displayName = profileInfo.name;
67       if (profileInfo.isCurrentProfile) {
68         displayName = loadTimeData.getStringF('profilesListItemCurrent',
69                                               profileInfo.name);
70       }
71       nameEl.textContent = displayName;
72
73       // Ensure that the button cannot be tabbed to for accessibility reasons.
74       this.closeButtonElement.tabIndex = -1;
75     },
76   };
77
78   var ProfileList = cr.ui.define('list');
79
80   ProfileList.prototype = {
81     __proto__: DeletableItemList.prototype,
82
83     /** @override */
84     decorate: function() {
85       DeletableItemList.prototype.decorate.call(this);
86       this.selectionModel = new ListSingleSelectionModel();
87     },
88
89     /** @override */
90     createItem: function(pageInfo) {
91       var item = new ProfileListItem(pageInfo);
92       item.deletable = this.canDeleteItems_;
93       return item;
94     },
95
96     /** @override */
97     deleteItemAtIndex: function(index) {
98       if (loadTimeData.getBoolean('profileIsManaged'))
99         return;
100       ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index));
101     },
102
103     /** @override */
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);
109     },
110
111     /**
112      * Sets whether items in this list are deletable.
113      */
114     set canDeleteItems(value) {
115       this.canDeleteItems_ = value;
116     },
117
118     /**
119      * If false, items in this list will not be deltable.
120      * @private
121      */
122     canDeleteItems_: true,
123   };
124
125   return {
126     ProfileList: ProfileList
127   };
128 });
129