Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Added update button for recipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Jun 26, 2012
1 parent 506ae69 commit bce9473
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/index.html
Expand Up @@ -34,6 +34,7 @@ <h1>BrewGear</h1>
<header data-role="header">
<a href="#" data-rel="back" data-role="button" data-mini="true" data-icon="back" data-direction="reverse" data-theme="b">Terug</a>
<h1>BrewGear</h1>
<a class="update" href="#" data-role="button" data-mini="true" data-icon="refresh" data-theme="b">Update</a>
</header>

<div data-role="content">
Expand Down
26 changes: 16 additions & 10 deletions public/scripts/controller.coffee
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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: =>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion 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"}
{"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"}

0 comments on commit bce9473

Please sign in to comment.