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() {
7 * Encapsulated handling of ChromeOS kiosk apps options page.
10 function KioskAppsOverlay() {
13 cr
.addSingletonGetter(KioskAppsOverlay
);
15 KioskAppsOverlay
.prototype = {
17 * Clear error timer id.
20 clearErrorTimer_
: null,
23 * Initialize the page.
25 initialize: function() {
26 chrome
.send('initializeKioskAppSettings');
27 extensions
.KioskAppList
.decorate($('kiosk-app-list'));
29 var overlay
= $('kiosk-apps-page');
30 cr
.ui
.overlay
.setupOverlay(overlay
);
31 cr
.ui
.overlay
.globalInitialization();
32 overlay
.addEventListener('cancelOverlay', this.handleDismiss_
.bind(this));
34 $('kiosk-options-overlay-confirm').onclick
=
35 this.handleDismiss_
.bind(this);
36 $('kiosk-app-id-edit').addEventListener('keypress',
37 this.handleAppIdInputKeyPressed_
.bind(this));
38 $('kiosk-app-add').onclick
= this.handleAddButtonClick_
.bind(this);
42 * Invoked when the page is shown.
44 didShowPage: function() {
45 chrome
.send('getKioskAppSettings');
46 $('kiosk-app-id-edit').focus();
50 * Shows error for given app name/id and schedules it to cleared.
51 * @param {!string} appName App name/id to show in error banner.
53 showError: function(appName
) {
54 var errorBanner
= $('kiosk-apps-error-banner');
55 var appNameElement
= errorBanner
.querySelector('.kiosk-app-name');
56 appNameElement
.textContent
= appName
;
57 errorBanner
.classList
.add('visible');
59 if (this.clearErrorTimer_
)
60 window
.clearTimeout(this.clearErrorTimer_
);
62 // Sets a timer to clear out error banner after 5 seconds.
63 this.clearErrorTimer_
= window
.setTimeout(function() {
64 errorBanner
.classList
.remove('visible');
65 this.clearErrorTimer_
= null;
70 * Handles keypressed event in the app id input element.
73 handleAppIdInputKeyPressed_: function(e
) {
74 if (e
.keyIdentifier
== 'Enter' && e
.target
.value
)
75 this.handleAddButtonClick_();
79 * Handles click event on the add button.
82 handleAddButtonClick_: function() {
83 var appId
= $('kiosk-app-id-edit').value
;
87 chrome
.send('addKioskApp', [appId
]);
88 $('kiosk-app-id-edit').value
= '';
92 * Handles the overlay being dismissed.
95 handleDismiss_: function() {
96 this.handleAddButtonClick_();
97 extensions
.ExtensionSettings
.showOverlay(null);
102 * Sets apps to be displayed in kiosk-app-list.
103 * @param {!Object<{apps: !Array<AppDict>, disableBailout: boolean,
104 * hasAutoLaunchApp: boolean}>} settings An object containing an array of
105 * app info objects and disable bailout shortcut flag.
107 KioskAppsOverlay
.setSettings = function(settings
) {
108 $('kiosk-app-list').setApps(settings
.apps
);
109 $('kiosk-disable-bailout-shortcut').checked
= settings
.disableBailout
;
110 $('kiosk-disable-bailout-shortcut').disabled
= !settings
.hasAutoLaunchApp
;
114 * Update an app in kiosk-app-list.
115 * @param {!Object} app App info to be updated.
117 KioskAppsOverlay
.updateApp = function(app
) {
118 $('kiosk-app-list').updateApp(app
);
122 * Shows error for given app name/id.
123 * @param {!string} appName App name/id to show in error banner.
125 KioskAppsOverlay
.showError = function(appName
) {
126 KioskAppsOverlay
.getInstance().showError(appName
);
130 * Enables consumer kiosk.
131 * @param {!{kioskEnabled: boolean, autoLaunchEnabled: boolean}} params
133 KioskAppsOverlay
.enableKiosk = function(params
) {
134 $('add-kiosk-app').hidden
= !params
.kioskEnabled
;
135 $('kiosk-disable-bailout-shortcut').parentNode
.hidden
=
136 !params
.autoLaunchEnabled
;
137 $('kiosk-app-list').setAutoLaunchEnabled(params
.autoLaunchEnabled
);
142 KioskAppsOverlay
: KioskAppsOverlay
146 <include src
="kiosk_app_list.js">
147 <include src
="kiosk_app_disable_bailout_confirm.js">