• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5cr.define('extensions', function() {
6  /**
7   * Encapsulated handling of ChromeOS kiosk apps options page.
8   * @constructor
9   */
10  function KioskAppsOverlay() {
11  }
12
13  cr.addSingletonGetter(KioskAppsOverlay);
14
15  KioskAppsOverlay.prototype = {
16    /**
17     * Clear error timer id.
18     * @type {?number}
19     */
20    clearErrorTimer_: null,
21
22    /**
23     * Initialize the page.
24     */
25    initialize: function() {
26      chrome.send('initializeKioskAppSettings');
27      extensions.KioskAppList.decorate($('kiosk-app-list'));
28
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));
33
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);
39    },
40
41    /*
42     * Invoked when the page is shown.
43     */
44    didShowPage: function() {
45      chrome.send('getKioskAppSettings');
46      $('kiosk-app-id-edit').focus();
47    },
48
49    /**
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.
52     */
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');
58
59      if (this.clearErrorTimer_)
60        window.clearTimeout(this.clearErrorTimer_);
61
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;
66      }.bind(this), 5000);
67    },
68
69    /**
70     * Handles keypressed event in the app id input element.
71     * @private
72     */
73    handleAppIdInputKeyPressed_: function(e) {
74      if (e.keyIdentifier == 'Enter' && e.target.value)
75        this.handleAddButtonClick_();
76    },
77
78    /**
79     * Handles click event on the add button.
80     * @private
81     */
82    handleAddButtonClick_: function() {
83      var appId = $('kiosk-app-id-edit').value;
84      if (!appId)
85        return;
86
87      chrome.send('addKioskApp', [appId]);
88      $('kiosk-app-id-edit').value = '';
89    },
90
91    /**
92     * Handles the overlay being dismissed.
93     * @private
94     */
95    handleDismiss_: function() {
96      this.handleAddButtonClick_();
97      extensions.ExtensionSettings.showOverlay(null);
98    }
99  };
100
101  /**
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.
106   */
107  KioskAppsOverlay.setSettings = function(settings) {
108    $('kiosk-app-list').setApps(settings.apps);
109    $('kiosk-disable-bailout-shortcut').checked = settings.disableBailout;
110  };
111
112  /**
113   * Update an app in kiosk-app-list.
114   * @param {!Object} app App info to be updated.
115   */
116  KioskAppsOverlay.updateApp = function(app) {
117    $('kiosk-app-list').updateApp(app);
118  };
119
120  /**
121   * Shows error for given app name/id.
122   * @param {!string} appName App name/id to show in error banner.
123   */
124  KioskAppsOverlay.showError = function(appName) {
125    KioskAppsOverlay.getInstance().showError(appName);
126  };
127
128  /**
129   * Enables consumer kiosk.
130   * @param {!boolean} enable True if consumer kiosk feature is enabled.
131   */
132  KioskAppsOverlay.enableKiosk = function(enable) {
133    $('add-kiosk-app').hidden = !enable;
134  };
135
136  // Export
137  return {
138    KioskAppsOverlay: KioskAppsOverlay
139  };
140});
141
142<include src="kiosk_app_list.js"></include>
143<include src="kiosk_app_disable_bailout_confirm.js"></include>
144