Created
October 29, 2014 13:11
-
-
Save Verkalets/5948fc0b47b3e5dd82d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 App.Views.Expences extends Backbone.View | |
template: HandlebarsTemplates['app/templates/expences'] | |
events: | |
'click a#new_expence': 'newExpence' | |
initialize: -> | |
@listenTo @collection, 'reset', @render | |
@listenTo App.Vent, 'expence:create', @addToCollection | |
@listenTo @collection, 'add', @renderExpence | |
@collection.fetch({ reset: true }) | |
newExpence: (e) -> | |
e.preventDefault() | |
App.Vent.trigger "expence:new" | |
item = $('#list_item').html() | |
$('#ml').html(item) | |
addToCollection: (model) -> | |
@collection.add model | |
templateUrl = document.URL.toString().substr(document.URL.toString().indexOf("es/") + 3).split("/edit")[0] | |
render: -> | |
@$el.html(@template()) | |
filtered_collection = @collection.where({ template_id: templateUrl}) | |
filtered_collection.forEach @renderExpence, @ | |
@ | |
renderExpence: (model) -> | |
v = new App.Views.Expence({ model: model}) | |
@$('ul').append(v.render().el) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment