Permalink
Browse files

Update to latest version of AeroGear.js

  • Loading branch information...
1 parent 069e694 commit 24403b0d467dd871a4427c8edfe865632f188325 @kborchers committed Dec 17, 2012
Showing with 61 additions and 17 deletions.
  1. +59 −15 app/scripts/vendor/aerogear.js
  2. +2 −2 app/scripts/vendor/aerogear.min.js
@@ -1,4 +1,4 @@
-/*! AeroGear JavaScript Library - v1.0.0.Alpha - 2012-12-11
+/*! AeroGear JavaScript Library - v1.0.0.Alpha - 2012-12-13
* https://github.com/aerogear/aerogear-js
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
@@ -1062,6 +1062,33 @@ AeroGear.Core = function() {
this.getDataSync = function() {
return dataSync;
};
+
+ /**
+ Little utility used to compare nested object values in the filter method
+ @private
+ @augments Memory
+ @param {String} nestedKey - Filter key to test
+ @param {Object} nestedFilter - Filter object to test
+ @param {Object} nestedValue - Value object to test
+ @returns {Boolean}
+ */
+ this.traverseObjects = function( nestedKey, nestedFilter, nestedValue ) {
+ while ( typeof nestedFilter === "object" ) {
+ if ( nestedValue ) {
+ // Value contains this key so continue checking down the object tree
+ nestedKey = Object.keys( nestedFilter )[ 0 ];
+ nestedFilter = nestedFilter[ nestedKey ];
+ nestedValue = nestedValue[ nestedKey ];
+ } else {
+ break;
+ }
+ }
+ if ( nestedFilter === nestedValue ) {
+ return true;
+ } else {
+ return false;
+ }
+ };
};
// Public Methods
@@ -1213,8 +1240,8 @@ AeroGear.Core = function() {
});
*/
AeroGear.DataManager.adapters.Memory.prototype.filter = function( filterParameters, matchAny ) {
- var filtered,
- key, j, k, l;
+ var filtered, key, j, k, l, nestedKey, nestedFilter, nestedValue,
+ that = this;
if ( !filterParameters ) {
filtered = this.getData() || [];
@@ -1234,7 +1261,7 @@ AeroGear.Core = function() {
for ( j = 0; j < filterObj.data.length; j++ ) {
if( AeroGear.isArray( value[ keys[ key ] ] ) ) {
- if(value[ keys [ key ] ].length ) {
+ if( value[ keys [ key ] ].length ) {
if( $( value[ keys ] ).not( filterObj.data ).length === 0 && $( filterObj.data ).not( value[ keys ] ).length === 0 ) {
paramResult = true;
break;
@@ -1266,15 +1293,28 @@ AeroGear.Core = function() {
paramResult = false;
}
} else {
- if ( filterObj.matchAny && filterObj.data[ j ] === value[ keys[ key ] ] ) {
- // At least one value must match and this one does so return true
- paramResult = true;
- break;
- }
- if ( !filterObj.matchAny && filterObj.data[ j ] !== value[ keys[ key ] ] ) {
- // All must match but this one doesn't so return false
- paramResult = false;
- break;
+ if ( typeof filterObj.data[ j ] === "object" ) {
+ if ( filterObj.matchAny && that.traverseObjects( keys[ key ], filterObj.data[ j ], value[ keys[ key ] ] ) ) {
+ // At least one value must match and this one does so return true
+ paramResult = true;
+ break;
+ }
+ if ( !filterObj.matchAny && !that.traverseObjects( keys[ key ], filterObj.data[ j ], value[ keys[ key ] ] ) ) {
+ // All must match but this one doesn't so return false
+ paramResult = false;
+ break;
+ }
+ } else {
+ if ( filterObj.matchAny && filterObj.data[ j ] === value[ keys[ key ] ] ) {
+ // At least one value must match and this one does so return true
+ paramResult = true;
+ break;
+ }
+ if ( !filterObj.matchAny && filterObj.data[ j ] !== value[ keys[ key ] ] ) {
+ // All must match but this one doesn't so return false
+ paramResult = false;
+ break;
+ }
}
}
}
@@ -1283,7 +1323,7 @@ AeroGear.Core = function() {
if( AeroGear.isArray( value[ keys[ key ] ] ) ) {
paramResult = matchAny ? false: true;
- if(value[ keys[ key ] ].length ) {
+ if( value[ keys[ key ] ].length ) {
for(j = 0; j < value[ keys[ key ] ].length; j++ ) {
if( matchAny && filterParameters[ keys[ key ] ] === value[ keys[ key ] ][ j ] ) {
//at least one must match and this one does so return true
@@ -1300,7 +1340,11 @@ AeroGear.Core = function() {
paramResult = false;
}
} else {
- paramResult = filterParameters[ keys[ key ] ] === value[ keys[ key ] ] ? true : false;
+ if ( typeof filterParameters[ keys[ key ] ] === "object" ) {
+ paramResult = that.traverseObjects( keys[ key ], filterParameters[ keys[ key ] ], value[ keys[ key ] ] );
+ } else {
+ paramResult = filterParameters[ keys[ key ] ] === value[ keys[ key ] ] ? true : false;
+ }
}
}
Oops, something went wrong.

0 comments on commit 24403b0

Please sign in to comment.