From bce9473f2c678014d93aaab4d0d1896e6ed7e84b Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Tue, 26 Jun 2012 18:06:31 +0200 Subject: [PATCH] Added update button for recipe. --- public/index.html | 1 + public/scripts/controller.coffee | 26 ++++++++++++++++---------- recipes/1 | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/public/index.html b/public/index.html index cd1fea6..15eaa47 100644 --- a/public/index.html +++ b/public/index.html @@ -34,6 +34,7 @@

BrewGear

Terug

BrewGear

+ Update
diff --git a/public/scripts/controller.coffee b/public/scripts/controller.coffee index bcd29d9..75a11b8 100644 --- a/public/scripts/controller.coffee +++ b/public/scripts/controller.coffee @@ -111,6 +111,7 @@ class BrewGear.Controller.Recipe extends BaseRecipeController constructor: -> super @delegateEvent BrewGear.Model.BeerStyle, ev, @renderBeerStyle for ev in ['refresh', 'change'] + @delegateEvent @el, 'click a.update', 'update' # Modify existing recipe: @modify = true if @id @@ -128,7 +129,7 @@ class BrewGear.Controller.Recipe extends BaseRecipeController @log "find style for #{style}" BrewGear.Model.BeerStyle.findByAttribute('name', style) - update: => + updateRecipe: => if @isModified form = @form.get(0) @model.updateAttributes @@ -138,19 +139,23 @@ class BrewGear.Controller.Recipe extends BaseRecipeController plannedOg: parseFloat form.plannedOg.value plannedFg: parseFloat form.plannedFg.value targetVolume: parseFloat form.targetVolume.value - @log "updated #{@model}" + @log "updated #{@model}" - back: => - super - @update() if @modify + update: (event) => + @log 'updating' + event.preventDefault() + event.stopPropagation() + @updateRecipe() + false submit: (event) => - @update() + @updateRecipe() super # Delay a little and go to the details screen - setTimeout => - window.location.hash = "/recipes/#{@id}" - , 20 + unless @modify + setTimeout => + window.location.hash = "/recipes/#{@id}" + , 20 false render: => @@ -191,8 +196,9 @@ class BrewGear.Controller.Fermentables extends BaseRecipeController render: => @name = @model.name @list.empty() - console.log ' model: ' + @model.fermentables + @log ' model: ', @model.fermentables for i, fermentable of @model.fermentables + @log 'Add fermentable', fermentable.source.name ctx = new BrewGear.Logic.MaltPercentage @model, fermentable @list.append @template.tmpl name: fermentable.source.name diff --git a/recipes/1 b/recipes/1 index e71f38c..797fde8 100644 --- a/recipes/1 +++ b/recipes/1 @@ -1 +1 @@ -{"name":"MyBeer","batch":"34","style":{"name":"Blond","description":"Hooggegist, meestal met nagisting op fles","gravity":[1053,1068],"alcohol":[6,7.4],"attenuation":[80,85],"ibu":[15,30],"co2g":[0.39,0.74],"co2v":[2,3.8],"ph":[4.1,4.4],"class":"C","id":"c-40"},"plannedOg":1.06,"plannedFg":1.01,"fermentables":[{"source":{"name":"Tarwemout donker","yield":0.8007,"moisture":0.04,"ebc":31,"category":"Dingemans","id":"c-3"},"amount":2520.433689086088}],"hops":[],"targetVolume":20,"id":"1"} \ No newline at end of file +{"name":"MyBeer","batch":"34","style":{"name":"Blond","description":"Hooggegist, meestal met nagisting op fles","gravity":[1053,1068],"alcohol":[6,7.4],"attenuation":[80,85],"ibu":[15,30],"co2g":[0.39,0.74],"co2v":[2,3.8],"ph":[4.1,4.4],"class":"C","id":"c-40"},"plannedOg":1.06,"plannedFg":1.01,"fermentables":[{"source":{"name":"Tarwemout donker","yield":0.8007,"moisture":0.04,"ebc":31,"category":"Dingemans","id":"c-3"},"amount":2520.433689086088}],"hops":[],"targetVolume":21,"id":"1"} \ No newline at end of file