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