OLD | NEW |
| (Empty) |
1 // Copyright 2013 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', function() { | |
6 /** @const */ var List = cr.ui.List; | |
7 /** @const */ var ListItem = cr.ui.ListItem; | |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | |
9 | |
10 /** | |
11 * Creates a list for showing kiosk apps. | |
12 * @constructor | |
13 * @extends {cr.ui.List} | |
14 */ | |
15 var KioskAppList = cr.ui.define('list'); | |
16 | |
17 KioskAppList.prototype = { | |
18 __proto__: List.prototype, | |
19 | |
20 /** @override */ | |
21 createItem: function(app) { | |
22 var item = new KioskAppListItem(); | |
23 item.data = app; | |
24 return item; | |
25 }, | |
26 | |
27 /** | |
28 * Loads the given list of apps. | |
29 * @param {!Array.<!Object>} apps An array of app info objects. | |
30 */ | |
31 setApps: function(apps) { | |
32 this.dataModel = new ArrayDataModel(apps); | |
33 }, | |
34 | |
35 /** | |
36 * Updates the given app. | |
37 * @param {!Object} app An app info object. | |
38 */ | |
39 updateApp: function(app) { | |
40 for (var i = 0; i < this.items.length; ++i) { | |
41 if (this.items[i].data.id == app.id) { | |
42 this.items[i].data = app; | |
43 break; | |
44 } | |
45 } | |
46 } | |
47 }; | |
48 | |
49 /** | |
50 * Creates a list item for a kiosk app. | |
51 * @constructor | |
52 * @extends {cr.ui.ListItem} | |
53 */ | |
54 var KioskAppListItem = cr.ui.define(function() { | |
55 var el = $('kiosk-app-list-item-template').cloneNode(true); | |
56 el.removeAttribute('id'); | |
57 el.hidden = false; | |
58 return el; | |
59 }); | |
60 | |
61 KioskAppListItem.prototype = { | |
62 __proto__: ListItem.prototype, | |
63 | |
64 /** | |
65 * Data object to hold app info. | |
66 * @type {Object} | |
67 * @private | |
68 */ | |
69 data_: null, | |
70 get data() { | |
71 assert(this.data_); | |
72 return this.data_; | |
73 }, | |
74 set data(data) { | |
75 this.data_ = data; | |
76 this.redraw(); | |
77 }, | |
78 | |
79 /** | |
80 * Getter for the icon element. | |
81 * @type {Element} | |
82 */ | |
83 get icon() { | |
84 return this.querySelector('.kiosk-app-icon'); | |
85 }, | |
86 | |
87 /** | |
88 * Getter for the name element. | |
89 * @type {Element} | |
90 */ | |
91 get name() { | |
92 return this.querySelector('.kiosk-app-name'); | |
93 }, | |
94 | |
95 /** | |
96 * Getter for the status text element. | |
97 * @type {Element} | |
98 */ | |
99 get status() { | |
100 return this.querySelector('.kiosk-app-status'); | |
101 }, | |
102 | |
103 /** @override */ | |
104 decorate: function() { | |
105 ListItem.prototype.decorate.call(this); | |
106 | |
107 var sendMessageWithId = function(msg) { | |
108 return function() { | |
109 chrome.send(msg, [this.data.id]); | |
110 }.bind(this); | |
111 }.bind(this); | |
112 | |
113 this.querySelector('.enable-auto-launch-button').onclick = | |
114 sendMessageWithId('enableKioskAutoLaunch'); | |
115 this.querySelector('.disable-auto-launch-button').onclick = | |
116 sendMessageWithId('disableKioskAutoLaunch'); | |
117 this.querySelector('.row-delete-button').onclick = | |
118 sendMessageWithId('removeKioskApp'); | |
119 }, | |
120 | |
121 /** | |
122 * Updates UI from app info data. | |
123 */ | |
124 redraw: function() { | |
125 this.icon.classList.toggle('spinner', this.data.isLoading); | |
126 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')'; | |
127 | |
128 this.name.textContent = this.data.name || this.data.id; | |
129 this.status.textContent = this.data.autoLaunch ? | |
130 loadTimeData.getString('autoLaunch') : ''; | |
131 | |
132 this.autoLaunch = this.data.autoLaunch; | |
133 } | |
134 }; | |
135 | |
136 /* | |
137 * True if the app represented by this item will auto launch. | |
138 * @type {boolean} | |
139 */ | |
140 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR); | |
141 | |
142 // Export | |
143 return { | |
144 KioskAppList: KioskAppList | |
145 }; | |
146 }); | |
OLD | NEW |