[Commits] r2503 - in sandbox/borealis: . geoext.ux geoext.ux/ux geoext.ux/ux/AttributeFilterPanel geoext.ux/ux/AttributeFilterPanel/examples geoext.ux/ux/AttributeFilterPanel/lib geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel
commits at geoext.org
commits at geoext.org
Mon Nov 29 20:28:43 CET 2010
Author: edube
Date: 2010-11-29 20:28:43 +0100 (Mon, 29 Nov 2010)
New Revision: 2503
Added:
sandbox/borealis/geoext.ux/
sandbox/borealis/geoext.ux/ux/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.html
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/geobidule.json
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/SingleFile.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterBasicForm.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FilterAction.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FormToFilter.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/ResetAction.js
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/resources/
sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/tests/
Log:
Initial commit of AttributeFilterPanel example in borealis sandbox
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.html
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.html (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.html 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,48 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>GeoExt Attribute Filter Panel</title>
+
+
+
+ <script type="text/javascript" src="http://dev.geoext.org/trunk/ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="http://dev.geoext.org/trunk/ext/ext-all.js"></script>
+ <link rel="stylesheet" type="text/css" href="http://dev.geoext.org/trunk/ext/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://dev.geoext.org/trunk/ext/examples/shared/examples.css" />
+
+ <script type="text/javascript" src="http://dev.geoext.org/trunk/openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="http://dev.geoext.org/trunk/geoext/lib/GeoExt.js"></script>
+
+ <!--
+ <script type="text/javascript" src="../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../ext/ext-all.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../../ext/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="../../../../ext/examples/shared/examples.css" />
+
+ <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../geoext/lib/GeoExt.js"></script>
+ -->
+
+ <!--<link rel="stylesheet" type="text/css" href="../resources/css/LayerTreeBuilder.css" />-->
+ <script type="text/javascript" src="../lib/GeoExt.ux/SingleFile.js"></script>
+ <!--<script type="text/javascript" src="../resources/lang/fr.js"></script>-->
+ <script type="text/javascript" src="attributefilterpanel.js"></script>
+ </head>
+ <body>
+ <div id="desc">
+ <h1>GeoExt Attribute Filter Panel</h1>
+
+ <p></p>
+
+ <p>The js is not minified so it is readable. See
+ <a href="attributefilterpanel.js">attributefilterpanel.js</a>.</p>
+
+ <p>See also the source code of the widget
+ <a href="../lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js">
+ ../lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js</a>.</p>
+
+ <p>
+ The widget is not fully completed.
+ </p>
+ </div>
+ </body>
+</html>
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/attributefilterpanel.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,208 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+ /** api: example[attribute filter panel]
+ * Attribute Filter Panel
+ * ----------------------
+ * ...
+ */
+
+var map, mapPanel;
+
+Ext.onReady(function() {
+
+ var layers = [];
+
+ // base WMS layer
+ layers.push(new OpenLayers.Layer.WMS("OpenLayers WMS",
+ "http://tilecache.osgeo.org/wms-c/Basic.py",
+ {layers: "basic"}
+ ));
+
+ /*
+ var vecLayer = new OpenLayers.Layer.GML(
+ "geobidule",
+ "geobidule.json",
+ { format: OpenLayers.Format.GeoJSON }
+ );
+ */
+
+ var filterStrategy = new OpenLayers.Strategy.Filter();
+
+ var vecLayer = (
+ new OpenLayers.Layer.Vector(
+ "geobidule",
+ {
+ strategies: [
+ new OpenLayers.Strategy.Fixed(),
+ filterStrategy
+ ],
+ protocol: new OpenLayers.Protocol.HTTP({
+ url: "geobidule.json",
+ format: new OpenLayers.Format.GeoJSON()
+ }),
+ filter: null
+ }
+ )
+ );
+
+ layers.push(vecLayer);
+
+ // HACK: since setting the layer's filter has no effect when
+ // using a simple GeoJSON file (no server-side filtering is done),
+ // we use an OpenLayers.Strategy.Filter to filter the features
+ // client-side; this event handler ensures that the strategy's filter
+ // is updated when the layer's filter is.
+ vecLayer.events.register("refresh", null, function() {
+ filterStrategy.setFilter(vecLayer.filter);
+ });
+
+ map = new OpenLayers.Map({
+ projection: new OpenLayers.Projection("EPSG:4326")
+ });
+
+ mapPanel = new GeoExt.MapPanel({
+ region: "center",
+ center: [-72.172623, 45.280564],
+ zoom: 8,
+ map: map
+ });
+
+ map.addLayers(layers);
+
+ var filterPanel = new GeoExt.ux.form.AttributeFilterPanel({
+ layer: vecLayer,
+ title: "Attribute Filter Panel",
+ labelAlign: 'top',
+ items: [
+ {
+ xtype: "textfield",
+ name: "name__like",
+ fieldLabel: "Name is like"
+ },
+ {
+ xtype: "textfield",
+ name: "color__eq",
+ fieldLabel: "Color equals"
+ },
+ {
+ xtype: "textfield",
+ name: "price__ge",
+ fieldLabel: "Price is greater than"
+ },
+ {
+ xtype: "textfield",
+ name: "name__lte",
+ fieldLabel: "Size is less than or equal"
+ },
+ {
+ xtype: "datefield",
+ name: "construction_date__gte",
+ fieldLabel: "Construction_date is greater than or equal",
+ format: "Y-m-d"
+ }
+ ],
+ region: "east",
+ width: 300
+ });
+
+ filterPanel.addButton({
+ // TODO: make buttons' text configurable (i18n)
+ text: "Filter",
+ handler: function() {
+ // trigger filter request, the options passed to doAction
+ // are passed to the protocol's read method, so one
+ // can register a read callback here
+ var o = {
+ callback: function(response) {
+ },
+ logicalOp: "&&",
+ ignoreEmptyFields: true
+ };
+ this.filter(o);
+ },
+ scope: filterPanel
+ });
+ filterPanel.addButton({
+ // TODO: make buttons' text configurable (i18n)
+ text: "Reset",
+ handler: function() {
+ var o = {
+ callback: function(response) {
+ },
+ formPanel: filterPanel
+ };
+ this.reset(o);
+ },
+ scope: filterPanel
+ });
+
+
+ // bind the layer to a FeatureStore so its feature attributes
+ // can be displayed in a grid panel
+ /*
+ // FIXME: store is not synchronized with the layer features... why?
+ var vecStore = new GeoExt.data.FeatureStore({
+ layer: vecLayer,
+ fields: [
+ {name: 'name', type: 'string'},
+ {name: 'color', type: 'string'},
+ {name: 'size', type: 'string'},
+ {name: 'price', type: 'string'},
+ {name: 'construction_date', type: Ext.data.Types.DATE, dateFormat: 'Y-m-d'}
+ ]
+ });
+
+ var gridPanel = new Ext.grid.GridPanel({
+ title: "Feature Grid",
+ region: "south",
+ store: vecStore,
+ height: 150,
+ columns: [{
+ header: "name",
+ width: 200,
+ dataIndex: "name"
+ }, {
+ header: "color",
+ width: 100,
+ dataIndex: "color"
+ }, {
+ header: "size",
+ width: 100,
+ dataIndex: "size"
+ }, {
+ header: "price",
+ width: 100,
+ dataIndex: "price"
+ }, {
+ header: "construction_date",
+ width: 200,
+ dataIndex: "construction_date"
+ }],
+ sm: new GeoExt.grid.FeatureSelectionModel()
+ });
+ */
+
+ new Ext.Viewport({
+ layout: "fit",
+ hideBorders: true,
+ items: {
+ layout: "border",
+ items: [
+ mapPanel, filterPanel, /* gridPanel, */ {
+ contentEl: "desc",
+ region: "west",
+ width: 250,
+ bodyStyle: {padding: "5px"}
+ }
+ ]
+ }
+ });
+
+ //map.setCenter(new OpenLayers.LonLat(-7924121.1710935, 6185868.5449234), 6);
+});
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/geobidule.json
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/geobidule.json (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/examples/geobidule.json 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1 @@
+{"crs": null, "type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-71.9561505836, 45.6129294045]}, "type": "Feature", "id": 23, "properties": {"name": "Bob Gratton", "price": 2334, "color": "red", "construction_date": "1980-07-23", "size": 2.5}}, {"geometry": {"type": "Point", "coordinates": [-71.1755226626, 46.1306839301]}, "type": "Feature", "id": 24, "properties": {"name": "Toto Machin", "price": 2313, "color": "green", "construction_date": "1984-08-22", "size": 5.2}}, {"geometry": {"type": "Point", "coordinates": [-72.9003156124, 46.2757592319]}, "type": "Feature", "id": 25, "properties": {"name": "Alice Lamalice", "price": 1912, "color": "blue", "construction_date": "1971-03-16", "size": 10.7}}, {"geometry": {"type": "Point", "coordinates": [-73.1095453549, 44.4364318856]}, "type": "Feature", "id": 26, "properties": {"name": "Armand Lamothe", "price": 9241, "color": "yellow", "construction_date": "1950-02-11", "size": 1.2}}, {"geometry": {"type": "Point", "coordinates": [-73.0657756207, 45.5125328935]}, "type": "Feature", "id": 27, "properties": {"name": "Frank Carrel", "price": 213, "color": "red", "construction_date": "1981-09-04", "size": 0.5}}, {"geometry": {"type": "Point", "coordinates": [-71.3910524585, 44.2978731619]}, "type": "Feature", "id": 28, "properties": {"name": "Colonel Sanders", "price": 24912, "color": "purple", "construction_date": "1923-11-21", "size": 6.3}}, {"geometry": {"type": "Point", "coordinates": [-71.7589364016, 45.945727037]}, "type": "Feature", "id": 29, "properties": {"name": "Jack Bauer", "price": 23, "color": "black", "construction_date": "1965-01-01", "size": 99.2}}, {"geometry": {"type": "Point", "coordinates": [-71.1898401754, 44.8249095886]}, "type": "Feature", "id": 30, "properties": {"name": "La Sagouine", "price": 8523, "color": "orange", "construction_date": "1901-01-14", "size": 6.4}}, {"geometry": {"type": "Point", "coordinates": [-72.7055073798, 44.4473620026]}, "type": "Feature", "id": 31, "properties": {"name": "Madrid Bigfoot", "price": 6421, "color": "green", "construction_date": "1975-04-21", "size": 9.9}}, {"geometry": {"type": "Point", "coordinates": [-71.4124166605, 44.6162838058]}, "type": "Feature", "id": 32, "properties": {"name": "Johnny Pizza", "price": 2141, "color": "green", "construction_date": "1995-08-01", "size": 4.6}}, {"geometry": {"type": "Point", "coordinates": [-72.8429504676, 46.1789955523]}, "type": "Feature", "id": 33, "properties": {"name": "Bonhomme Carnaval", "price": 2148, "color": "white", "construction_date": "1977-08-11", "size": 0.2}}, {"geometry": {"type": "Point", "coordinates": [-72.3014895692, 46.0800689625]}, "type": "Feature", "id": 34, "properties": {"name": "Yvette Clotilde", "price": 2441, "color": "blue", "construction_date": "1960-01-25", "size": 1.5}}, {"geometry": {"type": "Point", "coordinates": [-71.799940458, 46.114336805]}, "type": "Feature", "id": 35, "properties": {"name": "Tony Saputo", "price": 8523, "color": "yellow", "construction_date": "1985-06-13", "size": 2.1}}, {"geometry": {"type": "Point", "coordinates": [-71.4885107067, 44.7216382687]}, "type": "Feature", "id": 36, "properties": {"name": "Jimmy Hendrix", "price": 6241, "color": "purple", "construction_date": "1970-01-17", "size": 0.6}}, {"geometry": {"type": "Point", "coordinates": [-72.3210482569, 44.5409778635]}, "type": "Feature", "id": 37, "properties": {"name": "Harry Potter", "price": 2334, "color": "blue", "construction_date": "2004-08-12", "size": 2.5}}, {"geometry": {"type": "Point", "coordinates": [-71.6504135587, 44.2994600204]}, "type": "Feature", "id": 38, "properties": {"name": "Tim Hortons", "price": 2311, "color": "brown", "construction_date": "1995-06-21", "size": 1.8}}, {"geometry": {"type": "Point", "coordinates": [-71.8344232665, 45.3771141091]}, "type": "Feature", "id": 39, "properties": {"name": "Mr Bubble", "price": 8215, "color": "blue", "construction_date": "1984-07-23", "size": 1.7}}, {"geometry": {"type": "Point", "coordinates": [-72.1955028605, 44.6990238387]}, "type": "Feature", "id": 40, "properties": {"name": "Yop Solo", "price": 24881, "color": "black", "construction_date": "1977-06-29", "size": 4.5}}, {"geometry": {"type": "Point", "coordinates": [-72.398226189, 46.2085605529]}, "type": "Feature", "id": 41, "properties": {"name": "Plum Puddings", "price": 2211, "color": "purple", "construction_date": "1980-07-23", "size": 21.5}}, {"geometry": {"type": "Point", "coordinates": [-71.2893144031, 46.2130780487]}, "type": "Feature", "id": 42, "properties": {"name": "Jelly Beans", "price": 1211, "color": "red", "construction_date": "1983-05-05", "size": 6.5}}]}
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/SingleFile.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/SingleFile.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/SingleFile.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,84 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+/*
+ * The code in this file is based on code taken from OpenLayers.
+ *
+ * Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD
+ * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license.
+ */
+
+(function() {
+
+ /**
+ * The relative path of this script.
+ */
+ var scriptName = "lib/GeoExt.ux/SingleFile.js";
+
+ /**
+ * Function returning the path of this script.
+ */
+ var getScriptLocation = function() {
+ var scriptLocation = "";
+ // If we load other scripts right before GeoExt using the same
+ // mechanism to add script resources dynamically (e.g. OpenLayers),
+ // document.getElementsByTagName will not find the GeoExt script tag
+ // in FF2. Using document.documentElement.getElementsByTagName instead
+ // works around this issue.
+ var scripts = document.documentElement.getElementsByTagName('script');
+ for(var i=0, len=scripts.length; i<len; i++) {
+ var src = scripts[i].getAttribute('src');
+ if(src) {
+ var index = src.lastIndexOf(scriptName);
+ // set path length for src up to a query string
+ var pathLength = src.lastIndexOf('?');
+ if(pathLength < 0) {
+ pathLength = src.length;
+ }
+ // is it found, at the end of the URL?
+ if((index > -1) && (index + scriptName.length == pathLength)) {
+ scriptLocation = src.slice(0, pathLength - scriptName.length);
+ break;
+ }
+ }
+ }
+ return scriptLocation;
+ };
+
+ var jsfiles = new Array(
+ "widgets/attributefilterpanel/AttributeFilterBasicForm.js",
+ "widgets/attributefilterpanel/AttributeFilterPanel.js",
+ "widgets/attributefilterpanel/FormToFilter.js",
+ "widgets/attributefilterpanel/FilterAction.js",
+ "widgets/attributefilterpanel/ResetAction.js"
+ );
+
+ var agent = navigator.userAgent;
+ var docWrite = (agent.match("MSIE") || agent.match("Safari"));
+ if(docWrite) {
+ var allScriptTags = new Array(jsfiles.length);
+ }
+ var host = getScriptLocation() + "lib/GeoExt.ux/";
+ for (var i=0, len=jsfiles.length; i<len; i++) {
+ if (docWrite) {
+ allScriptTags[i] = "<script src='" + host + jsfiles[i] +
+ "'></script>";
+ } else {
+ var s = document.createElement("script");
+ s.src = host + jsfiles[i];
+ var h = document.getElementsByTagName("head").length ?
+ document.getElementsByTagName("head")[0] :
+ document.body;
+ h.appendChild(s);
+ }
+ }
+ if (docWrite) {
+ document.write(allScriptTags.join(""));
+ }
+})();
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterBasicForm.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterBasicForm.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterBasicForm.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,90 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+/**
+ * @include GeoExt/ux/widgets/form/FilterAction.js
+ * @include GeoExt/ux/widgets/form/ResetAction.js
+ */
+
+/** api: (define)
+ * module = GeoExt.ux.form
+ * class = AttributeFilterBasicForm
+ * base_link = `Ext.form.BasicForm <http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.BasicForm>`_
+ */
+
+Ext.namespace("GeoExt.ux.form");
+
+/** api: constructor
+ * .. class:: AttributeFilterBasicForm(config)
+ *
+ * A specific ``Ext.form.BasicForm`` whose doAction method creates
+ * a :class:`GeoExt.ux.form.FilterAction` if it is passed the string
+ * "filter" as its first argument.
+ *
+ * In most cases one would not use this class directly, but
+ * :class:`GeoExt.ux.form.AttributeFilterPanel` instead.
+ */
+GeoExt.ux.form.AttributeFilterBasicForm = Ext.extend(Ext.form.BasicForm, {
+
+ /** api: config[layer]
+ * ``OpenLayers.Layer.Vector`` The vector layer to apply a filter to
+ */
+ layer: null,
+
+ /** api: method[doAction]
+ * :param action: ``String or Ext.form.Action`` Either the name
+ * of the action or a ``Ext.form.Action`` instance.
+ * :param options: ``Object`` The options passed to the Action
+ * constructor.
+ * :return: :class:`GeoExt.ux.form.AttributeFilterBasicForm` This form.
+ *
+ * Performs the action, if the string "filter" is passed as the
+ * first argument then a :class:`GeoExt.ux.form.FilterAction` is created.
+ * If the string "reset" is passed, then a
+ * :class:`GeoExt.ux.form.ResetAction` is created.
+ */
+ doAction: function(action, options) {
+ if(action == "filter") {
+ options = Ext.applyIf(options || {}, {
+ layer: this.layer
+ });
+ action = new GeoExt.ux.form.FilterAction(this, options);
+ }
+ if(action == "reset") {
+ options = Ext.applyIf(options || {}, {
+ layer: this.layer
+ });
+ action = new GeoExt.ux.form.ResetAction(this, options);
+ }
+ return GeoExt.form.BasicForm.superclass.doAction.call(
+ this, action, options
+ );
+ },
+
+ /** api: method[filter]
+ * :param options: ``Object`` The options passed to the Action
+ * constructor.
+ * :return: :class:`GeoExt.ux.form.AttributeFilterBasicForm` This form.
+ *
+ * Shortcut to do a filter action.
+ */
+ filter: function(options) {
+ return this.doAction("filter", options);
+ },
+
+ /** api: method[reset]
+ * :param options: ``Object`` The options passed to the Action
+ * constructor.
+ * :return: :class:`GeoExt.ux.form.AttributeFilterBasicForm` This form.
+ *
+ * Shortcut to do a reset action.
+ */
+ reset: function(options) {
+ return this.doAction("reset", options);
+ }
+});
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/AttributeFilterPanel.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,101 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+/** api: (define)
+ * module = GeoExt.ux.form
+ * class = AttributeFilterPanel
+ * base_link = `Ext.form.FormPanel <http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.FormPanel>`_
+ */
+
+/**
+ * @include GeoExt/ux/widgets/form/AttributeFilterBasicForm.js
+ */
+
+Ext.namespace("GeoExt.ux.form");
+
+/** api: example
+ * Sample code showing how to use a GeoExt ux attribute filter panel.
+ *
+ * .. code-block:: javascript
+ *
+ * var filterPanel = new GeoExt.ux.form.AttributeFilterPanel({
+ * renderTo: "filterpanel",
+ * layer: myVectorLayer, // vector layer to apply the filter on
+ * items: [{
+ * xtype: "textfield",
+ * name: "name__ilike",
+ * fieldLabel: "Mountain name",
+ *
+ * }, {
+ * xtype: "textfield",
+ * name: "elevation__ge",
+ * value: "2000"
+ * }]
+ * });
+ *
+ * formPanel.addButton({
+ * text: "filter",
+ * handler: function() {
+ * this.filter();
+ * },
+ * scope: filterPanel
+ * });
+ */
+
+/** api: constructor
+ * .. class:: FormPanel(config)
+ *
+ * A specific ``Ext.form.FormPanel`` whose internal form is a
+ * :class:`GeoExt.ux.form.AttributeFilterBasicForm` instead of
+ * ``Ext.form.BasicForm``.
+ * One would use this form to apply attribute filters on a
+ * vector layer (``OpenLayers.Layer.Vector``).
+ *
+ * Look at :class:`GeoExt.ux.form.FormToFilter` to understand how
+ * form fields must be named for appropriate filters to be
+ * passed to the layer.
+ */
+GeoExt.ux.form.AttributeFilterPanel = Ext.extend(Ext.form.FormPanel, {
+
+ /** api: config[layer]
+ * ``OpenLayers.Layer.Vector`` The vector layer to apply the filter to
+ */
+ layer: null,
+
+ /** private: method[createForm]
+ * Create the internal :class:`GeoExt.ux.form.AttributeFilterBasicForm`
+ * instance.
+ */
+ createForm: function() {
+ delete this.initialConfig.listeners;
+ return new GeoExt.ux.form.AttributeFilterBasicForm(null, this.initialConfig);
+ },
+
+ /** api: method[filter]
+ * :param options: ``Object`` The options passed to the
+ * :class:`GeoExt.ux.form.FilterAction` constructor.
+ *
+ * Shortcut to the internal form's filter method.
+ */
+ filter: function(options) {
+ this.getForm().filter(options);
+ },
+
+ /** api: method[reset]
+ * :param options: ``Object`` The options passed to the
+ * :class:`GeoExt.ux.form.ResetAction` constructor.
+ *
+ * Shortcut to the internal form's reset method.
+ */
+ reset: function(options) {
+ this.getForm().reset(options);
+ }
+});
+
+/** api: xtype = gxux_attributefilterpanel */
+Ext.reg("gxux_attributefilterpanel", GeoExt.ux.form.AttributeFilterPanel);
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FilterAction.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FilterAction.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FilterAction.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace("GeoExt.ux.form");
+
+
+GeoExt.ux.form.FilterAction = Ext.extend(Ext.form.Action, {
+ /** private: property[type]
+ * ``String`` The action type string.
+ */
+ type: "filter",
+
+ /** api: property[formToFilter]
+ * ``GeoExt.ux.form.FormToFilter`` object that defines the mapping
+ * from the Form contents to the Filter object (by calling its toFilter()
+ * method).
+ * Defaults to an instance of GeoExt.ux.form.FormToFilter with
+ * the default options.
+ */
+ formToFilter: new GeoExt.ux.form.FormToFilter(),
+
+ /** private
+ * (used by ``GeoExt.ux.form.AttributeFilterBasicForm``)
+ */
+ constructor: function(form, options) {
+ Ext.apply(this, options);
+ GeoExt.ux.form.FilterAction.superclass.constructor.call(this, form, options);
+ },
+
+ /** private: method[run]
+ * Run the action.
+ */
+ run: function() {
+ var o = this.options;
+ var f = this.formToFilter.toFilter(this.form, o.logicalOp, o.wildcard);
+ if(o.clientValidation === false || this.form.isValid()){
+
+ if (o.layer) {
+ o.layer.filter = f;
+ o.layer.refresh({force: true});
+ }
+
+ } else if(o.clientValidation !== false){
+ // client validation failed
+ this.failureType = Ext.form.Action.CLIENT_INVALID;
+ this.form.afterAction(this, false);
+ }
+ }
+
+});
+
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FormToFilter.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FormToFilter.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/FormToFilter.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,212 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace("GeoExt.ux.form");
+
+GeoExt.ux.form.FormToFilter = function (options) {
+ if (!options) {
+ options = {};
+ }
+
+ this.ignoreEmptyFields = options.ignoreEmptyFields || true;
+
+ return this;
+};
+
+/** private: function[toFilter]
+ * :param form: ``Ext.form.BasicForm|Ext.form.FormPanel``
+ * :param logicalOp: ``String`` Either ``OpenLayers.Filter.Logical.AND`` or
+ * ``OpenLayers.Filter.Logical.OR``, set to
+ * ``OpenLayers.Filter.Logical.AND`` if null or undefined
+ * :param wildcard: ``Integer`` Determines the wildcard behaviour of like
+ * queries. This behaviour can either be: none, prepend, append or both.
+ *
+ * :return: ``OpenLayers.Filter``
+ *
+ * Create an {OpenLayers.Filter} object from a {Ext.form.BasicForm}
+ * or a {Ext.form.FormPanel} instance.
+ */
+GeoExt.ux.form.FormToFilter.prototype.toFilter = function(form, logicalOp, wildcard) {
+
+ if(form instanceof Ext.form.FormPanel) {
+ form = form.getForm();
+ }
+ var filters = [];
+
+ var that = this;
+ form.items.each( function(item) {
+
+ var prop = item.getName();
+ var s = prop.split("__");
+
+ var value = item.getValue();
+
+ if (value instanceof Date) {
+ // dates must be formatted with ISO date format (Y-m-d H:i:s)
+ value = value.format("Y-m-d H:i:s");
+ }
+
+ var type;
+
+ if(!that.ignoreEmptyFields || (value != null && value != "")) {
+ if(s.length > 1 &&
+ (type = that.toFilter.FILTER_MAP[s[1]]) !== undefined) {
+ prop = s[0];
+ } else {
+ type = OpenLayers.Filter.Comparison.EQUAL_TO;
+ }
+
+ if (type === OpenLayers.Filter.Comparison.LIKE) {
+ switch(wildcard) {
+ case that.toFilter.ENDS_WITH:
+ value = '.*' + value;
+ break;
+ case that.toFilter.STARTS_WITH:
+ value += '.*';
+ break;
+ case that.toFilter.CONTAINS:
+ value = '.*' + value + '.*';
+ break;
+ default:
+ // do nothing, just take the value
+ break;
+ }
+ }
+
+ filters.push(
+ new OpenLayers.Filter.Comparison({
+ type: type,
+ value: value,
+ property: prop
+ })
+ );
+ }
+ });
+
+
+ return filters.length == 1 && logicalOp != OpenLayers.Filter.Logical.NOT ?
+ filters[0] :
+ new OpenLayers.Filter.Logical({
+ type: logicalOp || OpenLayers.Filter.Logical.AND,
+ filters: filters
+ });
+};
+
+
+/** private: constant[FILTER_MAP]
+ * An object mapping operator strings as found in field names to
+ * ``OpenLayers.Filter.Comparison`` types.
+ */
+GeoExt.ux.form.FormToFilter.prototype.toFilter.FILTER_MAP = {
+ "eq": OpenLayers.Filter.Comparison.EQUAL_TO,
+ "ne": OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
+ "lt": OpenLayers.Filter.Comparison.LESS_THAN,
+ "le": OpenLayers.Filter.Comparison.LESS_THAN_OR_EQUAL_TO,
+ "gt": OpenLayers.Filter.Comparison.GREATER_THAN,
+ "ge": OpenLayers.Filter.Comparison.GREATER_THAN_OR_EQUAL_TO,
+ "like": OpenLayers.Filter.Comparison.LIKE
+};
+
+GeoExt.ux.form.FormToFilter.prototype.toFilter.ENDS_WITH = 1;
+GeoExt.ux.form.FormToFilter.prototype.toFilter.STARTS_WITH = 2;
+GeoExt.ux.form.FormToFilter.prototype.toFilter.CONTAINS = 3;
+
+/** private: function[recordToField]
+ * :param record: ``Ext.data.Record``, typically from an attributeStore
+ *
+ * :return: ``Object`` An object literal with a xtype property, use
+ * ``Ext.ComponentMgr.create`` (or ``Ext.create`` in Ext 3) to create
+ * an ``Ext.form.Field`` from this object.
+ *
+ * This function can be used to create an ``Ext.form.Field`` from
+ * an ``Ext.data.Record`` containing name, type, restriction and
+ * label fields.
+ */
+GeoExt.ux.form.FormToFilter.prototype.recordToField = function(record) {
+ var type = record.get("type");
+
+ if(typeof type === "object" && type.xtype) {
+ // we have an xtype'd object literal in the type
+ // field, just return it
+ return type;
+ }
+
+ var field;
+
+ var name = record.get("name");
+ var label = record.get("label");
+ var restriction = record.get("restriction") || {};
+
+ // use name for label if label isn't defined in the record
+ if(label == null) {
+ label = name;
+ }
+
+ type = type.split(":").pop(); // remove ns prefix
+
+ var r = this.recordToField.REGEXES;
+
+ if(type.match(r["text"])) {
+ var maxLength = restriction["maxLength"] !== undefined ?
+ parseFloat(restriction["maxLength"]) : undefined;
+ var minLength = restriction["minLength"] !== undefined ?
+ parseFloat(restriction["minLength"]) : undefined;
+ field = {
+ xtype: "textfield",
+ name: name,
+ fieldLabel: label,
+ maxLength: maxLength,
+ minLength: minLength
+ };
+ } else if(type.match(r["number"])) {
+ var maxValue = restriction["maxInclusive"] !== undefined ?
+ parseFloat(restriction["maxInclusive"]) : undefined;
+ var minValue = restriction["minInclusive"] !== undefined ?
+ parseFloat(restriction["minInclusive"]) : undefined;
+ field = {
+ xtype: "numberfield",
+ name: name,
+ fieldLabel: label,
+ maxValue: maxValue,
+ minValue: minValue
+ };
+ } else if(type.match(r["boolean"])) {
+ field = {
+ xtype: "checkbox",
+ name: name,
+ boxLabel: label
+ };
+ } else if(type.match(r["date"])) {
+ field = {
+ xtype: "datefield",
+ fieldLabel: label,
+ name: name
+ };
+ }
+
+ return field;
+};
+
+/** private: constant[REGEXES]
+ * ``Object`` Regular expressions for determining what type
+ * of field to create from an attribute record.
+ */
+GeoExt.ux.form.FormToFilter.prototype.recordToField.REGEXES = {
+ "text": new RegExp(
+ "^(text|string)$", "i"
+ ),
+ "number": new RegExp(
+ "^(number|float|decimal|double|int|long|integer|short)$", "i"
+ ),
+ "boolean": new RegExp(
+ "^(boolean)$", "i"
+ ),
+ "date": new RegExp(
+ "^(dateTime)$", "i"
+ )
+};
Added: sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/ResetAction.js
===================================================================
--- sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/ResetAction.js (rev 0)
+++ sandbox/borealis/geoext.ux/ux/AttributeFilterPanel/lib/GeoExt.ux/widgets/attributefilterpanel/ResetAction.js 2010-11-29 19:28:43 UTC (rev 2503)
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace("GeoExt.ux.form");
+
+GeoExt.ux.form.ResetAction = Ext.extend(Ext.form.Action, {
+ /** private: property[type]
+ * ``String`` The action type string.
+ */
+ type: "reset",
+
+ /** api: property[formPanel]
+ * ``GeoExt.ux.form.AttributeFilterPanel`` form object
+ */
+ formPanel: null,
+
+ /** private
+ * (used by ``GeoExt.ux.form.AttributeFilterBasicForm``)
+ */
+ constructor: function(form, options) {
+ Ext.apply(this, options);
+ GeoExt.ux.form.ResetAction.superclass.constructor.call(this, form, options);
+ },
+
+ /** private: method[run]
+ * Run the action.
+ */
+ run: function() {
+ var o = this.options;
+ if (this.formPanel) {
+ // clear the contents of the form fields
+ var data = {};
+ this.formPanel.items.each(function(item) {
+ data[item.getName()] = null;
+ });
+ var emptyRecord = new Ext.data.Record(data);
+ this.formPanel.getForm().loadRecord(emptyRecord);
+ }
+
+ if (o.layer) {
+ // clear the layer's filter and refresh the layer
+ o.layer.filter = null;
+ o.layer.refresh({force: true});
+ }
+
+ }
+
+});
More information about the Commits
mailing list