torsten@31: var queries = new Array('query1', 'query2'); torsten@246: torsten@294: /** torsten@294: * Controller for the Search torsten@294: * This controller handles all logic related to the search torsten@294: */ torsten@6: Ext.define('Lada.controller.Sql', { torsten@6: extend: 'Ext.app.Controller', torsten@8: stores: [ torsten@235: 'Proben', // List of found Proben torsten@374: 'ProbenList', // List of found Proben torsten@386: 'Queries', rrenkert@422: 'Info' torsten@8: ], torsten@369: requires: [ torsten@369: 'Lada.view.widgets.Mst', torsten@369: 'Lada.view.widgets.Uwb', torsten@386: 'Lada.view.widgets.Datetime', torsten@386: 'Lada.view.About' torsten@369: ], torsten@6: init: function() { torsten@6: console.log('Initialising the Sql controller'); torsten@6: this.control({ torsten@6: // CSS like selector to select element in the viewport. See torsten@6: // ComponentQuery documentation for more details. torsten@31: '#search': { torsten@6: // Map the "render" event to the given function. torsten@6: render: this.onPanelRendered, torsten@6: // Map Doubleclick on rows of the probenlist. torsten@28: select: this.selectSql torsten@31: }, torsten@31: '#SearchBtn': { torsten@31: // Map click event on Button. torsten@31: click: this.search torsten@31: }, torsten@31: '#ResetBtn': { torsten@31: // Map click event on Button. torsten@31: click: this.reset torsten@386: }, torsten@386: '#AboutBtn': { torsten@386: // Map click event on Button. torsten@386: click: this.about torsten@6: } torsten@6: }); torsten@6: }, torsten@6: onPanelRendered: function() { torsten@6: console.log('The panel was rendered'); torsten@6: }, torsten@294: /** torsten@294: * Function called when the user selects a SQL query in the dropdownlist. torsten@294: * The function will hide/display additional element related to the torsten@294: * selected search query torsten@294: */ torsten@28: selectSql: function(element, record, index) { torsten@241: var result = Ext.getCmp('result'); torsten@246: var filters = Ext.getCmp('queryfilters'); torsten@252: var sqlquery = Ext.getCmp('sqlquery'); torsten@252: var sqldesc = Ext.getCmp('sqldesc'); torsten@31: var buttons = Ext.getCmp('SearchBtnPanel'); torsten@253: var displayFields = record[0].data.results; torsten@246: var filterFields = record[0].data.filters; torsten@253: torsten@31: this.reset(); torsten@246: torsten@252: sqlquery.setValue(record[0].data.sql); torsten@252: sqldesc.setValue(record[0].data.description); torsten@252: torsten@246: // Setup Columns of the probenlist torsten@413: displayFields.reverse(); torsten@241: result.setupColumns(displayFields); torsten@246: torsten@369: // Setup Filters of the probenlist torsten@369: // torsten@369: // Allowed types are torsten@369: // * text torsten@369: // * number torsten@369: // * datetime torsten@375: // * bool torsten@369: // * listmst torsten@369: // * listumw torsten@375: // * listver torsten@375: // * listdbasis torsten@375: // * listnetz torsten@369: // torsten@369: // Iterate over all configured filters and add filters dynamically torsten@369: // torsten@369: // 1. Empty filters torsten@369: filters.removeAll(); torsten@369: var hide = true; torsten@369: // 2. Iterate over all configured filters torsten@369: for (var j=0; j < filterFields.length; j++) { torsten@369: var type = filterFields[j].type; torsten@369: var name = filterFields[j].dataIndex; torsten@369: var label = filterFields[j].label; rrenkert@418: var multi = filterFields[j].multiSelect; torsten@369: var field = null; torsten@369: if (type == "text") { torsten@369: console.log("Found text filter"); torsten@369: field = Ext.create('Ext.form.field.Text', { name: name, fieldLabel: label }); torsten@369: } else if (type == "number") { torsten@369: console.log("Found number filter"); torsten@369: field = Ext.create('Ext.form.field.Number', { name: name, fieldLabel: label }); torsten@369: } else if (type == "datetime") { torsten@369: console.log("Found datetime filter"); torsten@369: field = Ext.create('Lada.view.widgets.Datetime', { name: name, fieldLabel: label }); torsten@375: } else if (type == "bool") { torsten@375: console.log("Found bool filter"); torsten@375: field = Ext.create('Lada.view.widgets.Testdatensatz', { name: name, fieldLabel: label, emptyText: '' }); torsten@369: } else if (type == "listmst") { torsten@369: console.log("Found listmst filter"); rrenkert@418: field = Ext.create('Lada.view.widgets.Mst', { name: name, fieldLabel: label, multiSelect: multi }); torsten@369: } else if (type == "listumw") { torsten@369: console.log("Found listumw filter"); rrenkert@418: field = Ext.create('Lada.view.widgets.Uwb', { name: name, fieldLabel: label, multiSelect: multi }); torsten@375: } else if (type == "listdbasis") { torsten@375: console.log("Found listdbasis filter"); rrenkert@418: field = Ext.create('Lada.view.widgets.Datenbasis', { name: name, fieldLabel: label, multiSelect: multi }); torsten@375: } else if (type == "listver") { torsten@375: console.log("Found listver filter"); rrenkert@418: field = Ext.create('Lada.view.widgets.Verwaltungseinheit', { name: name, fieldLabel: label, multiSelect: multi }); torsten@375: } else if (type == "listnetz") { torsten@375: console.log("Found listnetz filter"); rrenkert@418: field = Ext.create('Lada.view.widgets.Netzbetreiber', { name: name, fieldLabel: label, multiSelect: multi }); torsten@366: } torsten@369: if (field) { torsten@369: console.log("Pushing field to filters"); torsten@369: filters.add(field); torsten@369: filters.show(); torsten@369: hide = false; torsten@369: } torsten@369: } torsten@369: if (hide) { torsten@246: filters.hide(); torsten@369: } torsten@31: buttons.show(); torsten@31: }, torsten@294: /** torsten@294: * Function is called when the user clicks the search button. The function torsten@294: * will perform a search to the server on refreshes the result list. torsten@294: */ torsten@31: search: function(element, record, index) { torsten@31: var result = Ext.getCmp('result'); torsten@369: var filters = Ext.getCmp('queryfilters'); torsten@369: var search = Ext.getCmp('search'); torsten@36: torsten@36: // Get search parameters: torsten@36: var searchParams = {}; torsten@369: searchParams['qid'] = search.getValue(); torsten@369: for (var i = filters.items.length - 1; i >= 0; i--){ torsten@369: var filter = filters.items.items[i]; torsten@369: var value = filter.getValue(); torsten@378: if (value instanceof Array) { torsten@378: value = value.join(","); torsten@378: } torsten@378: searchParams[filter.getName()] = value; torsten@36: } torsten@369: console.log('Loading store with the following search params: ' + searchParams); torsten@36: result.getStore().load({ torsten@36: params: searchParams torsten@36: }); torsten@28: console.log('Store loaded'); torsten@25: result.show(); torsten@31: }, torsten@31: reset: function(element, record, index) { torsten@31: var buttons = Ext.getCmp('SearchBtnPanel'); torsten@31: var result = Ext.getCmp('result'); torsten@246: //for (var i = 0; i < queries.length; ++i) { torsten@246: // var toHide = Ext.getCmp(queries[i]); torsten@246: // toHide.hide(); torsten@246: //} torsten@147: //result.hide(); torsten@147: //buttons.hide(); torsten@386: }, torsten@386: about: function(element, record, index) { torsten@386: var info = this.getInfoStore(); torsten@386: var view = Ext.widget('about', {info: info}); torsten@6: } torsten@6: });