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.
6 * The type of the app data object. The definition is based on
7 * chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc:
9 * @typedef {{id: string,
12 * autoLaunch: boolean,
13 * isLoading: boolean}}
17 cr
.define('extensions', function() {
18 /** @const */ var List
= cr
.ui
.List
;
19 /** @const */ var ListItem
= cr
.ui
.ListItem
;
20 /** @const */ var ArrayDataModel
= cr
.ui
.ArrayDataModel
;
23 * Creates a list for showing kiosk apps.
25 * @extends {cr.ui.List}
27 var KioskAppList
= cr
.ui
.define('list');
29 KioskAppList
.prototype = {
30 __proto__
: List
.prototype,
33 * True if auto launch feature can be configured.
36 autoLaunchEnabled_
: false,
39 createItem: function(app
) {
40 var item
= new KioskAppListItem();
42 item
.autoLaunchEnabled
= this.autoLaunchEnabled_
;
47 * Sets auto launch enabled flag.
48 * @param {boolean} enabled True if auto launch should be enabled.
50 setAutoLaunchEnabled: function(enabled
) {
51 this.autoLaunchEnabled_
= enabled
;
55 * Loads the given list of apps.
56 * @param {!Array<!Object>} apps An array of app info objects.
58 setApps: function(apps
) {
59 this.dataModel
= new ArrayDataModel(apps
);
63 * Updates the given app.
64 * @param {!AppDict} app An app info object.
66 updateApp: function(app
) {
67 for (var i
= 0; i
< this.items
.length
; ++i
) {
68 if (this.items
[i
].data
.id
== app
.id
) {
69 this.items
[i
].data
= app
;
77 * Creates a list item for a kiosk app.
79 * @extends {cr.ui.ListItem}
81 var KioskAppListItem
= cr
.ui
.define(function() {
82 var el
= $('kiosk-app-list-item-template').cloneNode(true);
83 el
.removeAttribute('id');
88 KioskAppListItem
.prototype = {
89 __proto__
: ListItem
.prototype,
92 * Data object to hold app info.
108 set autoLaunchEnabled(enabled
) {
109 this.querySelector('.enable-auto-launch-button').hidden
= !enabled
;
110 this.querySelector('.disable-auto-launch-button').hidden
= !enabled
;
114 * Getter for the icon element.
118 return this.querySelector('.kiosk-app-icon');
122 * Getter for the name element.
126 return this.querySelector('.kiosk-app-name');
130 * Getter for the status text element.
134 return this.querySelector('.kiosk-app-status');
138 decorate: function() {
139 ListItem
.prototype.decorate
.call(this);
141 var sendMessageWithId = function(msg
) {
143 chrome
.send(msg
, [this.data
.id
]);
147 this.querySelector('.enable-auto-launch-button').onclick
=
148 sendMessageWithId('enableKioskAutoLaunch');
149 this.querySelector('.disable-auto-launch-button').onclick
=
150 sendMessageWithId('disableKioskAutoLaunch');
151 this.querySelector('.row-delete-button').onclick
=
152 sendMessageWithId('removeKioskApp');
156 * Updates UI from app info data.
159 this.icon
.classList
.toggle('spinner', this.data
.isLoading
);
160 this.icon
.style
.backgroundImage
= 'url(' + this.data
.iconURL
+ ')';
162 this.name
.textContent
= this.data
.name
|| this.data
.id
;
163 this.status
.textContent
= this.data
.autoLaunch
?
164 loadTimeData
.getString('autoLaunch') : '';
166 this.autoLaunch
= this.data
.autoLaunch
;
171 * True if the app represented by this item will auto launch.
173 cr
.defineProperty(KioskAppListItem
, 'autoLaunch', cr
.PropertyKind
.BOOL_ATTR
);
177 KioskAppList
: KioskAppList