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.<Object>, disableBailout: boolean}>}
104 * settings An object containing an array of app info objects and
105 * disable bailout shortcut flag.
107 KioskAppsOverlay.setSettings = function(settings) {
108 $('kiosk-app-list').setApps(settings.apps);
109 $('kiosk-disable-bailout-shortcut').checked = settings.disableBailout;
113 * Update an app in kiosk-app-list.
114 * @param {!Object} app App info to be updated.
116 KioskAppsOverlay.updateApp = function(app) {
117 $('kiosk-app-list').updateApp(app);
121 * Shows error for given app name/id.
122 * @param {!string} appName App name/id to show in error banner.
124 KioskAppsOverlay.showError = function(appName) {
125 KioskAppsOverlay.getInstance().showError(appName);
129 * Enables consumer kiosk.
130 * @param {!boolean} enable True if consumer kiosk feature is enabled.
132 KioskAppsOverlay.enableKiosk = function(enable) {
133 $('add-kiosk-app').hidden = !enable;
138 KioskAppsOverlay: KioskAppsOverlay
142 <include src="kiosk_app_list.js"></include>
143 <include src="kiosk_app_disable_bailout_confirm.js"></include>