Created
January 15, 2013 18:04
-
-
Save VinSpee/4540553 to your computer and use it in GitHub Desktop.
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
21class CalculatorView extends Backbone.View | |
el: "[data-content=calculator]" | |
events: | |
"click [data-action=calculate]": "showResult" | |
initialize: -> | |
@model.bind "change:active", @render, @ | |
render: -> | |
data = {} | |
compiledTemplate = _.template CalculatorTemplate, data | |
@$el.append compiledTemplate | |
hideView: -> | |
console.log "hide calculator" | |
do @$el.hide | |
showView: -> | |
console.log "show calculator" | |
do @$el.show | |
showResult: (e) -> | |
do e.preventDefault | |
userData = {} | |
userData.accountId = @model.id | |
userData.pricee = $("[data-input=price-e85]").val() | |
userData.priceg = $("[data-input=price-gas]").val() | |
userData.mpge = $("[data-input=mpg-e85]").val() | |
userData.mpgg = $("[data-input=mpg-gas]").val() | |
result = new CalculationModel userData | |
result.save().then => | |
resultsView = new ResultsView model: result | |
do resultsView.render | |
do @hideView | |
@listenTo resultsView, 'retry', @showView | |
return CalculatorView |
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
21class ResultsView extends Backbone.View | |
el: "[data-content=results]" | |
template: _.template ResultsTemplate | |
events: | |
"click [data-action=retry]": "retryCalculation" | |
destroyView: -> | |
#COMPLETELY UNBIND THE VIEW | |
do @undelegateEvents | |
do @$el.removeData().unbind | |
do @$el.hide | |
#Remove view from DOM | |
#do @remove | |
#Backbone.View.prototype.remove.call @ | |
console.log "kill result" | |
render: -> | |
console.log "show result" | |
do @model.fetch | |
@$el.html @template @model.toJSON() | |
retryCalculation: -> | |
@trigger "retry" | |
do @destroyView | |
return ResultsView | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment