comparison app/controller/Sql.js @ 369:cebed9ef8293

Dynamically add configured search filters. Send needed values to the server.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 16 Aug 2013 12:20:51 +0200
parents 71ca7e597952
children 1179b3a1251b
comparison
equal deleted inserted replaced
368:cec9fe8d0000 369:cebed9ef8293
7 Ext.define('Lada.controller.Sql', { 7 Ext.define('Lada.controller.Sql', {
8 extend: 'Ext.app.Controller', 8 extend: 'Ext.app.Controller',
9 stores: [ 9 stores: [
10 'Proben', // List of found Proben 10 'Proben', // List of found Proben
11 'Queries' 11 'Queries'
12 ],
13 requires: [
14 'Lada.view.widgets.Mst',
15 'Lada.view.widgets.Uwb',
16 'Lada.view.widgets.Datetime'
12 ], 17 ],
13 init: function() { 18 init: function() {
14 console.log('Initialising the Sql controller'); 19 console.log('Initialising the Sql controller');
15 this.control({ 20 this.control({
16 // CSS like selector to select element in the viewport. See 21 // CSS like selector to select element in the viewport. See
54 sqldesc.setValue(record[0].data.description); 59 sqldesc.setValue(record[0].data.description);
55 60
56 // Setup Columns of the probenlist 61 // Setup Columns of the probenlist
57 result.setupColumns(displayFields); 62 result.setupColumns(displayFields);
58 63
59 // Setup Columns of the probenlist 64 // Setup Filters of the probenlist
60 if (filterFields.length > 0) { 65 //
61 var items = filters.items.items; 66 // Allowed types are
62 for (var i=0; i < items.length; i++) { 67 // * text
63 var filtername = items[i].id; 68 // * number
64 items[i].hide(); 69 // * datetime
65 for (var j=0; j < filterFields.length; j++) { 70 // * listmst
66 if ('filter-'+filterFields[j].dataIndex === filtername) { 71 // * listumw
67 items[i].show(); 72 //
68 } 73 // Iterate over all configured filters and add filters dynamically
69 } 74 //
75 // 1. Empty filters
76 filters.removeAll();
77 var hide = true;
78 // 2. Iterate over all configured filters
79 for (var j=0; j < filterFields.length; j++) {
80 var type = filterFields[j].type;
81 var name = filterFields[j].dataIndex;
82 var label = filterFields[j].label;
83 var field = null;
84 if (type == "text") {
85 console.log("Found text filter");
86 field = Ext.create('Ext.form.field.Text', { name: name, fieldLabel: label });
87 } else if (type == "number") {
88 console.log("Found number filter");
89 field = Ext.create('Ext.form.field.Number', { name: name, fieldLabel: label });
90 } else if (type == "datetime") {
91 console.log("Found datetime filter");
92 field = Ext.create('Lada.view.widgets.Datetime', { name: name, fieldLabel: label });
93 } else if (type == "listmst") {
94 console.log("Found listmst filter");
95 field = Ext.create('Lada.view.widgets.Mst', { name: name, fieldLabel: label });
96 } else if (type == "listumw") {
97 console.log("Found listumw filter");
98 field = Ext.create('Lada.view.widgets.Uwb', { name: name, fieldLabel: label });
70 } 99 }
71 filters.show(); 100 if (field) {
72 } else { 101 console.log("Pushing field to filters");
102 filters.add(field);
103 filters.show();
104 hide = false;
105 }
106 }
107 if (hide) {
73 filters.hide(); 108 filters.hide();
74 }; 109 }
75 buttons.show(); 110 buttons.show();
76 }, 111 },
77 /** 112 /**
78 * Function is called when the user clicks the search button. The function 113 * Function is called when the user clicks the search button. The function
79 * will perform a search to the server on refreshes the result list. 114 * will perform a search to the server on refreshes the result list.
80 */ 115 */
81 search: function(element, record, index) { 116 search: function(element, record, index) {
82 var result = Ext.getCmp('result'); 117 var result = Ext.getCmp('result');
83 console.log('Loading store'); 118 var filters = Ext.getCmp('queryfilters');
119 var search = Ext.getCmp('search');
84 120
85 // Get search parameters: 121 // Get search parameters:
86 var searchParams = {}; 122 var searchParams = {};
87 if (Ext.getCmp('search').getValue() == 1) { 123 searchParams['qid'] = search.getValue();
88 var mst = Ext.getCmp('filter-mstId').getValue(); 124 for (var i = filters.items.length - 1; i >= 0; i--){
89 var uwb = Ext.getCmp('filter-umwId').getValue(); 125 var filter = filters.items.items[i];
90 if (mst !== null) { 126 var value = filter.getValue();
91 searchParams['mstId'] = mst; 127 if (value) {
92 } 128 searchParams[filter.getName()] = filter.getValue();
93 if (uwb !== null) {
94 searchParams['umwId'] = uwb;
95 }
96 } else {
97 // Get date object an convert it into a timestamp (ms since epoch)
98 var datefield = Ext.getCmp('filter-pbegin').getValue();
99 if (datefield !== null) {
100 var ts = Ext.getCmp('filter-pbegin').getValue().getTime();
101 searchParams['begin'] = ts;
102 } 129 }
103 } 130 }
131 console.log('Loading store with the following search params: ' + searchParams);
104 result.getStore().load({ 132 result.getStore().load({
105 params: searchParams 133 params: searchParams
106 }); 134 });
107 console.log('Store loaded'); 135 console.log('Store loaded');
108 result.show(); 136 result.show();

http://lada.wald.intevation.org