1 | /** |
---|
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
---|
3 | * |
---|
4 | * Published under the BSD license. |
---|
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
6 | * of the license. |
---|
7 | */ |
---|
8 | |
---|
9 | /** api: example[search-form] |
---|
10 | * Filter Form Panel |
---|
11 | * ----------------- |
---|
12 | * Use a form to build an OpenLayers filter. |
---|
13 | */ |
---|
14 | |
---|
15 | var formPanel; |
---|
16 | |
---|
17 | Ext.onReady(function() { |
---|
18 | |
---|
19 | // create a protocol, this protocol is used by the form |
---|
20 | // to send the search request, this protocol's read |
---|
21 | // method received an OpenLayers.Filter instance, |
---|
22 | // which is derived from the content of the form |
---|
23 | var protocol = new OpenLayers.Protocol({ |
---|
24 | read: function(options) { |
---|
25 | var f; html = []; |
---|
26 | |
---|
27 | f = options.filter; |
---|
28 | html.push([f.CLASS_NAME, ",", f.type, "<br />"].join(" ")); |
---|
29 | |
---|
30 | f = options.filter.filters[0]; |
---|
31 | html.push([f.CLASS_NAME, ",", f.type, ",", |
---|
32 | f.property, ":", f.value, "<br />"].join(" ")); |
---|
33 | |
---|
34 | f = options.filter.filters[1]; |
---|
35 | html.push([f.CLASS_NAME, ",", f.type, ", ", |
---|
36 | f.property, ": ", f.value].join(" ")); |
---|
37 | |
---|
38 | Ext.get("filter").update(html.join("")); |
---|
39 | |
---|
40 | } |
---|
41 | }); |
---|
42 | |
---|
43 | // create a GeoExt form panel (configured with an OpenLayers.Protocol |
---|
44 | // instance) |
---|
45 | formPanel = new GeoExt.form.FormPanel({ |
---|
46 | width: 300, |
---|
47 | height: 200, |
---|
48 | protocol: protocol, |
---|
49 | items: [{ |
---|
50 | xtype: "textfield", |
---|
51 | name: "name__like", |
---|
52 | value: "foo", |
---|
53 | fieldLabel: "name" |
---|
54 | }, { |
---|
55 | xtype: "textfield", |
---|
56 | name: "elevation__ge", |
---|
57 | value: "1200", |
---|
58 | fieldLabel: "maximum elevation" |
---|
59 | }], |
---|
60 | listeners: { |
---|
61 | actioncomplete: function(form, action) { |
---|
62 | // this listener triggers when the search request |
---|
63 | // is complete, the OpenLayers.Protocol.Response |
---|
64 | // resulting from the request is available |
---|
65 | // through "action.response" |
---|
66 | } |
---|
67 | } |
---|
68 | }); |
---|
69 | |
---|
70 | formPanel.addButton({ |
---|
71 | text: "search", |
---|
72 | handler: function() { |
---|
73 | // trigger search request, the options passed to doAction |
---|
74 | // are passed to the protocol's read method, so one |
---|
75 | // can register a read callback here |
---|
76 | var o = { |
---|
77 | callback: function(response) { |
---|
78 | } |
---|
79 | }; |
---|
80 | this.search(o); |
---|
81 | }, |
---|
82 | scope: formPanel |
---|
83 | }); |
---|
84 | |
---|
85 | formPanel.render("formpanel"); |
---|
86 | }); |
---|