123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- define("dojo/store/util/SimpleQueryEngine", ["../../_base/array"], function(arrayUtil) {
-
-
-
-
- return function(query, options){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- switch(typeof query){
- default:
- throw new Error("Can not query with a " + typeof query);
- case "object": case "undefined":
- var queryObject = query;
- query = function(object){
- for(var key in queryObject){
- var required = queryObject[key];
- if(required && required.test){
- if(!required.test(object[key])){
- return false;
- }
- }else if(required != object[key]){
- return false;
- }
- }
- return true;
- };
- break;
- case "string":
-
- if(!this[query]){
- throw new Error("No filter function " + query + " was found in store");
- }
- query = this[query];
-
- case "function":
-
- }
- function execute(array){
-
- var results = arrayUtil.filter(array, query);
-
- if(options && options.sort){
- results.sort(function(a, b){
- for(var sort, i=0; sort = options.sort[i]; i++){
- var aValue = a[sort.attribute];
- var bValue = b[sort.attribute];
-
- aValue = aValue != null ? aValue.valueOf() : aValue;
- bValue = bValue != null ? bValue.valueOf() : bValue;
- if (aValue != bValue) {
- return !!sort.descending == aValue > bValue ? -1 : 1;
- }
- }
- return 0;
- });
- }
-
- if(options && (options.start || options.count)){
- var total = results.length;
- results = results.slice(options.start || 0, (options.start || 0) + (options.count || Infinity));
- results.total = total;
- }
- return results;
- }
- execute.matches = query;
- return execute;
- };
- });
|