Path: blob/master/webroot/rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js
12242 views
/**1* @provides javelin-behavior-dashboard-query-panel-select2* @requires javelin-behavior3* javelin-dom4*/56/**7* When editing a "Query" panel on dashboards, make the "Query" selector control8* dynamically update in response to changes to the "Engine" selector control.9*/10JX.behavior('dashboard-query-panel-select', function(config) {1112var app_control = JX.$(config.applicationID);13var query_control = JX.$(config.queryID);1415// If we have a currently-selected query, add it to the appropriate group16// in the options list if it does not already exist.17if (config.value.key !== null) {18var app = app_control.value;19if (!(app in config.options)) {20config.options[app] = [];21}2223var found = false;24for (var ii = 0; ii < config.options[app].length; ii++) {25if (config.options[app][ii].key == config.value.key) {26found = true;27break;28}29}3031if (!found) {32config.options[app] = [config.value].concat(config.options[app]);33}34}3536// When the user changes the selected search engine, update the query37// control to show available queries for that engine.38function update() {39var app = app_control.value;4041var old_value = query_control.value;42var new_value = null;4344var options = config.options[app] || [];45var nodes = [];46for (var ii = 0; ii < options.length; ii++) {47if (new_value === null) {48new_value = options[ii].key;49}50if (options[ii].key == old_value) {51new_value = options[ii].key;52}53nodes.push(JX.$N('option', {value: options[ii].key}, options[ii].name));54}5556JX.DOM.setContent(query_control, nodes);57query_control.value = new_value;58}5960JX.DOM.listen(app_control, 'change', null, function() { update(); });61update();6263});646566