Skip to content

Commit

Permalink
fix for gxp planetfederal#191 - allow automatic wildcard attachment i…
Browse files Browse the repository at this point in the history
…n LIKE Filters
  • Loading branch information
justb4 committed May 27, 2013
1 parent 0d1e37c commit ee1ecba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
41 changes: 41 additions & 0 deletions src/script/widgets/FilterBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, {
*/
caseInsensitiveMatch: false,


/** api: config[autoWildCardAttach]
* ``Boolean``
* Should search strings (LIKE comparison only) for attribute queries always be pre- and postfixed with wildcards?
* The ``wildCardString`` variable determines the wildcard string to be attached.
* Default is ``"false"``.
*/
autoWildCardAttach: false,

/** api: config[wildCardString]
* ``String``
* String to be pre- and postfixed for wildcards in LIKE Comparison Filters.
*/
wildCardString: '.*',

/** api: config[preComboText]
* ``String``
* String to display before filter type combo. Default is ``"Match"``.
Expand Down Expand Up @@ -193,6 +208,11 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, {
if(filter instanceof OpenLayers.Filter.Logical) {
filter = this.cleanFilter(filter);
}

// Should wildcard chars be attached to LIKE Filters?
if (this.autoWildCardAttach) {
filter = this.attachWildCards(filter);
}
}
return filter;
},
Expand Down Expand Up @@ -332,6 +352,27 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, {
return filter;
},

/** api: method[attachWildCards]
* :return: ``OpenLayers.Filter``
*
* Returns a filter where wildcard symbols are pre/appended for
* Comparison LIKE Filters.
*/
attachWildCards: function (filter) {

if (filter instanceof OpenLayers.Filter.Logical) {
// Go recursively through composite filter
for (var i = 0, len = filter.filters.length; i < len; ++i) {
filter = this.attachWildCards(filter.filters[i]);
}
} else if (filter.type === OpenLayers.Filter.Comparison.LIKE) {
// Wrap the value in Wildcard strings.
filter.value = this.wildCardString + filter.value + this.wildCardString;
}

return filter;
},

createDefaultFilter: function() {
return new OpenLayers.Filter.Comparison({
matchCase: !this.caseInsensitiveMatch});
Expand Down
10 changes: 9 additions & 1 deletion src/script/widgets/QueryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, {
*/
caseInsensitiveMatch: false,

/** api: config[autoWildCardAttach]
* ``Boolean``
* Should search strings (LIKE comparison only) for attribute queries always be pre/postpended with a wildcard '*' character?
* Default is ``"false"``.
*/
autoWildCardAttach: false,

/** private: property[selectedLayer]
* ``Ext.data.Record``
* The currently selected record in the layers combo.
Expand Down Expand Up @@ -299,7 +306,8 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, {
//anchor: "-8px",
attributes: this.attributeStore,
allowGroups: false,
caseInsensitiveMatch: this.caseInsensitiveMatch
caseInsensitiveMatch: this.caseInsensitiveMatch,
autoWildCardAttach: this.autoWildCardAttach
});

if(owner) {
Expand Down

0 comments on commit ee1ecba

Please sign in to comment.