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@235: 'Queries' torsten@8: ], 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@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@241: result.setupColumns(displayFields); torsten@246: torsten@246: // Setup Columns of the probenlist torsten@246: if (filterFields.length > 0) { torsten@246: var items = filters.items.items; torsten@246: for (var i=0; i < items.length; i++) { torsten@246: var filtername = items[i].id; torsten@246: items[i].hide(); torsten@246: for (var j=0; j < filterFields.length; j++) { torsten@365: if ('filter-'+filterFields[j].dataIndex === filtername) { torsten@246: items[i].show(); torsten@366: } torsten@366: } torsten@366: } torsten@246: filters.show(); torsten@246: } else { torsten@246: filters.hide(); torsten@246: }; 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@28: console.log('Loading store'); torsten@36: torsten@36: // Get search parameters: torsten@36: var searchParams = {}; torsten@36: if (Ext.getCmp('search').getValue() == 1) { torsten@251: var mst = Ext.getCmp('filter-mstId').getValue(); torsten@251: var uwb = Ext.getCmp('filter-umwId').getValue(); torsten@96: if (mst !== null) { torsten@139: searchParams['mstId'] = mst; torsten@96: } torsten@96: if (uwb !== null) { torsten@139: searchParams['umwId'] = uwb; torsten@96: } torsten@36: } else { torsten@36: // Get date object an convert it into a timestamp (ms since epoch) torsten@251: var datefield = Ext.getCmp('filter-pbegin').getValue(); torsten@97: if (datefield !== null) { torsten@251: var ts = Ext.getCmp('filter-pbegin').getValue().getTime(); torsten@96: searchParams['begin'] = ts; torsten@96: } torsten@36: } 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@6: } torsten@6: });