| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/array", |
| 4 |
"dojo/_base/lang", |
| 5 |
"./_FilterExpr" |
| 6 |
], function(declare, array, lang, exprs){ |
| 7 |
|
| 8 |
var bdr = function(opCls){ |
| 9 |
return lang.partial(function(cls,operands){ |
| 10 |
return new exprs[cls](operands); |
| 11 |
},opCls); |
| 12 |
}, |
| 13 |
bdr_not = function(opCls){ |
| 14 |
return lang.partial(function(cls,operands){ |
| 15 |
return new exprs.LogicNOT(new exprs[cls](operands)); |
| 16 |
},opCls); |
| 17 |
}; |
| 18 |
return declare("dojox.grid.enhanced.plugins.filter.FilterBuilder", null, { |
| 19 |
|
| 20 |
|
| 21 |
buildExpression: function(def){ |
| 22 |
if("op" in def){ |
| 23 |
return this.supportedOps[def.op.toLowerCase()](array.map(def.data, this.buildExpression, this)); |
| 24 |
}else{ |
| 25 |
var args = lang.mixin(this.defaultArgs[def.datatype], def.args || {}); |
| 26 |
return new this.supportedTypes[def.datatype](def.data, def.isColumn, args); |
| 27 |
} |
| 28 |
}, |
| 29 |
supportedOps: { |
| 30 |
|
| 31 |
|
| 32 |
"equalto": bdr("EqualTo"), |
| 33 |
"lessthan": bdr("LessThan"), |
| 34 |
"lessthanorequalto": bdr("LessThanOrEqualTo"), |
| 35 |
"largerthan": bdr("LargerThan"), |
| 36 |
"largerthanorequalto": bdr("LargerThanOrEqualTo"), |
| 37 |
"contains": bdr("Contains"), |
| 38 |
"startswith": bdr("StartsWith"), |
| 39 |
"endswith": bdr("EndsWith"), |
| 40 |
"notequalto": bdr_not("EqualTo"), |
| 41 |
"notcontains": bdr_not("Contains"), |
| 42 |
"notstartswith": bdr_not("StartsWith"), |
| 43 |
"notendswith": bdr_not("EndsWith"), |
| 44 |
"isempty": bdr("IsEmpty"), |
| 45 |
"range": function(operands){ |
| 46 |
return new exprs.LogicALL( |
| 47 |
new exprs.LargerThanOrEqualTo(operands.slice(0,2)), |
| 48 |
new exprs.LessThanOrEqualTo(operands[0], operands[2]) |
| 49 |
); |
| 50 |
}, |
| 51 |
"logicany": bdr("LogicANY"), |
| 52 |
"logicall": bdr("LogicALL") |
| 53 |
}, |
| 54 |
supportedTypes: { |
| 55 |
"number": exprs.NumberExpr, |
| 56 |
"string": exprs.StringExpr, |
| 57 |
"boolean": exprs.BooleanExpr, |
| 58 |
"date": exprs.DateExpr, |
| 59 |
"time": exprs.TimeExpr |
| 60 |
}, |
| 61 |
defaultArgs: { |
| 62 |
"boolean": { |
| 63 |
"falseValue": "false", |
| 64 |
"convert": function(dataValue, args){ |
| 65 |
var falseValue = args.falseValue; |
| 66 |
var trueValue = args.trueValue; |
| 67 |
if(lang.isString(dataValue)){ |
| 68 |
if(trueValue && dataValue.toLowerCase() == trueValue){ |
| 69 |
return true; |
| 70 |
} |
| 71 |
if(falseValue && dataValue.toLowerCase() == falseValue){ |
| 72 |
return false; |
| 73 |
} |
| 74 |
} |
| 75 |
return !!dataValue; |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
}); |
| 80 |
}); |