Home | History | Annotate | Download | only in chromeos
      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 
      5 cr.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_);
     38     },
     39 
     40     /*
     41      * Invoked when the page is shown.
     42      */
     43     didShowPage: function() {
     44       chrome.send('getKioskAppSettings');
     45       $('kiosk-app-id-edit').focus();
     46     },
     47 
     48     /**
     49      * Shows error for given app name/id and schedules it to cleared.
     50      * @param {!string} appName App name/id to show in error banner.
     51      */
     52     showError: function(appName) {
     53       var errorBanner = $('kiosk-apps-error-banner');
     54       var appNameElement = errorBanner.querySelector('.kiosk-app-name');
     55       appNameElement.textContent = appName;
     56       errorBanner.classList.add('visible');
     57 
     58       if (this.clearErrorTimer_)
     59         window.clearTimeout(this.clearErrorTimer_);
     60 
     61       // Sets a timer to clear out error banner after 5 seconds.
     62       this.clearErrorTimer_ = window.setTimeout(function() {
     63         errorBanner.classList.remove('visible');
     64         this.clearErrorTimer_ = null;
     65       }.bind(this), 5000);
     66     },
     67 
     68     /**
     69      * Handles keypressed event in the app id input element.
     70      * @private
     71      */
     72     handleAppIdInputKeyPressed_: function(e) {
     73       if (e.keyIdentifier == 'Enter' && e.target.value) {
     74         chrome.send('addKioskApp', [e.target.value]);
     75         e.target.value = '';
     76       }
     77     },
     78 
     79     /**
     80      * Handles the overlay being dismissed.
     81      * @private
     82      */
     83     handleDismiss_: function() {
     84       ExtensionSettings.showOverlay(null);
     85     }
     86   };
     87 
     88   /**
     89    * Sets apps to be displayed in kiosk-app-list.
     90    * @param {!Object.<{apps: !Array.<Object>, disableBailout: boolean}>}
     91    *     settings An object containing an array of app info objects and
     92    *     disable bailout shortcut flag.
     93    */
     94   KioskAppsOverlay.setSettings = function(settings) {
     95     $('kiosk-app-list').setApps(settings.apps);
     96     $('kiosk-disable-bailout-shortcut').checked = settings.disableBailout;
     97   };
     98 
     99   /**
    100    * Update an app in kiosk-app-list.
    101    * @param {!Object} app App info to be updated.
    102    */
    103   KioskAppsOverlay.updateApp = function(app) {
    104     $('kiosk-app-list').updateApp(app);
    105   };
    106 
    107   /**
    108    * Shows error for given app name/id.
    109    * @param {!string} appName App name/id to show in error banner.
    110    */
    111   KioskAppsOverlay.showError = function(appName) {
    112     KioskAppsOverlay.getInstance().showError(appName);
    113   };
    114 
    115   /**
    116    * Enables consumer kiosk.
    117    * @param {!boolean} enable True if consumer kiosk feature is enabled.
    118    */
    119   KioskAppsOverlay.enableKiosk = function(enable) {
    120     $('add-kiosk-app').hidden = !enable;
    121   };
    122 
    123   // Export
    124   return {
    125     KioskAppsOverlay: KioskAppsOverlay
    126   };
    127 });
    128 
    129 <include src="kiosk_app_list.js"></include>
    130 <include src="kiosk_app_disable_bailout_confirm.js"></include>
    131