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.
5 cr.define('extensions', function() {
6 /** @const */ var List = cr.ui.List;
7 /** @const */ var ListItem = cr.ui.ListItem;
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
11 * Creates a list for showing kiosk apps.
13 * @extends {cr.ui.List}
15 var KioskAppList = cr.ui.define('list');
17 KioskAppList.prototype = {
18 __proto__: List.prototype,
21 createItem: function(app) {
22 var item = new KioskAppListItem();
28 * Loads the given list of apps.
29 * @param {!Array.<!Object>} apps An array of app info objects.
31 setApps: function(apps) {
32 this.dataModel = new ArrayDataModel(apps);
36 * Updates the given app.
37 * @param {!Object} app An app info object.
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;
50 * Creates a list item for a kiosk app.
52 * @extends {cr.ui.ListItem}
54 var KioskAppListItem = cr.ui.define(function() {
55 var el = $('kiosk-app-list-item-template').cloneNode(true);
56 el.removeAttribute('id');
61 KioskAppListItem.prototype = {
62 __proto__: ListItem.prototype,
65 * Data object to hold app info.
80 * Getter for the icon element.
84 return this.querySelector('.kiosk-app-icon');
88 * Getter for the name element.
92 return this.querySelector('.kiosk-app-name');
96 * Getter for the status text element.
100 return this.querySelector('.kiosk-app-status');
104 decorate: function() {
105 ListItem.prototype.decorate.call(this);
107 var sendMessageWithId = function(msg) {
109 chrome.send(msg, [this.data.id]);
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');
122 * Updates UI from app info data.
125 this.icon.classList.toggle('spinner', this.data.isLoading);
126 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')';
128 this.name.textContent = this.data.name || this.data.id;
129 this.status.textContent = this.data.autoLaunch ?
130 loadTimeData.getString('autoLaunch') : '';
132 this.autoLaunch = this.data.autoLaunch;
137 * True if the app represented by this item will auto launch.
140 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR);
144 KioskAppList: KioskAppList