Upstream version 7.36.149.0
[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 represents.
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 containerEl = this.ownerDocument.createElement('div');
56       containerEl.className = 'profile-container';
57
58       var iconEl = this.ownerDocument.createElement('img');
59       iconEl.className = 'profile-img';
60       iconEl.style.content = getProfileAvatarIcon(profileInfo.iconURL);
61       containerEl.appendChild(iconEl);
62
63       var nameEl = this.ownerDocument.createElement('div');
64       nameEl.className = 'profile-name';
65       if (profileInfo.isCurrentProfile)
66         nameEl.classList.add('profile-item-current');
67       containerEl.appendChild(nameEl);
68
69       var displayName = profileInfo.name;
70       if (profileInfo.isCurrentProfile) {
71         displayName = loadTimeData.getStringF('profilesListItemCurrent',
72                                               profileInfo.name);
73       }
74       nameEl.textContent = displayName;
75
76       if (profileInfo.isManaged) {
77         var supervisedEl = this.ownerDocument.createElement('div');
78         supervisedEl.className = 'profile-supervised';
79         supervisedEl.textContent =
80           '(' + loadTimeData.getStringF('managedUserLabel') + ')';
81         containerEl.appendChild(supervisedEl);
82       }
83
84       this.contentElement.appendChild(containerEl);
85
86       // Ensure that the button cannot be tabbed to for accessibility reasons.
87       this.closeButtonElement.tabIndex = -1;
88     },
89   };
90
91   var ProfileList = cr.ui.define('list');
92
93   ProfileList.prototype = {
94     __proto__: DeletableItemList.prototype,
95
96     /** @override */
97     decorate: function() {
98       DeletableItemList.prototype.decorate.call(this);
99       this.selectionModel = new ListSingleSelectionModel();
100     },
101
102     /** @override */
103     createItem: function(pageInfo) {
104       var item = new ProfileListItem(pageInfo);
105       item.deletable = this.canDeleteItems_;
106       return item;
107     },
108
109     /** @override */
110     deleteItemAtIndex: function(index) {
111       if (loadTimeData.getBoolean('profileIsManaged'))
112         return;
113       ManageProfileOverlay.showDeleteDialog(this.dataModel.item(index));
114     },
115
116     /** @override */
117     activateItemAtIndex: function(index) {
118       // Don't allow the user to edit a profile that is not current.
119       var profileInfo = this.dataModel.item(index);
120       if (profileInfo.isCurrentProfile)
121         ManageProfileOverlay.showManageDialog(profileInfo);
122     },
123
124     /**
125      * Sets whether items in this list are deletable.
126      */
127     set canDeleteItems(value) {
128       this.canDeleteItems_ = value;
129     },
130
131     /**
132      * If false, items in this list will not be deletable.
133      * @private
134      */
135     canDeleteItems_: true,
136   };
137
138   return {
139     ProfileList: ProfileList
140   };
141 });