raimund@548: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@548: * Software engineering by Intevation GmbH raimund@548: * raimund@548: * This file is Free Software under the GNU GPL (v>=3) raimund@548: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@548: * the documentation coming with IMIS-Labordaten-Application for details. raimund@548: */ raimund@548: raimund@548: /** raimund@548: * Controller for the Filter raimund@548: * This controller handles all logic related to the filter raimund@548: */ raimund@548: Ext.define('Lada.controller.Filter', { raimund@548: extend: 'Ext.app.Controller', raimund@548: raimund@548: requires: [ raimund@548: 'Lada.view.widget.Messstelle', raimund@548: 'Lada.view.widget.Umwelt' raimund@548: ], raimund@548: raimund@548: stores: [ dustin@908: 'ProbenList', // List of found Proben dustin@908: 'MessprogrammeList' //List of found Messprogramme raimund@548: ], raimund@548: raimund@734: displayFields: null, raimund@734: dustin@742: /** dustin@742: * Initialize this Controller dustin@742: * It has 4 Listeners dustin@742: */ raimund@548: init: function() { raimund@548: this.control({ raimund@548: // CSS like selector to select element in the viewport. See raimund@548: // ComponentQuery documentation for more details. raimund@548: 'combobox[name=filter]': { dustin@794: // Map Select event dustin@882: select: this.selectSql raimund@548: }, raimund@548: 'button[action=search]': { raimund@548: // Map click event on Button. raimund@548: click: this.search raimund@548: }, raimund@548: 'button[action=reset]': { raimund@548: // Map click event on Button. raimund@548: click: this.reset raimund@548: }, raimund@548: 'menuitem[action=about]': { raimund@548: // Map click event on Button. raimund@548: click: this.about raimund@548: } raimund@548: }); raimund@548: this.callParent(arguments); raimund@548: }, raimund@548: raimund@548: /** raimund@548: * Function called when the user selects a SQL query in the dropdownlist. raimund@548: * The function will hide/display additional element related to the dustin@975: * selected search query. dustin@975: * It also replaces the Store of the Filteresultgrid. dustin@975: * Two possibilities exist to do so: Proben/Messprogramme where dynamic columns exist, but the dustin@975: * content remains of the same type and Stammdaten, were columns are fixed but the type might dustin@975: * vary between orte, kategorien, ... raimund@548: */ raimund@548: selectSql: function(element, record) { raimund@548: var filters = element.up('panel[name=main]').down('fieldset[name=filtervariables]'); dustin@979: dustin@979: // Set "Filter Auswahl" Description raimund@548: var desc = element.up('fieldset').down('displayfield[name=description]'); dustin@979: desc.setValue(record[0].data.description); dustin@979: raimund@734: this.displayFields = record[0].data.results; raimund@548: var filterFields = record[0].data.filters; dustin@975: var contentPanel = element.up('panel[name=main]').down('panel[name=contentpanel]'); dustin@975: var queryType = record[0].get('type'); //The type of the query, might be proben, messprogramme, dustin@975: // or a stammdatendtype raimund@548: raimund@734: this.reset(element); raimund@548: dustin@979: contentPanel.removeAll(); //clear the panel: make space for new grids dustin@979: dustin@979: // Set "Filter Auswahl" Columns dustin@979: var columns = element.up('fieldset').down('displayfield[name=columns]'); dustin@979: var columnString = []; dustin@979: for (var i = 0; i < this.displayFields.length; i++) { dustin@979: columnString.push(this.displayFields[i].header); dustin@979: } dustin@979: columns.setValue(columnString.join(', ')); dustin@979: dustin@979: // Setup Columns dustin@979: if (this.displayFields) { dustin@979: this.displayFields.reverse(); dustin@979: } dustin@975: dustin@981: if (queryType == 'probe' || queryType == 'messprogramm') { dustin@979: // Dynamic Grids dustin@979: // We need to set both grid and Store. dustin@975: var frgrid; // The Resultgrid dustin@975: var gridstore; // The Store which will be used in the resultgrid. dustin@975: dustin@975: switch (queryType) { dustin@981: case 'probe': dustin@975: gridstore = Ext.create('Lada.store.ProbenList'); dustin@975: frgrid = Ext.create('Lada.view.grid.ProbeList'); dustin@975: break; dustin@981: case 'messprogramm': dustin@975: gridstore = Ext.create('Lada.store.MessprogrammeList'); dustin@975: frgrid = Ext.create('Lada.view.grid.MessprogrammeList'); dustin@975: break; dustin@975: } dustin@975: dustin@975: if (gridstore) { dustin@975: frgrid.setStore(gridstore); dustin@975: } dustin@975: dustin@975: contentPanel.add(frgrid); raimund@548: } dustin@975: else { dustin@975: // Grids which are not build with dynamic columns dustin@979: // The store is configured in each grid, hence we only need to set the dustin@979: // grid dustin@975: var resultGrid; dustin@975: switch (queryType) { dustin@981: case 'messprogrammkategorie': dustin@975: resultGrid = Ext.create('Lada.view.grid.MessprogrammKategorie'); dustin@975: break; dustin@981: case 'datensatzerzeuger': dustin@975: resultGrid = Ext.create('Lada.view.grid.DatensatzErzeuger'); dustin@975: break; dustin@981: case 'ort': dustin@981: resultGrid = Ext.create('Lada.view.grid.Ort'); dustin@981: break; dustin@981: case 'probenehmer': dustin@981: resultGrid = Ext.create('Lada.view.grid.Probenehmer'); dustin@981: break; dustin@975: } dustin@975: if (resultGrid) { dustin@975: contentPanel.add(resultGrid); dustin@975: } dustin@975: } dustin@975: /* Setup Filters dustin@742: * dustin@742: * Allowed types are dustin@742: * * text dustin@742: * * number dustin@742: * * datetime dustin@742: * * bool dustin@742: * * listmst dustin@742: * * listumw dustin@742: * * listver dustin@742: * * listdbasis dustin@742: * * listnetz dustin@742: * dustin@742: * Iterate over all configured filters and add filters dynamically dustin@742: * dustin@742: * 1. Empty filters dustin@742: */ raimund@548: filters.removeAll(); raimund@548: var hide = true; dustin@742: /* 2. Iterate over all configured filters */ raimund@548: var j; raimund@548: for (j = 0; j < filterFields.length; j++) { raimund@548: var type = filterFields[j].type; raimund@548: var name = filterFields[j].dataIndex; raimund@548: var label = filterFields[j].label; raimund@548: var multi = filterFields[j].multiSelect; raimund@548: var field = null; raimund@548: if (type === 'text') { raimund@548: field = Ext.create('Ext.form.field.Text', { raimund@548: name: name, raimund@548: fieldLabel: label raimund@548: }); raimund@548: } raimund@548: else if (type === 'number') { raimund@548: field = Ext.create('Ext.form.field.Number', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label raimund@548: }); raimund@548: } raimund@548: else if (type === 'datetime') { raimund@575: field = Ext.create('Lada.view.widget.Datetime', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label raimund@548: }); raimund@548: } raimund@548: else if (type === 'bool') { raimund@575: field = Ext.create('Lada.view.widget.Testdatensatz', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, raimund@548: emptyText: '' raimund@548: }); raimund@548: } raimund@548: else if (type === 'listmst') { raimund@575: field = Ext.create('Lada.view.widget.Messstelle', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, raimund@548: multiSelect: multi raimund@548: }); raimund@548: } raimund@548: else if (type === 'listumw') { raimund@575: field = Ext.create('Lada.view.widget.Umwelt', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, dustin@874: multiSelect: multi, dustin@874: displayTpl: Ext.create('Ext.XTemplate', dustin@874: '{id} ') raimund@548: }); raimund@548: } raimund@548: else if (type === 'listdbasis') { raimund@575: field = Ext.create('Lada.view.widget.Datenbasis', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, raimund@548: multiSelect: multi raimund@548: }); raimund@548: } raimund@548: else if (type === 'listver') { raimund@575: field = Ext.create('Lada.view.widget.Verwaltungseinheit', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, raimund@548: multiSelect: multi raimund@548: }); raimund@548: } raimund@548: else if (type === 'listnetz') { raimund@575: field = Ext.create('Lada.view.widget.Netzbetreiber', { raimund@548: name: name, raimund@548: labelWidth: 135, raimund@548: fieldLabel: label, raimund@548: multiSelect: multi raimund@548: }); raimund@548: } raimund@548: if (field) { raimund@548: filters.add(field); raimund@548: filters.show(); raimund@548: hide = false; raimund@548: } raimund@548: } raimund@548: if (hide) { raimund@548: filters.hide(); raimund@548: } raimund@548: }, raimund@548: raimund@548: /** raimund@548: * Function is called when the user clicks the search button. The function raimund@548: * will perform a search to the server on refreshes the result list. dustin@975: * To do so it replaces the store of the Resultgrids. raimund@548: */ raimund@548: search: function(element) { dustin@975: var resultGrid = element.up('panel[name=main]').down('panel[name=contentpanel]').down('grid'); raimund@548: var filters = element.up('panel[name=main]').down('fieldset[name=filtervariables]'); raimund@548: var search = element.up('fieldset').down('combobox[name=filter]'); raimund@548: dustin@975: //Type of the search Proben/Messprogramme/Stammdaten dustin@975: var type = search.store.getById(search.getValue()).get('type') dustin@975: raimund@548: // Get search parameters: raimund@548: var searchParams = {}; raimund@548: searchParams['qid'] = search.getValue(); raimund@548: for (var i = filters.items.length - 1; i >= 0; i--) { raimund@548: var filter = filters.items.items[i]; raimund@548: var value = filter.getValue(); raimund@548: if (value instanceof Array) { raimund@548: value = value.join(','); raimund@548: } raimund@548: searchParams[filter.getName()] = value; raimund@548: } dustin@751: dustin@981: //Store depends of the Type... dustin@981: // TODO the switchcasese should be unified withj those in SelectSql dustin@981: switch (type) { dustin@983: case 'probe': dustin@981: sname = 'Lada.store.ProbenList'; dustin@981: break; dustin@981: case 'messprogramm': dustin@981: sname = 'Lada.store.MessprogrammeList'; dustin@981: break; dustin@981: case 'messprogrammkategorie': dustin@981: sname = 'Lada.store.MessprogrammKategorie'; dustin@981: break; dustin@981: case 'datensatzerzeuger': dustin@981: sname = 'Lada.store.DatensatzErzeuger'; dustin@981: break; dustin@981: case 'ort': dustin@981: sname = 'Lada.store.Ort'; dustin@981: break; dustin@981: case 'probenehmer': dustin@981: sname = 'Lada.store.Probenehmer'; dustin@981: break; dustin@975: } dustin@751: dustin@751: // Find the store or create a new one. dustin@751: var store = Ext.StoreManager.lookup(sname); dustin@751: if (!store) { dustin@751: store = Ext.create(sname); dustin@751: } dustin@751: if (store) { dustin@810: store.addListener('beforeload', this.loadingAnimationOn, resultGrid); dustin@810: store.addListener('load', this.loadingAnimationOff, resultGrid); dustin@976: dustin@751: resultGrid.setStore(store); dustin@976: //TODO: Check if this is still necessary, as a Grid exists dustin@976: // for each Type. dustin@976: dustin@976: if (resultGrid.isDynamic) { dustin@976: //only the dynamic resultgrid can and needs to do the following: dustin@976: resultGrid.setupColumns(this.displayFields); dustin@976: } dustin@976: dustin@751: resultGrid.getStore().proxy.extraParams = searchParams; dustin@751: resultGrid.getStore().load(); dustin@751: resultGrid.show(); dustin@751: } raimund@548: }, dustin@810: dustin@810: /** dustin@810: * Enable the Loading Animation of the Grid. dustin@810: */ dustin@810: loadingAnimationOn: function(store, operation) { dustin@810: // this = resultgrid because of the scope which was set in addListener dustin@810: this.setLoading(true); dustin@810: }, dustin@810: dustin@810: /** dustin@810: * Disable the Loading Animation of the Grid. dustin@810: */ dustin@810: loadingAnimationOff: function(store, operation) { dustin@810: // this = resultgrid because of the scope which was set in addListener dustin@810: this.setLoading(false); dustin@810: }, dustin@810: dustin@742: /** dustin@742: * This function resets the filters dustin@742: */ raimund@734: reset: function(element) { raimund@734: var filters = element.up('panel[name=main]').down('fieldset[name=filtervariables]'); raimund@734: for (var i = filters.items.length - 1; i >= 0; i--) { raimund@734: var filter = filters.items.items[i]; raimund@844: if (filter.clearValue) { raimund@844: filter.clearValue(); raimund@844: } raimund@844: else { raimund@844: filter.setValue(''); raimund@844: } raimund@734: } raimund@548: }, dustin@742: /** dustin@742: * This Function is supposed to handle the About action dustin@742: * It has no function yet. dustin@742: */ raimund@548: about: function() { dustin@800: var win = Ext.create('Lada.view.window.About'); dustin@800: win.show(); raimund@548: } raimund@548: });