[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/js/application/dashboard/ -> behavior-dashboard-query-panel-select.js (source)

   1  /**
   2   * @provides javelin-behavior-dashboard-query-panel-select
   3   * @requires javelin-behavior
   4   *           javelin-dom
   5   */
   6  
   7  /**
   8   * When editing a "Query" panel on dashboards, make the "Query" selector control
   9   * dynamically update in response to changes to the "Engine" selector control.
  10   */
  11  JX.behavior('dashboard-query-panel-select', function(config) {
  12  
  13    var app_control = JX.$(config.applicationID);
  14    var query_control = JX.$(config.queryID);
  15  
  16    // If we have a currently-selected query, add it to the appropriate group
  17    // in the options list if it does not already exist.
  18    if (config.value.key !== null) {
  19      var app = app_control.value;
  20      if (!(app in config.options)) {
  21        config.options[app] = [];
  22      }
  23  
  24      var found = false;
  25      for (var ii = 0; ii < config.options[app].length; ii++) {
  26        if (config.options[app][ii].key == config.value.key) {
  27          found = true;
  28          break;
  29        }
  30      }
  31  
  32      if (!found) {
  33        config.options[app] = [config.value].concat(config.options[app]);
  34      }
  35    }
  36  
  37    // When the user changes the selected search engine, update the query
  38    // control to show available queries for that engine.
  39    function update() {
  40      var app = app_control.value;
  41  
  42      var old_value = query_control.value;
  43      var new_value = null;
  44  
  45      var options = config.options[app] || [];
  46      var nodes = [];
  47      for (var ii = 0; ii < options.length; ii++) {
  48        if (new_value === null) {
  49          new_value = options[ii].key;
  50        }
  51        if (options[ii].key == old_value) {
  52          new_value = options[ii].key;
  53        }
  54        nodes.push(JX.$N('option', {value: options[ii].key}, options[ii].name));
  55      }
  56  
  57      JX.DOM.setContent(query_control, nodes);
  58      query_control.value = new_value;
  59    }
  60  
  61    JX.DOM.listen(app_control, 'change', null, function() { update(); });
  62    update();
  63  
  64  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1