Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. advancedSearch: (field_name = null, values = []) ->
  2.     options = []
  3.     if arguments.length is 1 and _.isArray field_name
  4.       options = field_name
  5.       for option in options
  6.         if option[1] and !_.isArray option[1]
  7.           option[1] = [option[1]]
  8.     else if arguments.length is 1 and _.isObject field_name
  9.       options = []
  10.       _.each field_name, (values, field_name) =>
  11.         if !_.isArray values
  12.           values = [values]
  13.         options.push [field_name, values]
  14.     else
  15.       if !_.isArray values
  16.         values = [values]
  17.       options = [[field_name, values ]]
  18.     @filter (item) =>
  19.       len = options.length
  20.       checked = 0
  21.       for option in options
  22.         if _.include option[1], item.get option[0]
  23.           checked++
  24.       len is checked