Sha256: f5728de10af1670f0777b7142802b9a657a2cd1e0581b36cb5f2d5a66b0ae5ed

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 KB

Contents

class IuguUI.SearchFilter extends IuguUI.Base

  layout: "iugu-ui-search-filter"
  className: "search-filter"

  defaults:
    name: "age"
    filterNames: [ "age" ]
    fixedFilters: []
    multiSelection: false
    translateTerms: false
    translationPrefix: "translation."

  events:
    'click [data-action=search-filter-button]': 'searchCollection'

  searchCollection: (e) ->
    e.preventDefault()
    @handleEvent "facet:click"
    button = $(e.target)
    filter = button.data('filter')
    button.toggleClass('active')

    unless @options.multiSelection || (@selected.length > 0 && _.first(@selected) == filter)
      @selected = []

    unless _.indexOf(@selected, filter.toString()) == -1
      @selected = _.without(@selected, filter.toString())
    else
      @selected.push(filter.toString())

    if @selected.length > 0
      @collection.configureFilter @options.name + '_filter', @selected
    else
      @collection.removeFilter @options.name + '_filter'
    
    @collection.goTo(1)

  initialize: ->
    @selected = []
    _.bindAll @, 'searchCollection', 'render'
    @collection.on 'reset', @render, @
    @collection.on "removed-filter:#{@options.name}_filter", @removedFilter, @
    super
    @

  context: ->
    collection: @collection
    selected: @selected
    filterNames: @options.filterNames
    fixedFilters: @options.fixedFilters
    translateTerms: @options.translateTerms
    translationPrefix: @options.translationPrefix

  render: ->
    lastFilter = @collection.getFilter 'status_filter'
    if lastFilter? && lastFilter.length > 0
      @selected = lastFilter

    super

  removedFilter: ->
    @selected = []

@IuguUI.SearchFilter = IuguUI.SearchFilter

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
iugu-ux-1.0.25 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.24 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.23 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.22 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.21 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.20 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.19 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.18 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.17 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.16 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.15 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee
iugu-ux-1.0.14 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-search-filter.js.coffee