Author: jaz
Date: Tue Mar 8 16:43:25 2011
New Revision: 1079427
URL:
http://svn.apache.org/viewvc?rev=1079427&view=revLog:
two new features added to the autocomplete lookups:
1. pass searchDistinct will set the distinct flag on the entity options
2. list of condition field values are ORed together (key = value1 OR key = value2 etc)
Modified:
ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
Modified: ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy?rev=1079427&r1=1079426&r2=1079427&view=diff==============================================================================
--- ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy (original)
+++ ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy Tue Mar 8 16:43:25 2011
@@ -32,6 +32,7 @@ def orExprs = [];
def entityName = context.entityName;
def searchFields = context.searchFields;
def displayFields = context.displayFields ?: searchFields;
+def searchDistinct = Boolean.valueOf(context.searchDistinct ?: false);
def searchValueFieldName = parameters.term;
def fieldValue = null;
@@ -81,7 +82,15 @@ def conditionFields = context.conditionF
if (conditionFields) {
// these fields are for additonal conditions, this is a Map of name/value pairs
for (conditionFieldEntry in conditionFields.entrySet()) {
- mainAndConds.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(conditionFieldEntry.getKey()), EntityOperator.EQUALS, conditionFieldEntry.getValue()));
+ if (conditionFieldEntry.getValue() instanceof java.util.List) {
+ def orCondFields = [];
+ for (entry in conditionFieldEntry.getValue()) {
+ orCondFields.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(conditionFieldEntry.getKey()), EntityOperator.EQUALS, entry));
+ }
+ mainAndConds.add(EntityCondition.makeCondition(orCondFields, EntityOperator.OR));
+ } else {
+ mainAndConds.add(EntityCondition.makeCondition(EntityFieldValue.makeFieldValue(conditionFieldEntry.getKey()), EntityOperator.EQUALS, conditionFieldEntry.getValue()));
+ }
}
}
@@ -93,11 +102,13 @@ if (orExprs && entityName && displayFiel
mainAndConds.add(context.andCondition);
}
- def entityConditionList = EntityCondition.makeCondition(mainAndConds, EntityOperator.AND);
-
+ def entityConditionList = EntityCondition.makeCondition(mainAndConds, EntityOperator.AND);
+
Integer autocompleterViewSize = Integer.valueOf(context.autocompleterViewSize ?: 10);
EntityFindOptions findOptions = new EntityFindOptions();
findOptions.setMaxRows(autocompleterViewSize);
+ findOptions.setDistinct(searchDistinct);
+
autocompleteOptions = delegator.findList(entityName, entityConditionList, displayFieldsSet, StringUtil.toList(displayFields), findOptions, false);
if (autocompleteOptions) {
context.autocompleteOptions = autocompleteOptions;