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 * True if auto launch feature can be configured.
24 autoLaunchEnabled_: false,
27 createItem: function(app) {
28 var item = new KioskAppListItem();
30 item.autoLaunchEnabled = this.autoLaunchEnabled_;
35 * Sets auto launch enabled flag.
36 * @param {boolean} enabled True if auto launch should be enabled.
38 setAutoLaunchEnabled: function(enabled) {
39 this.autoLaunchEnabled_ = enabled;
43 * Loads the given list of apps.
44 * @param {!Array.<!Object>} apps An array of app info objects.
46 setApps: function(apps) {
47 this.dataModel = new ArrayDataModel(apps);
51 * Updates the given app.
52 * @param {!Object} app An app info object.
54 updateApp: function(app) {
55 for (var i = 0; i < this.items.length; ++i) {
56 if (this.items[i].data.id == app.id) {
57 this.items[i].data = app;
65 * Creates a list item for a kiosk app.
67 * @extends {cr.ui.ListItem}
69 var KioskAppListItem = cr.ui.define(function() {
70 var el = $('kiosk-app-list-item-template').cloneNode(true);
71 el.removeAttribute('id');
76 KioskAppListItem.prototype = {
77 __proto__: ListItem.prototype,
80 * Data object to hold app info.
96 set autoLaunchEnabled(enabled) {
97 this.querySelector('.enable-auto-launch-button').hidden = !enabled;
98 this.querySelector('.disable-auto-launch-button').hidden = !enabled;
102 * Getter for the icon element.
106 return this.querySelector('.kiosk-app-icon');
110 * Getter for the name element.
114 return this.querySelector('.kiosk-app-name');
118 * Getter for the status text element.
122 return this.querySelector('.kiosk-app-status');
126 decorate: function() {
127 ListItem.prototype.decorate.call(this);
129 var sendMessageWithId = function(msg) {
131 chrome.send(msg, [this.data.id]);
135 this.querySelector('.enable-auto-launch-button').onclick =
136 sendMessageWithId('enableKioskAutoLaunch');
137 this.querySelector('.disable-auto-launch-button').onclick =
138 sendMessageWithId('disableKioskAutoLaunch');
139 this.querySelector('.row-delete-button').onclick =
140 sendMessageWithId('removeKioskApp');
144 * Updates UI from app info data.
147 this.icon.classList.toggle('spinner', this.data.isLoading);
148 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')';
150 this.name.textContent = this.data.name || this.data.id;
151 this.status.textContent = this.data.autoLaunch ?
152 loadTimeData.getString('autoLaunch') : '';
154 this.autoLaunch = this.data.autoLaunch;
159 * True if the app represented by this item will auto launch.
162 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR);
166 KioskAppList: KioskAppList