Home | History | Annotate | Download | only in js
      1 // Copyright (c) 2012 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('apps_dev_tool', function() {
      6   'use strict';
      7 
      8   /**
      9    * AppsDevTool constructor.
     10    * @constructor
     11    * @extends {HTMLDivElement}
     12    */
     13   function AppsDevTool() {}
     14 
     15   AppsDevTool.prototype = {
     16     __proto__: HTMLDivElement.prototype,
     17 
     18     /**
     19      * Perform initial setup.
     20      */
     21     initialize: function() {
     22       cr.ui.decorate('tabbox', cr.ui.TabBox);
     23 
     24       // Set up the three buttons (load unpacked, pack and update).
     25       document.querySelector('#apps-tab .load-unpacked').
     26           addEventListener('click', this.handleLoadUnpackedItem_.bind(this));
     27       document.querySelector('#extensions-tab .load-unpacked').
     28           addEventListener('click', this.handleLoadUnpackedItem_.bind(this));
     29       document.querySelector('#apps-tab .update-items-now').
     30           addEventListener('click', this.handleUpdateItemNow_.bind(this,
     31           document.querySelector('#apps-tab .update-items-progress')));
     32       document.querySelector('#extensions-tab .update-items-now').
     33           addEventListener('click', this.handleUpdateItemNow_.bind(this,
     34           document.querySelector('#extensions-tab .update-items-progress')));
     35       var packItemOverlay =
     36           apps_dev_tool.PackItemOverlay.getInstance().initializePage();
     37 
     38       preventDefaultOnPoundLinkClicks();  // From webui/js/util.js
     39     },
     40 
     41     /**
     42      * Handles the Load Unpacked Extension button.
     43      * @param {!Event} e Click event.
     44      * @private
     45      */
     46     handleLoadUnpackedItem_: function(e) {
     47       chrome.developerPrivate.loadUnpacked();
     48     },
     49 
     50     /**
     51      * Handles the Update Extension Now Button.
     52      * @param {!Element} tabNode Element containing the progress label.
     53      * @param {!Event} e Click event.
     54      * @private
     55      */
     56     handleUpdateItemNow_: function(progressLabelNode, e) {
     57       progressLabelNode.classList.add('updating');
     58       chrome.developerPrivate.autoUpdate(function(response) {
     59         // autoUpdate() will run too fast. We wait for 2 sec
     60         // before hiding the label so that the user can see it.
     61         setTimeout(function() {
     62           progressLabelNode.classList.remove('updating');
     63         }, 2000);
     64       });
     65     },
     66   };
     67 
     68   /**
     69    * Returns the current overlay or null if one does not exist.
     70    * @return {Element} The overlay element.
     71    */
     72   AppsDevTool.getCurrentOverlay = function() {
     73     return document.querySelector('#overlay .page.showing');
     74   };
     75 
     76   /**
     77    * Shows |el|. If there's another overlay showing, hide it.
     78    * @param {HTMLElement} el The overlay page to show. If falsey, all overlays
     79    *     are hidden.
     80    */
     81   AppsDevTool.showOverlay = function(el) {
     82     var currentlyShowingOverlay = AppsDevTool.getCurrentOverlay();
     83     if (currentlyShowingOverlay)
     84       currentlyShowingOverlay.classList.remove('showing');
     85     if (el)
     86       el.classList.add('showing');
     87     overlay.hidden = !el;
     88     uber.invokeMethodOnParent(el ? 'beginInterceptingEvents' :
     89                                    'stopInterceptingEvents');
     90   };
     91 
     92   /**
     93    * Loads translated strings.
     94    */
     95   AppsDevTool.initStrings = function() {
     96     chrome.developerPrivate.getStrings(function(strings) {
     97       loadTimeData.data = strings;
     98       i18nTemplate.process(document, loadTimeData);
     99 
    100       // Check managed profiles.
    101       chrome.developerPrivate.isProfileManaged(function(isManaged) {
    102         if (!isManaged)
    103           return;
    104         alertOverlay.setValues(
    105             loadTimeData.getString('managedProfileDialogTitle'),
    106             loadTimeData.getString('managedProfileDialogDescription'),
    107             loadTimeData.getString('managedProfileDialogCloseButton'),
    108             null,
    109             function() {
    110               AppsDevTool.showOverlay(null);
    111               window.close();
    112             },
    113             null);
    114         AppsDevTool.showOverlay($('alertOverlay'));
    115       });
    116     });
    117   };
    118 
    119   return {
    120     AppsDevTool: AppsDevTool,
    121   };
    122 });
    123