Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / resources / extensions / chromeos / kiosk_app_list.js
blobd92784097d7546765fa95de40f79416e4e6ec9b7
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 /**
6 * The type of the app data object. The definition is based on
7 * chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.cc:
8 * PopulateAppDict()
9 * @typedef {{id: string,
10 * name: string,
11 * iconURL: string,
12 * autoLaunch: boolean,
13 * isLoading: boolean}}
15 var AppDict;
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;
22 /**
23 * Creates a list for showing kiosk apps.
24 * @constructor
25 * @extends {cr.ui.List}
27 var KioskAppList = cr.ui.define('list');
29 KioskAppList.prototype = {
30 __proto__: List.prototype,
32 /**
33 * True if auto launch feature can be configured.
34 * @type {?boolean}
36 autoLaunchEnabled_: false,
38 /** @override */
39 createItem: function(app) {
40 var item = new KioskAppListItem();
41 item.data = app;
42 item.autoLaunchEnabled = this.autoLaunchEnabled_;
43 return item;
46 /**
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;
54 /**
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);
62 /**
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;
70 break;
76 /**
77 * Creates a list item for a kiosk app.
78 * @constructor
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');
84 el.hidden = false;
85 return el;
86 });
88 KioskAppListItem.prototype = {
89 __proto__: ListItem.prototype,
91 /**
92 * Data object to hold app info.
93 * @type {Object}
94 * @private
96 data_: null,
98 get data() {
99 assert(this.data_);
100 return this.data_;
103 set data(data) {
104 this.data_ = data;
105 this.redraw();
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.
115 * @type {Element}
117 get icon() {
118 return this.querySelector('.kiosk-app-icon');
122 * Getter for the name element.
123 * @type {Element}
125 get name() {
126 return this.querySelector('.kiosk-app-name');
130 * Getter for the status text element.
131 * @type {Element}
133 get status() {
134 return this.querySelector('.kiosk-app-status');
137 /** @override */
138 decorate: function() {
139 ListItem.prototype.decorate.call(this);
141 var sendMessageWithId = function(msg) {
142 return function() {
143 chrome.send(msg, [this.data.id]);
144 }.bind(this);
145 }.bind(this);
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.
158 redraw: function() {
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);
175 // Export
176 return {
177 KioskAppList: KioskAppList