Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created August 26, 2008 21:48
Show Gist options
  • Save nickjs/7360 to your computer and use it in GitHub Desktop.
Save nickjs/7360 to your computer and use it in GitHub Desktop.
listFor: function(opts) {
var recordType = opts.recordType ;
var resource = recordType.resourceURL() ; if (!resource) return false ;
// TODO: check if the user has given a path to a view.
// if so, call that view (with Method: GET)
var url = resource + "/_temp_view"
var content = {}
var context = {
recordType: recordType
}
//CHANGED
params = {} ;
var temp = '(doc)';
if (opts.conditions) {
var conditions = this._decamelizeData(opts.conditions) ;
for(var key in conditions) {
temp = '' + temp + ' && (doc.' + key + '==\'' + conditions[key] + '\')';
}
}
//CHANGED
content.map = "function(doc) { " +
"if ("+temp+"){ "+
"emit(doc._id, doc)"+
"}}" ;
params.requestContext = context ;
params.url = url ;
params.body = content ;
params.onSuccess = this._listSuccess.bind(this) ;
params.onNotModified = this._listNotModified.bind(this) ;
params.onFailure = this._listFailure.bind(this) ;
this.request(resource, this._listForAction, null, params, this._listForMethod) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment