Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add an AJAX call to set the preference for ingredients in english
Roland Geider02277a3e6f52
diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.jsindex 92195f958..0e06eb722 100644--- a/manager/static/js/workout-manager.js+++ b/manager/static/js/workout-manager.js@@ -84,6 +84,11 @@ function setup_ajax_set_edit()});}+/*+ *+ * Functions related to the user's preferences+ *+ */function toggle_comments(){$("#exercise-comments-toggle").click(function(e) {@@ -102,9 +107,31 @@ function toggle_comments()}$("#ajax-info").load("/workout/api/user-preferences?do=set_show-comments&show=" + showComment);+ });+}++function set_english_ingredients()+{+ $("#ajax-english-ingredients").click(function(e) {+ e.preventDefault();+++ if ( useEnglishIngredients == 0 )+ {+ $('#english-ingredients-status').html('ON')+ useEnglishIngredients = 1;+ }+ else if ( useEnglishIngredients == 1 )+ {+ $('#english-ingredients-status').html('OFF')+ useEnglishIngredients = 0;+ }++ $("#ajax-info").load("/workout/api/user-preferences?do=set_english-ingredients&show=" + useEnglishIngredients);});}+function setup_inplace_editing(){$(".ajax-form-cancel").each(function(index, element) {diff --git a/manager/views.py b/manager/views.pyindex db20dfc77..cbc24b350 100644--- a/manager/views.py+++ b/manager/views.py@@ -435,6 +435,16 @@ def api_user_preferences(request):profile.save()return HttpResponse(_('Success'))++ # Show ingredients in english+ elif request.GET.get('do') == 'set_english-ingredients':+ new_value = int(request.GET.get('show'))++ profile = request.user.get_profile()+ profile.show_english_ingredients = new_value+ profile.save()++ return HttpResponse(_('Success'))# ************************diff --git a/nutrition/templates/view_nutrition_plan.html b/nutrition/templates/view_nutrition_plan.htmlindex ee6863576..ca48d662f 100644--- a/nutrition/templates/view_nutrition_plan.html+++ b/nutrition/templates/view_nutrition_plan.html@@ -17,6 +17,17 @@ function custom_modal_init()$(document).ready(function() {+ // Check if the user wants to see ingredients in english+ set_english_ingredients();++ {% if user.userprofile.show_english_ingredients %}+ useEnglishIngredients = 1;+ $('#english-ingredients-status').html('ON')+ {% else %}+ useEnglishIngredients = 0;+ $('#english-ingredients-status').html('OFF')+ {% endif %}+// Add a flag indicating we are using javascript. Depending on this we show a drop down list// with the ingredients or use an autocompleter$('.edit-meal').each(function(element){@@ -143,6 +154,13 @@ $(document).ready(function() {</tbody></table>+{% if language.short_name != 'en' %}+ <p>+ {% trans "If you find the ingredient list too short, you might want to activate the preference to also show English ingredients." %}+ <a href="{% url manager.views.preferences %}" id="ajax-english-ingredients">{% trans "That's done here" %}</a>:+ <span id="english-ingredients-status"></span>+ </p>+{% endif %}{% endblock %}diff --git a/nutrition/views.py b/nutrition/views.pyindex b4b35c000..d1dd507ea 100644--- a/nutrition/views.py+++ b/nutrition/views.py@@ -98,6 +98,10 @@ def view(request, id):plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)template_data['plan'] = plan+ # Load the language and pass it to the template+ language = load_language()+ template_data['language'] = language+# Sum the nutrional infonutritional_info = {'energy': 0,'protein': 0,