Fixes issue 18841: Upgrade smartclient workaround issues
authorMartin Taal <martin.taal@openbravo.com>
Sat, 05 Nov 2011 23:36:04 +0100
changeset 14196 832f9c67f42b
parent 14195 5e7f093f2199
child 14197 2c91b7756596
Fixes issue 18841: Upgrade smartclient workaround issues
Fixes issue 18765: AND and OR logic does not work in column filter expressions
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Sat Nov 05 23:25:14 2011 +0100
+++ b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Sat Nov 05 23:36:04 2011 +0100
@@ -33,11 +33,6 @@
 
 isc.Canvas.addProperties({
   
-  // workaround for this issue:
-  // http://forums.smartclient.com/showthread.php?p=75007#post75007
-  // https://issues.openbravo.com/view.php?id=18841
-  cancelNativeScrollOnKeyDown: false,
-  
   // make sure that the datasources are also destroyed
   _original_destroy: isc.Canvas.getPrototype().destroy,
   destroy: function() {
@@ -105,7 +100,7 @@
   // this is a copy of the FormItem.parseValueExpressions to support
   // and/or logic for enum and text fields
   parseOBValueExpressions: function(value, fieldName) {
-    var type = this.getType(),
+    var type = this.getType(), i,
       isValidLogicType = (isc.SimpleType.inheritsFrom(type, 'enum') ||
           isc.SimpleType.inheritsFrom(type, 'text') ||
           isc.SimpleType.inheritsFrom(type, 'integer') ||
@@ -114,216 +109,242 @@
       ),
       opIndex = isc.DynamicForm.getOperatorIndex(),
       validOps = isc.getKeys(opIndex),
-      result = { operator: 'and', criteria: [], fieldName: fieldName},
+      result = { operator: "and", criteria: [] },
       crit = result.criteria,
-      valueParts = [], i,
-      ds = isc.DS.get(this.form.expressionDataSource || this.form.dataSource),
-      defOpName, defOp, insensitive, field, skipTheseOps,
-      valuePart, subCrit, isDateField, useDefaultOperator, opKey, key,
-      operator, operators, op, ops, wildCard,
-      parts, partCrit, part, partIndex,
-      hasPrefix, hasSuffix;
-    
+      valueParts = [],
+      allowEx = this._shouldAllowExpressions(),
+      ds = isc.DS.get(this.form.expressionDataSource || this.form.dataSource)
+    ;
+  
     if (!value) {
       value = this.getValue();
     }
     if (!value) {
       return;
     }
-    
+  
     if (!isc.isA.String(value)) {
-      value += '';
+      value += "";
     }
     
-    defOpName = this.getOperator();
+    var tempOps, tempOp;
+    
+    var defOpName = this.getOperator();
     if (defOpName) {
       validOps.add(defOpName);
     }
+  
+    var defOp = ds ? ds.getSearchOperator(defOpName) : { id: defOpName };
     
-    defOp = ds ? ds.getSearchOperator(defOpName) : { id: defOpName };
-    
-    insensitive = defOp.caseInsensitive;
-    
-    if (isValidLogicType && value.contains(' and ')) {
-        valueParts = value.split(' and ');
-    } else if (isValidLogicType && value.contains(' or ')) {
-        valueParts = value.split(' or ');
-        result.operator = 'or';
-    } else if (value.contains('...')) {
-        valueParts = value.split('...');
+    var field, insensitive = defOp.caseInsensitive;
+    var partIndex, parts, partCrit, part; 
+
+    if (isValidLogicType && value.contains(" and ")) {
+        valueParts = value.split(" and ");
+    } else if (isValidLogicType && value.contains(" or ")) {
+        valueParts = value.split(" or ");
+        result.operator = "or";
+    } else if (value.contains("...")) {
+        valueParts = value.split("...");
         if (valueParts.length === 2) {
-            var tempOps = opIndex['...'],
-                tempOp;
-    
+            tempOps = opIndex["..."];
+  
             if (tempOps) {
-              tempOp = (insensitive ? tempOps.find('caseInsensitive', true) : tempOps[0]);
+              tempOp = (insensitive ? tempOps.find("caseInsensitive", true) : tempOps[0]);
             }
-    
+  
             field = ds ? ds.getField(fieldName) : null;
-    
-            if (field && isc.SimpleType.inheritsFrom(field.type, 'date')) {
+  
+            if (field && isc.SimpleType.inheritsFrom(field.type, "date")) {
                 valueParts[0] = new Date(Date.parse(valueParts[0]));
                 valueParts[0].logicalDate = true;
                 valueParts[1] = new Date(Date.parse(valueParts[1]));
                 valueParts[1].logicalDate = true;
-            } else if (field && field.type === 'text') {
+            } else if (field && field.type === "text") {
                 
                 if (!valueParts[1].endsWith(this._betweenInclusiveEndCrit)) {
                     valueParts[1] += this._betweenInclusiveEndCrit;
                 }
             }
-    
+  
             return { fieldName: fieldName, operator: tempOp.ID, 
                 start: valueParts[0], end: valueParts[1] };
         }
     } else {
         valueParts = [value];
     }
-    
-    skipTheseOps = [ ' and ', ' or ', '...' ];
-    
-    for (i = 0; i < valueParts.length; i++) {
-        valuePart = valueParts[i];
-        subCrit = { fieldName: fieldName };
+  
+    var skipTheseOps = [ " and ", " or " ];
+  
+    for (i = 0; i<valueParts.length; i++) {
+        var key, valuePart = valueParts[i],
+            subCrit = { fieldName: fieldName };
+            
         field = ds ? ds.getField(fieldName) : null;
-        isDateField = (field ? field && isc.SimpleType.inheritsFrom(field.type, 'date') : false);
-    
-        useDefaultOperator = true;
-        for (opKey in opIndex) {
-          if (opIndex.hasOwnProperty(opKey)) {
-            if (!opKey) {
-              continue;
-            }
-            
-            operators = opIndex[opKey];
-  
-            if (operators && operators.length) {
-                operator = operators.find('caseInsensitive', insensitive) || operators[0];
-            }
-    
-            if (!operator || !operator.symbol || skipTheseOps.contains(operator.symbol)) {
-              continue;
-            }
-            if (validOps.contains(operator.symbol) && 
-                      (isc.isA.String(valuePart) && valuePart.startsWith(operator.symbol))) {
-              useDefaultOperator = false;
-              break;
-            }
-          }
-        }
-        if (useDefaultOperator) {
-          valuePart = defOp.symbol + valuePart;
-        }
+        var isDateField = (field ? field && isc.SimpleType.inheritsFrom(field.type, "date") : false),
+          valueHasExpression = false;
         
         for (key in opIndex) {
           if (opIndex.hasOwnProperty(key)) {
-    
             if (!key) {
               continue;
             }
-    
-            ops = opIndex[key];
-            wildCard = false;
-    
-            if (key === '==' && isc.isA.String(valuePart) && valuePart.startsWith('=') && 
-                    !valuePart.startsWith('==') && !valuePart.startsWith('=(')) 
+  
+            var ops = opIndex[key],
+                wildCard = false,
+                op
+            ;
+  
+            if (key === "==" && isc.isA.String(valuePart) && valuePart.startsWith("=") && 
+                    !valuePart.startsWith("==") && !valuePart.startsWith("=(")) 
             {
-              wildCard = true;
+                wildCard = true;
             }
-    
+  
             if (ops && ops.length) {
-              op = ops.find('caseInsensitive', insensitive) || ops[0];
+                op = ops.find("caseInsensitive", insensitive) || ops[0];
             }
-    
+  
             if (!op || !op.symbol || skipTheseOps.contains(op.symbol)) {
               continue;
             }
             
             if (validOps.contains(op.symbol) && (
-                  (isc.isA.String(valuePart) && valuePart.startsWith(op.symbol)) 
-                  || wildCard))
+                    (isc.isA.String(valuePart) && (valuePart.startsWith(op.symbol) || 
+                        
+                        (op.symbol === "..." && valuePart.contains(op.symbol)))
+                    ) 
+                    || wildCard))
             {
-              valuePart = valuePart.substring(op.symbol.length - (wildCard ? 1 : 0));
-              if (op.closingSymbol) {
-                // this is a containing operator (inSet, notInSet), with opening and 
-                // closing symbols...  check that the value endsWith the correct 
-                // closing symbol and strip it off - op.processValue() will split 
-                // the string for us later
-                if (valuePart.endsWith(op.closingSymbol)) {
-                    valuePart = valuePart.substring(0, valuePart.length - op.closingSymbol.length);
+                valueHasExpression = true;
+            
+                if (valuePart.startsWith(op.symbol)) {
+                    valuePart = valuePart.substring(op.symbol.length - (wildCard ? 1 : 0));
                 }
-              }
   
-              if (isDateField) {
-                valuePart = new Date(Date.parse(valuePart));
-                valuePart.logicalDate = true;
-              }
+                if (op.closingSymbol) {
+                    // this is a containing operator (inSet, notInSet), with opening and 
+                    // closing symbols...  check that the value endsWith the correct 
+                    // closing symbol and strip it off - op.processValue() will split 
+                    // the string for us later
+                    if (valuePart.endsWith(op.closingSymbol)) {
+                        valuePart = valuePart.substring(0, valuePart.length - op.closingSymbol.length);
+                    }
+                }
   
-              subCrit.operator = op.ID;
+                if (valuePart.contains("...")) {
+                    // allow range operators as well as conjunctives
+                    var rangeValueParts = valuePart.split("...");
+                    if (rangeValueParts.length === 2) {
+                        tempOps = opIndex["..."];
   
-              if (op.processValue) {
-                valuePart = op.processValue(valuePart, ds);
-              }
+                        if (tempOps) {
+                          tempOp = (insensitive ? tempOps.find("caseInsensitive", true) : tempOps[0]);
+                        }
   
-              if (op.wildCard && isc.isA.String(valuePart) && valuePart.contains(op.wildCard)) {
-                // this is an operator that supports wildCards (equals, notEquals)...
-                
-                parts = valuePart.split(op.wildCard);
+                        field = ds ? ds.getField(fieldName) : null;
   
-                if (parts.length > 1) {
-                  for (partIndex=0; partIndex<parts.length; partIndex++) {
-                    part = parts[partIndex];
+                        if (field && isc.SimpleType.inheritsFrom(field.type, "date")) {
+                            rangeValueParts[0] = new Date(Date.parse(rangeValueParts[0]));
+                            rangeValueParts[0].logicalDate = true;
+                            rangeValueParts[1] = new Date(Date.parse(rangeValueParts[1]));
+                            rangeValueParts[1].logicalDate = true;
+                        } else if (field && field.type === "text") {
+                            
+                            if (!rangeValueParts[1].endsWith(this._betweenInclusiveEndCrit)) {
+                                rangeValueParts[1] += this._betweenInclusiveEndCrit;
+                            }
+                        }
   
-                    if (!part || part.length === 0) {
-                      continue;
+                        result.criteria.add({ fieldName: fieldName, operator: tempOp.ID, 
+                            start: rangeValueParts[0], end: rangeValueParts[1] 
+                        });
+  
+                        continue;
                     }
+                }
   
-                    partCrit = { fieldName: fieldName, value: part };
+                if (isDateField) {
+                    valuePart = new Date(Date.parse(valuePart));
+                    valuePart.logicalDate = true;
+                }
   
-                    hasPrefix = partIndex > 0;
-                    hasSuffix = parts.length - 1 > partIndex;
+                subCrit.operator = op.ID;
   
-                    if (hasPrefix && hasSuffix) {
-                      // this is a contains criteria
-                      partCrit.operator = insensitive ? 'iContains' : 'contains';
-                    } else if (hasPrefix) {
-                      // this is an endsWith criteria
-                      partCrit.operator = insensitive ? 'iEndsWith' : 'endsWith';
-                    } else if (hasSuffix) {
-                      // this is a startsWith criteria
-                      partCrit.operator = insensitive ? 'iStartsWith' : 'startsWith';
+                if (op.processValue) {
+                    valuePart = op.processValue(valuePart, ds);
+                }
+  
+                if (op.wildCard && isc.isA.String(valuePart) && valuePart.contains(op.wildCard)) {
+                    // this is an operator that supports wildCards (equals, notEquals)...
+                    
+                    parts = valuePart.split(op.wildCard);
+  
+                    if (parts.length > 1) {
+                        for (partIndex=0; partIndex<parts.length; partIndex++) {
+                            part = parts[partIndex];
+  
+                            if (!part || part.length === 0) {
+                              continue;
+                            }
+  
+                            partCrit = { fieldName: fieldName, value: part };
+  
+                            var hasPrefix = partIndex > 0,
+                                hasSuffix = parts.length - 1 > partIndex
+                            ;
+  
+                            if (hasPrefix && hasSuffix) {
+                                // this is a contains criteria
+                                partCrit.operator = insensitive ? "iContains" : "contains";
+                            } else if (hasPrefix) {
+                                // this is an endsWith criteria
+                                partCrit.operator = insensitive ? "iEndsWith" : "endsWith";
+                            } else if (hasSuffix) {
+                                // this is a startsWith criteria
+                                partCrit.operator = insensitive ? "iStartsWith" : "startsWith";
+                            }
+  
+                            result.criteria.add(partCrit);
+                        }
+  
+                        // we'll include a check for this attribute when rebuilding the 
+                        // value later
+                        this._lastValueHadWildCards = true;
+  
+                        // clear out the sub-crit's operator - this will prevent it being
+                        // added to the result criteria below (we've already added 
+                        // everything we need above
+                        subCrit.operator = null;
                     }
+                } else {
+                    // set the value if one is required for the op
+                    if (op.valueType !== "none") {
+                      subCrit.value = valuePart;
+                    }
+                }
   
-                    result.criteria.add(partCrit);
-                  }
-  
-                  // clear out the sub-crit's operator - this will prevent it being
-                  // added to the result criteria below (we've already added 
-                  // everything we need above
-                  subCrit.operator = null;
-                }
-            } else {
-              // set the value if one is required for the op
-              if (op.valueType !== 'none') {
-                subCrit.value = valuePart;
-              }
+                break;
             }
-  
-            break;
           }
         }
-      }
-      if (subCrit.operator) {
-        result.criteria.add(subCrit);
-      }
+        if (!valueHasExpression) {
+            // this was a straight expression like "10"
+            subCrit.operator = defOpName;
+            subCrit.value = valuePart;
+        }
+        if (subCrit.operator) {
+          result.criteria.add(subCrit);
+        }
     }
+  //  this.logWarn("Parsed expression:" + value + " to criterion:" + this.echo(result));
     if (result.criteria.length === 1) {
       result = result.criteria[0];
     }
     if (result.criteria && result.criteria.length === 0) {
       result = null;
     }
-    
+  
     return result;
   },
 
@@ -656,17 +677,6 @@
 // between accent or non-accent words
 isc.DataSource.addProperties({
   
-  // workaround for this issue:
-  // http://forums.smartclient.com/showthread.php?p=75186#post75186
-  // https://issues.openbravo.com/view.php?id=18841
-  compareAdvancedCriteria: function(newCriterion, oldCriterion) {
-    // simple check...
-    if (newCriterion === oldCriterion) {
-      return 0;
-    }
-    return 1;
-  },
-  
   _fieldMatchesFilter: isc.DataSource.getPrototype().fieldMatchesFilter,
   fieldMatchesFilter: function(fieldValue, filterValue, requestProperties) {
     if (fieldValue && typeof fieldValue === 'string') {