OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
6 /** @const */ var List = cr.ui.List; | 6 /** @const */ var List = cr.ui.List; |
7 /** @const */ var ListItem = cr.ui.ListItem; | 7 /** @const */ var ListItem = cr.ui.ListItem; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
11 * Creates a list for showing kiosk apps. | 11 * Creates a list for showing kiosk apps. |
12 * @constructor | 12 * @constructor |
13 * @extends {cr.ui.List} | 13 * @extends {cr.ui.List} |
14 */ | 14 */ |
15 var KioskAppList = cr.ui.define('list'); | 15 var KioskAppList = cr.ui.define('list'); |
16 | 16 |
17 KioskAppList.prototype = { | 17 KioskAppList.prototype = { |
18 __proto__: List.prototype, | 18 __proto__: List.prototype, |
19 | 19 |
| 20 /** |
| 21 * True if auto launch feature can be configured. |
| 22 * @type {?boolean} |
| 23 */ |
| 24 autoLaunchEnabled_: false, |
| 25 |
20 /** @override */ | 26 /** @override */ |
21 createItem: function(app) { | 27 createItem: function(app) { |
22 var item = new KioskAppListItem(); | 28 var item = new KioskAppListItem(); |
23 item.data = app; | 29 item.data = app; |
| 30 item.autoLaunchEnabled = this.autoLaunchEnabled_; |
24 return item; | 31 return item; |
25 }, | 32 }, |
26 | 33 |
27 /** | 34 /** |
| 35 * Sets auto launch enabled flag. |
| 36 * @param {boolean} enabled True if auto launch should be enabled. |
| 37 */ |
| 38 setAutoLaunchEnabled: function(enabled) { |
| 39 this.autoLaunchEnabled_ = enabled; |
| 40 }, |
| 41 |
| 42 /** |
28 * Loads the given list of apps. | 43 * Loads the given list of apps. |
29 * @param {!Array.<!Object>} apps An array of app info objects. | 44 * @param {!Array.<!Object>} apps An array of app info objects. |
30 */ | 45 */ |
31 setApps: function(apps) { | 46 setApps: function(apps) { |
32 this.dataModel = new ArrayDataModel(apps); | 47 this.dataModel = new ArrayDataModel(apps); |
33 }, | 48 }, |
34 | 49 |
35 /** | 50 /** |
36 * Updates the given app. | 51 * Updates the given app. |
37 * @param {!Object} app An app info object. | 52 * @param {!Object} app An app info object. |
(...skipping 22 matching lines...) Expand all Loading... |
60 | 75 |
61 KioskAppListItem.prototype = { | 76 KioskAppListItem.prototype = { |
62 __proto__: ListItem.prototype, | 77 __proto__: ListItem.prototype, |
63 | 78 |
64 /** | 79 /** |
65 * Data object to hold app info. | 80 * Data object to hold app info. |
66 * @type {Object} | 81 * @type {Object} |
67 * @private | 82 * @private |
68 */ | 83 */ |
69 data_: null, | 84 data_: null, |
| 85 |
70 get data() { | 86 get data() { |
71 assert(this.data_); | 87 assert(this.data_); |
72 return this.data_; | 88 return this.data_; |
73 }, | 89 }, |
| 90 |
74 set data(data) { | 91 set data(data) { |
75 this.data_ = data; | 92 this.data_ = data; |
76 this.redraw(); | 93 this.redraw(); |
77 }, | 94 }, |
78 | 95 |
| 96 set autoLaunchEnabled(enabled) { |
| 97 this.querySelector('.enable-auto-launch-button').hidden = !enabled; |
| 98 this.querySelector('.disable-auto-launch-button').hidden = !enabled; |
| 99 }, |
| 100 |
79 /** | 101 /** |
80 * Getter for the icon element. | 102 * Getter for the icon element. |
81 * @type {Element} | 103 * @type {Element} |
82 */ | 104 */ |
83 get icon() { | 105 get icon() { |
84 return this.querySelector('.kiosk-app-icon'); | 106 return this.querySelector('.kiosk-app-icon'); |
85 }, | 107 }, |
86 | 108 |
87 /** | 109 /** |
88 * Getter for the name element. | 110 * Getter for the name element. |
(...skipping 15 matching lines...) Expand all Loading... |
104 decorate: function() { | 126 decorate: function() { |
105 ListItem.prototype.decorate.call(this); | 127 ListItem.prototype.decorate.call(this); |
106 | 128 |
107 var sendMessageWithId = function(msg) { | 129 var sendMessageWithId = function(msg) { |
108 return function() { | 130 return function() { |
109 chrome.send(msg, [this.data.id]); | 131 chrome.send(msg, [this.data.id]); |
110 }.bind(this); | 132 }.bind(this); |
111 }.bind(this); | 133 }.bind(this); |
112 | 134 |
113 this.querySelector('.enable-auto-launch-button').onclick = | 135 this.querySelector('.enable-auto-launch-button').onclick = |
114 sendMessageWithId('enableKioskAutoLaunch'); | 136 sendMessageWithId('enableKioskAutoLaunch'); |
115 this.querySelector('.disable-auto-launch-button').onclick = | 137 this.querySelector('.disable-auto-launch-button').onclick = |
116 sendMessageWithId('disableKioskAutoLaunch'); | 138 sendMessageWithId('disableKioskAutoLaunch'); |
117 this.querySelector('.row-delete-button').onclick = | 139 this.querySelector('.row-delete-button').onclick = |
118 sendMessageWithId('removeKioskApp'); | 140 sendMessageWithId('removeKioskApp'); |
119 }, | 141 }, |
120 | 142 |
121 /** | 143 /** |
122 * Updates UI from app info data. | 144 * Updates UI from app info data. |
123 */ | 145 */ |
124 redraw: function() { | 146 redraw: function() { |
125 this.icon.classList.toggle('spinner', this.data.isLoading); | 147 this.icon.classList.toggle('spinner', this.data.isLoading); |
126 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')'; | 148 this.icon.style.backgroundImage = 'url(' + this.data.iconURL + ')'; |
(...skipping 10 matching lines...) Expand all Loading... |
137 * True if the app represented by this item will auto launch. | 159 * True if the app represented by this item will auto launch. |
138 * @type {boolean} | 160 * @type {boolean} |
139 */ | 161 */ |
140 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR); | 162 cr.defineProperty(KioskAppListItem, 'autoLaunch', cr.PropertyKind.BOOL_ATTR); |
141 | 163 |
142 // Export | 164 // Export |
143 return { | 165 return { |
144 KioskAppList: KioskAppList | 166 KioskAppList: KioskAppList |
145 }; | 167 }; |
146 }); | 168 }); |
OLD | NEW |