From 1c042b860bd952167b9be8bc2aff1f573176eab0 Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Fri, 19 Jul 2019 21:09:51 -0600 Subject: [PATCH] Javascript for handling mash steps --- src/humulus/static/recipes.js | 59 ++++++++++++++++++++++ src/humulus/templates/recipes/_macros.html | 4 +- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/humulus/static/recipes.js b/src/humulus/static/recipes.js index c105df7..1053f65 100644 --- a/src/humulus/static/recipes.js +++ b/src/humulus/static/recipes.js @@ -90,6 +90,11 @@ function removeHop() { removeForm($(this), '.hop-form', '#hops'); } +// Remove a mash step +function removeMashStep() { + removeForm($(this), '.mash-form', '#mash'); +} + // Add a fermentable function addFerm() { var $fermsDiv = $('#ferms'); @@ -212,6 +217,58 @@ function addHop() { rebindChangeEvents(); } +// Add a new mash step +function addMashStep() { + var $mashDiv = $('#mash'); + var stepsLength = $mashDiv.data('length'); + if (stepsLength == 20) { + window.alert("Can't have more than 20 mash steps."); + return; + } + + var newStep = `
` + + '
' + + // Step Name Field + `` + + `` + + '
' + // End Step Name field + // Type field + '
' + + `` + + `' + + '
' + // End Type field + // Temperature field + '
' + + `` + + `` + + '
' + // End temperature field + //Time field + '
' + + `` + + `` + + '
' + // End time field + // Amount field + '
' + + `` + + `` + + '
' + // End amount field + '
' + + '' + + '
'; + + $mashDiv.append(newStep); + $('.rem-step').unbind('click'); + $('.rem-step').click(removeMashStep); +} + // Calculate recipe's original gravity function calculateOG() { var fermsLength = $('#ferms').data('length'); @@ -414,6 +471,8 @@ $(document).ready(function() { $('.rem-ferm').click(removeFerm); $('#add-hop').click(addHop); $('.rem-hop').click(removeHop); + $('#add-step').click(addMashStep); + $('.rem-step').click(removeMashStep); // Register change events rebindChangeEvents(); diff --git a/src/humulus/templates/recipes/_macros.html b/src/humulus/templates/recipes/_macros.html index 19b37e6..59d88ef 100644 --- a/src/humulus/templates/recipes/_macros.html +++ b/src/humulus/templates/recipes/_macros.html @@ -134,10 +134,10 @@ function getSpecsURL() { Mash & Steps -#}

Mash

-
+
{{ render_field_with_errors(form.mash.form.name, 'form-control-sm') }} {% for step in form.mash.form.steps %} -
+
{{ render_field_with_errors(step.form.name, 'form-control-sm') }}
{{ render_field_with_errors(step.form.type, 'custom-select-sm', base_class='custom-select') }}