Author: ygrego Date: 2015-04-15 13:14:26 +0000 (Wed, 15 Apr 2015) New Revision: 1195 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1195 Log: New methods added and call of method "_evaluateQuery" into method "_getAnyProgramme". Modified: oipf/js/impl/model/SearchResults.js Modified: oipf/js/impl/model/SearchResults.js =================================================================== --- oipf/js/impl/model/SearchResults.js 2015-04-15 13:11:52 UTC (rev 1194) +++ oipf/js/impl/model/SearchResults.js 2015-04-15 13:14:26 UTC (rev 1195) @@ -197,8 +197,7 @@ for (var i = 0, l = programmes.length; i < l; i++) { var programme = programmes[i]; - if (programme[field] && methodName && - oipf.utils[methodName].call(null, programme[field], value)) { + if (this._evaluateQuery(this._search._currentQuery, programme)) { var constraints = this._search. _constraints.channels; @@ -259,6 +258,53 @@ */ item: function(index) { return this[index]; + }, + + _evaluateQuery: function(query, programme) { + var field = this._getPropertyName(this._search._currentQuery._field); + var comparison = this._search._currentQuery._comparison; + var value = this._search._currentQuery._value; + var methodName = this._methodToCall[comparison]; + + if (query._and.length > 0 && query._or.length > 0) { + + return + (oipf.utils[methodName].call(null, programme[field], value) && + this._evaluateQueryLoop(query._and, programme)) || + (oipf.utils[methodName].call(null, programme[field], value) || + this._evaluateQueryLoop(query._and, programme)); + + } else if (query._and.length > 0 && query._or.length == 0) { + + return + (oipf.utils[methodName].call(null, programme[field], value) && + this._evaluateQueryLoop(query._and, programme)); + + } else if (query._or.length > 0 && query._and.length == 0) { + + return + (oipf.utils[methodName].call(null, programme[field], value) && + this._evaluateQueryLoop(query._or, programme)); + + } else if (query._and.length == 0 && query._or.length == 0) { + return (oipf.utils[methodName].call(null, programme[field], value)); + } + + }, + + _evaluateQueryLoop: function(query, programme) { + for (var i = 0, l = query; i < l; i++) { + if (!this._evaluateQuery(query, programme)) { + return false; + } + } + }, + + _getPropertyName: function(field) { + var pattern = /\w+.(\w+)/; + var propertyName = pattern.exec(field); + + return propertyName[1]; } - + }); \ No newline at end of file