11/**
22*@author Jason Dobry <jason.dobry@gmail.com>
33*@file angular-data.js
4- *@version 1.4.1 - Homepage <http://angular-data.pseudobry.com/>
4+ *@version 1.4.2 - Homepage <http://angular-data.pseudobry.com/>
55*@copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66*@license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77*
@@ -4139,6 +4139,7 @@ Defaults.prototype.idAttribute = 'id';
41394139Defaults . prototype . defaultAdapter = 'DSHttpAdapter' ;
41404140Defaults . prototype . defaultFilter = function ( collection , resourceName , params , options ) {
41414141var _this = this ;
4142+ var DSUtils = _this . utils ;
41424143var filtered = collection ;
41434144var where = null ;
41444145var reserved = {
@@ -4152,14 +4153,14 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
41524153
41534154params = params || { } ;
41544155
4155- if ( _this . utils . isObject ( params . where ) ) {
4156+ if ( DSUtils . isObject ( params . where ) ) {
41564157where = params . where ;
41574158} else {
41584159where = { } ;
41594160}
41604161
41614162if ( options . allowSimpleWhere ) {
4162- _this . utils . forEach ( params , function ( value , key ) {
4163+ DSUtils . forEach ( params , function ( value , key ) {
41634164if ( ! ( key in reserved ) && ! ( key in where ) ) {
41644165where [ key ] = {
41654166'==' :value
@@ -4168,26 +4169,26 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
41684169} ) ;
41694170}
41704171
4171- if ( _this . utils . isEmpty ( where ) ) {
4172+ if ( DSUtils . isEmpty ( where ) ) {
41724173where = null ;
41734174}
41744175
41754176if ( where ) {
4176- filtered = _this . utils . filter ( filtered , function ( attrs ) {
4177+ filtered = DSUtils . filter ( filtered , function ( attrs ) {
41774178var first = true ;
41784179var keep = true ;
4179- _this . utils . forEach ( where , function ( clause , field ) {
4180- if ( _this . utils . isString ( clause ) ) {
4180+ DSUtils . forEach ( where , function ( clause , field ) {
4181+ if ( DSUtils . isString ( clause ) ) {
41814182clause = {
41824183'===' :clause
41834184} ;
4184- } else if ( _this . utils . isNumber ( clause ) || _this . utils . isBoolean ( clause ) ) {
4185+ } else if ( DSUtils . isNumber ( clause ) || DSUtils . isBoolean ( clause ) ) {
41854186clause = {
41864187'==' :clause
41874188} ;
41884189}
4189- if ( _this . utils . isObject ( clause ) ) {
4190- _this . utils . forEach ( clause , function ( val , op ) {
4190+ if ( DSUtils . isObject ( clause ) ) {
4191+ DSUtils . forEach ( clause , function ( val , op ) {
41914192if ( op === '==' ) {
41924193keep = first ?( attrs [ field ] == val ) :keep && ( attrs [ field ] == val ) ;
41934194} else if ( op === '===' ) {
@@ -4205,9 +4206,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42054206} else if ( op === '<=' ) {
42064207keep = first ?( attrs [ field ] <= val ) :keep && ( attrs [ field ] <= val ) ;
42074208} else if ( op === 'in' ) {
4208- keep = first ?_this . utils . contains ( val , attrs [ field ] ) :keep && _this . utils . contains ( val , attrs [ field ] ) ;
4209+ if ( DSUtils . isString ( val ) ) {
4210+ keep = first ?val . indexOf ( attrs [ field ] ) !== - 1 :keep && val . indexOf ( attrs [ field ] ) !== - 1 ;
4211+ } else {
4212+ keep = first ?DSUtils . contains ( val , attrs [ field ] ) :keep && DSUtils . contains ( val , attrs [ field ] ) ;
4213+ }
42094214} else if ( op === 'notIn' ) {
4210- keep = first ?! _this . utils . contains ( val , attrs [ field ] ) :keep && ! _this . utils . contains ( val , attrs [ field ] ) ;
4215+ if ( DSUtils . isString ( val ) ) {
4216+ keep = first ?val . indexOf ( attrs [ field ] ) === - 1 :keep && val . indexOf ( attrs [ field ] ) === - 1 ;
4217+ } else {
4218+ keep = first ?! DSUtils . contains ( val , attrs [ field ] ) :keep && ! DSUtils . contains ( val , attrs [ field ] ) ;
4219+ }
42114220} else if ( op === '|==' ) {
42124221keep = first ?( attrs [ field ] == val ) :keep || ( attrs [ field ] == val ) ;
42134222} else if ( op === '|===' ) {
@@ -4225,9 +4234,17 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42254234} else if ( op === '|<=' ) {
42264235keep = first ?( attrs [ field ] <= val ) :keep || ( attrs [ field ] <= val ) ;
42274236} else if ( op === '|in' ) {
4228- keep = first ?_this . utils . contains ( val , attrs [ field ] ) :keep || _this . utils . contains ( val , attrs [ field ] ) ;
4237+ if ( DSUtils . isString ( val ) ) {
4238+ keep = first ?val . indexOf ( attrs [ field ] ) !== - 1 :keep || val . indexOf ( attrs [ field ] ) !== - 1 ;
4239+ } else {
4240+ keep = first ?DSUtils . contains ( val , attrs [ field ] ) :keep || DSUtils . contains ( val , attrs [ field ] ) ;
4241+ }
42294242} else if ( op === '|notIn' ) {
4230- keep = first ?! _this . utils . contains ( val , attrs [ field ] ) :keep || ! _this . utils . contains ( val , attrs [ field ] ) ;
4243+ if ( DSUtils . isString ( val ) ) {
4244+ keep = first ?val . indexOf ( attrs [ field ] ) === - 1 :keep || val . indexOf ( attrs [ field ] ) === - 1 ;
4245+ } else {
4246+ keep = first ?! DSUtils . contains ( val , attrs [ field ] ) :keep || ! DSUtils . contains ( val , attrs [ field ] ) ;
4247+ }
42314248}
42324249first = false ;
42334250} ) ;
@@ -4239,29 +4256,29 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42394256
42404257var orderBy = null ;
42414258
4242- if ( _this . utils . isString ( params . orderBy ) ) {
4259+ if ( DSUtils . isString ( params . orderBy ) ) {
42434260orderBy = [
42444261[ params . orderBy , 'ASC' ]
42454262] ;
4246- } else if ( _this . utils . isArray ( params . orderBy ) ) {
4263+ } else if ( DSUtils . isArray ( params . orderBy ) ) {
42474264orderBy = params . orderBy ;
42484265}
42494266
4250- if ( ! orderBy && _this . utils . isString ( params . sort ) ) {
4267+ if ( ! orderBy && DSUtils . isString ( params . sort ) ) {
42514268orderBy = [
42524269[ params . sort , 'ASC' ]
42534270] ;
4254- } else if ( ! orderBy && _this . utils . isArray ( params . sort ) ) {
4271+ } else if ( ! orderBy && DSUtils . isArray ( params . sort ) ) {
42554272orderBy = params . sort ;
42564273}
42574274
42584275// Apply 'orderBy'
42594276if ( orderBy ) {
42604277var index = 0 ;
42614278angular . forEach ( orderBy , function ( def , i ) {
4262- if ( _this . utils . isString ( def ) ) {
4279+ if ( DSUtils . isString ( def ) ) {
42634280orderBy [ i ] = [ def , 'ASC' ] ;
4264- } else if ( ! _this . utils . isArray ( def ) ) {
4281+ } else if ( ! DSUtils . isArray ( def ) ) {
42654282throw new _this . errors . IllegalArgumentError ( 'DS.filter(resourceName[, params][, options]): ' + JSON . stringify ( def ) + ': Must be a string or an array!' , {
42664283params :{
42674284'orderBy[i]' :{
@@ -4271,8 +4288,8 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42714288}
42724289} ) ;
42734290}
4274- filtered = _this . utils . sort ( filtered , function ( a , b ) {
4275- return compare ( _this . utils , orderBy , index , a , b ) ;
4291+ filtered = DSUtils . sort ( filtered , function ( a , b ) {
4292+ return compare ( DSUtils , orderBy , index , a , b ) ;
42764293} ) ;
42774294} ) ;
42784295}