torsten@472: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz torsten@472: * Software engineering by Intevation GmbH torsten@472: * torsten@472: * This file is Free Software under the GNU GPL (v>=3) torsten@472: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@500: * the documentation coming with IMIS-Labordaten-Application for details. torsten@472: */ torsten@472: 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', raimund@491: raimund@491: requires: [ raimund@491: 'Lada.view.widgets.Mst', raimund@491: 'Lada.view.widgets.Uwb', raimund@491: 'Lada.view.widgets.Datetime', raimund@491: 'Lada.view.About' raimund@491: ], raimund@491: 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: ], raimund@491: torsten@6: init: function() { 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 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: }); raimund@491: this.callParent(arguments); torsten@6: }, raimund@491: 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: */ raimund@500: selectSql: function(element, record) { torsten@241: var result = Ext.getCmp('result'); torsten@246: var filters = Ext.getCmp('queryfilters'); raimund@527: var columns = Ext.getCmp('results'); 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: raimund@527: columnString = []; raimund@527: for (var i = 0; i < displayFields.length; i++) { raimund@527: columnString.push(displayFields[i].header); raimund@527: } raimund@527: columns.setValue(columnString.join(', ')); 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 raimund@500: var j; raimund@500: for (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; raimund@500: if (type === 'text') { raimund@491: field = Ext.create('Ext.form.field.Text', { raimund@491: name: name, raimund@491: fieldLabel: label raimund@491: }); raimund@491: } raimund@500: else if (type === 'number') { raimund@491: field = Ext.create('Ext.form.field.Number', { raimund@491: name: name, raimund@491: fieldLabel: label raimund@491: }); raimund@491: } raimund@500: else if (type === 'datetime') { raimund@491: field = Ext.create('Lada.view.widgets.Datetime', { raimund@491: name: name, raimund@491: fieldLabel: label raimund@491: }); raimund@491: } raimund@500: else if (type === 'bool') { raimund@491: field = Ext.create('Lada.view.widgets.Testdatensatz', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: emptyText: '' raimund@491: }); raimund@491: } raimund@500: else if (type === 'listmst') { raimund@491: field = Ext.create('Lada.view.widgets.Mst', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: multiSelect: multi raimund@491: }); raimund@491: } raimund@500: else if (type === 'listumw') { raimund@491: field = Ext.create('Lada.view.widgets.Uwb', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: multiSelect: multi raimund@491: }); raimund@491: } raimund@500: else if (type === 'listdbasis') { raimund@491: field = Ext.create('Lada.view.widgets.Datenbasis', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: multiSelect: multi raimund@491: }); raimund@491: } raimund@500: else if (type === 'listver') { raimund@491: field = Ext.create('Lada.view.widgets.Verwaltungseinheit', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: multiSelect: multi raimund@491: }); raimund@491: } raimund@500: else if (type === 'listnetz') { raimund@491: field = Ext.create('Lada.view.widgets.Netzbetreiber', { raimund@491: name: name, raimund@491: fieldLabel: label, raimund@491: multiSelect: multi raimund@491: }); torsten@366: } torsten@369: if (field) { 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: }, raimund@491: 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: */ raimund@500: search: function() { 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(); raimund@491: 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) { raimund@500: value = value.join(','); torsten@378: } torsten@378: searchParams[filter.getName()] = value; torsten@36: } torsten@36: result.getStore().load({ torsten@36: params: searchParams torsten@36: }); torsten@25: result.show(); torsten@31: }, raimund@491: raimund@500: reset: function() { raimund@500: // var buttons = Ext.getCmp('SearchBtnPanel'); raimund@500: // var result = Ext.getCmp('result'); raimund@500: // for (var i = 0; i < queries.length; ++i) { raimund@500: // var toHide = Ext.getCmp(queries[i]); raimund@500: // toHide.hide(); raimund@500: // } raimund@500: // result.hide(); raimund@500: // buttons.hide(); torsten@386: }, raimund@491: raimund@500: about: function() { torsten@386: var info = this.getInfoStore(); raimund@500: Ext.widget('about', { raimund@491: info: info raimund@491: }); torsten@6: } torsten@6: });