annotate app/controller/Sql.js @ 314:65f8be677c8a

Added docstring
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 13 Aug 2013 08:05:32 +0200
parents 92b475303806
children ae1b4c828649
rev   line source
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
1 var queries = new Array('query1', 'query2');
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
2
294
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
3 /**
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
4 * Controller for the Search
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
5 * This controller handles all logic related to the search
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
6 */
6
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
7 Ext.define('Lada.controller.Sql', {
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
8 extend: 'Ext.app.Controller',
8
e4fcb4ddd782 Moved stored SQL into its own file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 6
diff changeset
9 stores: [
235
78134e20e62d Added new model and store for Queries.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 147
diff changeset
10 'Proben', // List of found Proben
78134e20e62d Added new model and store for Queries.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 147
diff changeset
11 'Queries'
8
e4fcb4ddd782 Moved stored SQL into its own file.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 6
diff changeset
12 ],
6
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
13 init: function() {
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
14 console.log('Initialising the Sql controller');
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
15 this.control({
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
16 // CSS like selector to select element in the viewport. See
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17 // ComponentQuery documentation for more details.
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
18 '#search': {
6
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
19 // Map the "render" event to the given function.
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
20 render: this.onPanelRendered,
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
21 // Map Doubleclick on rows of the probenlist.
28
4d60b9ebce15 Renamed sql modul into search. Further display The query selection as Combobox
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 25
diff changeset
22 select: this.selectSql
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
23 },
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
24 '#SearchBtn': {
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
25 // Map click event on Button.
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
26 click: this.search
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
27 },
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
28 '#ResetBtn': {
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
29 // Map click event on Button.
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
30 click: this.reset
6
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
31 }
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
32 });
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
33 },
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
34 onPanelRendered: function() {
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
35 console.log('The panel was rendered');
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
36 },
294
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
37 /**
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
38 * Function called when the user selects a SQL query in the dropdownlist.
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
39 * The function will hide/display additional element related to the
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
40 * selected search query
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
41 */
28
4d60b9ebce15 Renamed sql modul into search. Further display The query selection as Combobox
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 25
diff changeset
42 selectSql: function(element, record, index) {
241
4ca858026191 If the user selects a search query add call setupColumns method to dynamically
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 235
diff changeset
43 var result = Ext.getCmp('result');
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
44 var filters = Ext.getCmp('queryfilters');
252
1bce2d59b7e9 Update description and sql statement when chosing another query
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 251
diff changeset
45 var sqlquery = Ext.getCmp('sqlquery');
1bce2d59b7e9 Update description and sql statement when chosing another query
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 251
diff changeset
46 var sqldesc = Ext.getCmp('sqldesc');
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
47 var buttons = Ext.getCmp('SearchBtnPanel');
253
424f18da3c64 Fixed variable name
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 252
diff changeset
48 var displayFields = record[0].data.results;
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
49 var filterFields = record[0].data.filters;
253
424f18da3c64 Fixed variable name
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 252
diff changeset
50
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
51 this.reset();
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
52
252
1bce2d59b7e9 Update description and sql statement when chosing another query
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 251
diff changeset
53 sqlquery.setValue(record[0].data.sql);
1bce2d59b7e9 Update description and sql statement when chosing another query
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 251
diff changeset
54 sqldesc.setValue(record[0].data.description);
1bce2d59b7e9 Update description and sql statement when chosing another query
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 251
diff changeset
55
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
56 // Setup Columns of the probenlist
241
4ca858026191 If the user selects a search query add call setupColumns method to dynamically
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 235
diff changeset
57 result.setupColumns(displayFields);
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
58
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
59 // Setup Columns of the probenlist
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
60 if (filterFields.length > 0) {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
61 var items = filters.items.items;
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
62 for (var i=0; i < items.length; i++) {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
63 var filtername = items[i].id;
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
64 items[i].hide();
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
65 for (var j=0; j < filterFields.length; j++) {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
66 if ('filter-'+filterFields[j] === filtername) {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
67 items[i].show();
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
68 };
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
69 };
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
70
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
71 };
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
72 filters.show();
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
73 } else {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
74 filters.hide();
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
75 };
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
76 buttons.show();
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
77 },
294
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
78 /**
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
79 * Function is called when the user clicks the search button. The function
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
80 * will perform a search to the server on refreshes the result list.
92b475303806 Inherit from Base controller
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 253
diff changeset
81 */
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
82 search: function(element, record, index) {
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
83 var result = Ext.getCmp('result');
28
4d60b9ebce15 Renamed sql modul into search. Further display The query selection as Combobox
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 25
diff changeset
84 console.log('Loading store');
36
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
85
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
86 // Get search parameters:
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
87 var searchParams = {};
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
88 if (Ext.getCmp('search').getValue() == 1) {
251
d79b3bab600c Fixed filter names
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 246
diff changeset
89 var mst = Ext.getCmp('filter-mstId').getValue();
d79b3bab600c Fixed filter names
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 246
diff changeset
90 var uwb = Ext.getCmp('filter-umwId').getValue();
96
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
91 if (mst !== null) {
139
df6e36dd57ee Changed params probe -> probeId, mst -> mstId, uwb -> umwId
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 120
diff changeset
92 searchParams['mstId'] = mst;
96
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
93 }
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
94 if (uwb !== null) {
139
df6e36dd57ee Changed params probe -> probeId, mst -> mstId, uwb -> umwId
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 120
diff changeset
95 searchParams['umwId'] = uwb;
96
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
96 }
36
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
97 } else {
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
98 // Get date object an convert it into a timestamp (ms since epoch)
251
d79b3bab600c Fixed filter names
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 246
diff changeset
99 var datefield = Ext.getCmp('filter-pbegin').getValue();
97
9a549ca6e664 Only getTimte from datefield if the value is not null.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 96
diff changeset
100 if (datefield !== null) {
251
d79b3bab600c Fixed filter names
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 246
diff changeset
101 var ts = Ext.getCmp('filter-pbegin').getValue().getTime();
96
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
102 searchParams['begin'] = ts;
ecb0c0cf386b Only add search params if the user actually set them in the form.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 36
diff changeset
103 }
36
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
104 }
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
105 result.getStore().load({
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
106 params: searchParams
2a67e062519b Implemted search. When user clicks on the search buttons parameters are
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 35
diff changeset
107 });
28
4d60b9ebce15 Renamed sql modul into search. Further display The query selection as Combobox
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 25
diff changeset
108 console.log('Store loaded');
25
f964a50bfe57 Restructured the application. Fixed layouts etc.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 17
diff changeset
109 result.show();
31
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
110 },
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
111 reset: function(element, record, index) {
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
112 var buttons = Ext.getCmp('SearchBtnPanel');
897e3100c6da Changed logic of the Probenauswahl. Now logic works like the BFS version.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 28
diff changeset
113 var result = Ext.getCmp('result');
246
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
114 //for (var i = 0; i < queries.length; ++i) {
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
115 // var toHide = Ext.getCmp(queries[i]);
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
116 // toHide.hide();
c5d7fae5997a Change logic how to show and hide the search filters. Now we iterate over the
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
117 //}
147
5da0b56bf9bf Do no hide the earch buttons and the resultlist on reset.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 139
diff changeset
118 //result.hide();
5da0b56bf9bf Do no hide the earch buttons and the resultlist on reset.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 139
diff changeset
119 //buttons.hide();
6
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
120 }
8e79bda4d55b Added a list to select predefined SQL Statement for the Proben list.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
121 });

http://lada.wald.intevation.org