Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add an argument to the URL, generated with javascript.

Roland Geidera0a6b1217c9d
diff --git a/nutrition/templates/edit_meal_item.html b/nutrition/templates/edit_meal_item.html
index 89dbc395d..1ecb140e0 100644
--- a/nutrition/templates/edit_meal_item.html
+++ b/nutrition/templates/edit_meal_item.html
@@ -23,7 +23,7 @@ $(document).ready(function() {
<h2>{% trans "Edit meal" %}</h2>
-<form action="{% url nutrition.views.edit_meal_item plan.id meal.id meal_item.id%}"
+<form action="{% url nutrition.views.edit_meal_item plan.id meal.id meal_item.id%}{% if js_active %}?js=on{% endif %}"
method="post"
class="ym-form">
{% csrf_token %}
@@ -31,12 +31,13 @@ $(document).ready(function() {
<table>
{% include "form_snippet.html" with field=form.amount_gramm %}
{% include "form_snippet.html" with field=form.amount_freetext %}
- {% comment %}
- {% include "form_snippet.html" with field=form.ingredient css_class="ym-fbox-select" %}
- {% endcomment %}
+ {% if js_active %}
+ <input type="hidden" id="id_ingredient" name="ingredient">
+ {% include "form_snippet.html" with field=form.ingredient_freetext %}
+ {% else %}
+ {% include "form_snippet.html" with field=form.ingredient css_class="ym-fbox-select" %}
+ {% endif %}
- <input type="hidden" id="id_ingredient" name="ingredient">
- {% include "form_snippet.html" with field=form.ingredient_freetext %}
<tr>
<td><input type="submit" value="{% trans "Save" %}" /></td>
<td></td>
diff --git a/nutrition/templates/view_nutrition_plan.html b/nutrition/templates/view_nutrition_plan.html
index 7fd226bd8..c5bcb99ce 100644
--- a/nutrition/templates/view_nutrition_plan.html
+++ b/nutrition/templates/view_nutrition_plan.html
@@ -16,6 +16,11 @@ function custom_modal_init()
}
$(document).ready(function() {
+
+ $('.edit-meal').each(function(element){
+ $(this).attr('href', $(this).attr('href') + '?js=on')
+ })
+
// Init the modal dialog to open forms in a window
form_modal_dialog();
});
@@ -97,7 +102,7 @@ $(document).ready(function() {
</a>
<a href="{% url nutrition.views.edit_meal_item plan.id meal.id item.id %}"
title="{% trans 'Edit' %}"
- class="modal-dialog">
+ class="modal-dialog edit-meal">
<img src="{% static 'images/icons/edit.svg' %}"
width="16"
height="16"
diff --git a/nutrition/views.py b/nutrition/views.py
index 7af73d7d5..89babf247 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -278,6 +278,11 @@ def edit_meal_item(request, id, meal_id, item_id=None):
template_data['meal_item'] = meal_item
+ # Check that javascript is activated This is used to hide the drop down list with the
+ # ingredients and use the autocompleter version instead. This is not only nicer but also much
+ # faster as the ingredient list from USDA is many thosand entries long.
+ js_active = request.GET.get('js', False)
+ template_data['js_active'] = js_active
# Process request