Created
March 5, 2012 17:13
-
-
Save kwhitaker/1979501 to your computer and use it in GitHub Desktop.
Trying to scope back to currentView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class window.PlacementFiltersView extends Backbone.View | |
el: "#placements form#filters" | |
initialize: -> | |
currentView = @ | |
# Create a hash of labels for the filter type-aheads | |
@filterLabels = [] | |
jQuery(@el).find('.filter-top-level option').each -> | |
if jQuery(@).val() isnt '' | |
label = { | |
forInput: jQuery(@).val() | |
labelText: jQuery(@).text() | |
} | |
currentView.filterLabels.push label | |
@currentView = currentView | |
this | |
events: | |
"submit form": "noop" | |
# "click #search": "applyFilters" | |
"change .filter-top-level": "addFilterTypeAhead" | |
addFilterTypeAhead: (event) -> | |
el = jQuery(event.target) | |
parentUl = jQuery(el).parents('ul.filter-row:first') | |
unless el.val() is '' | |
for label in @currentView.filterLabels #Make sure the label exists, then create the type-ahead | |
if label["forInput"] is el.val() | |
filter = new PlacementFilterTypeAhead({id: el.val(), name: el.val(), label: label["labelText"]}) | |
view = new PlacementFilterTypeAheadView(model: filter) | |
newFilterLi = view.render().el | |
filterInput = jQuery(newFilterLi).find('input') | |
parentUl.append newFilterLi | |
filterInput.tokenInput tokenSource, | |
preventDuplicates: true | |
theme: "rounded" | |
onAdd: (token) -> | |
window.currentView.applyFilters() | |
filterInput.focus() | |
el.attr('value', '') # Reset the select box | |
true #propegate event | |
applyFilters: -> | |
console.log jQuery(@el).find("#filters").serialize() | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment