Self hosted FLOSS fitness/workout, nutrition and weight tracker
Use a drop down list when adding exercises to a set in mobile version
Roland Geiderdb9540e625ad
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.pyindex 32a47bb38..73016a37c 100644--- a/wger/exercises/views/exercises.py+++ b/wger/exercises/views/exercises.py@@ -313,7 +313,7 @@ def search(request):# Perform the searchq = request.GET.get('term', '')- #user_language = load_language()+languages = load_item_languages(LanguageConfig.SHOW_ITEM_EXERCISES)exercises = (Exercise.objects.filter(name__icontains=q).filter(language__in=languages)diff --git a/wger/manager/forms.py b/wger/manager/forms.pyindex d71e9c318..f616eea49 100644--- a/wger/manager/forms.py+++ b/wger/manager/forms.py@@ -132,6 +132,27 @@ class SetForm(ModelForm):self.fields['exercises'].help_text = _('You can search for more than one exercise, ''they will be grouped together for a superset.')+from wger.exercises.models import Exercise+from django.forms import ModelChoiceField+++class SetFormMobile(ModelForm):+ '''+ Don't use the autocompleter when accessing the mobile version+ '''+ exercise_list = ModelChoiceField(Exercise.objects)++ class Meta:+ model = Set++ # We need to overwrite the init method here because otherwise Django+ # will outut a default help text, regardless of the widget used+ # https://code.djangoproject.com/ticket/9321+ def __init__(self, *args, **kwargs):+ super(SetFormMobile, self).__init__(*args, **kwargs)+ self.fields['exercises'].help_text = _('You can search for more than one exercise, '+ 'they will be grouped together for a superset.')+class HelperDateForm(Form):'''diff --git a/wger/manager/static/css/workout-manager.css b/wger/manager/static/css/workout-manager.cssindex 65e5402f6..e4041ec47 100644--- a/wger/manager/static/css/workout-manager.css+++ b/wger/manager/static/css/workout-manager.css@@ -132,6 +132,9 @@ div.muscle-background* 'form-error' is inserted by the JQuery form validator and the styling* is copied from the yaml ones, for consistency*/+.ym-form a {+ color:black;+}.ym-form .form-error {color: #880000;}diff --git a/wger/manager/static/js/workout-manager.js b/wger/manager/static/js/workout-manager.jsindex dde5ac694..c1433a740 100644--- a/wger/manager/static/js/workout-manager.js+++ b/wger/manager/static/js/workout-manager.js@@ -398,6 +398,20 @@ function update_all_exercise_formset()}}+/*+ * Remove the result DIV (also contains the hidden form element) with the exercise+ * formsets when the user clicks on the delete link+ */+function init_remove_exercise_formset()+{+ $(".ajax-exercise-select a").click(function(e) {+ e.preventDefault();+ var exercise_id = $(this).parent('div').find('input').val()+ $('#formset-exercise-'+exercise_id).remove();+ $(this).parent('div').remove();+ });+}+function init_edit_set(){// Initialise the autocompleter (our widget, defined above)@@ -412,14 +426,8 @@ function init_edit_set()// Load formsetsget_exercise_formset(ui.item.id)- // Remove the result div (also contains the hidden form element) when the user- // clicks on the delete link- $(".ajax-exercise-select a").click(function(e) {- e.preventDefault();- var exercise_id = $(this).parent('div').find('input').val()- $('#formset-exercise-'+exercise_id).remove();- $(this).parent('div').remove();- });+ // Init the remove buttons+ init_remove_exercise_formset();// Reset the autocompleter$(this).val("");@@ -427,14 +435,19 @@ function init_edit_set()}});- // Delete button next to exercise- $(".ajax-exercise-select a").click(function(e) {- e.preventDefault();- var exercise_id = $(this).parent('div').find('input').val()- $('#formset-exercise-'+exercise_id).remove();- $(this).parent('div').remove();+ // Mobile select box+ $('#id_exercise_list').change(function(e) {+ var exercise_id = $('#id_exercise_list').val();+ var exercise_name = $('#id_exercise_list').find(":selected").text();+ add_exercise({id: exercise_id,+ value: exercise_name});+ get_exercise_formset(exercise_id);+ init_remove_exercise_formset();});+ // Delete button next to exercise+ init_remove_exercise_formset();+// Slider to set the number of sets$("#slider").slider({range: "min",diff --git a/wger/manager/templates/mobile/set/add.html b/wger/manager/templates/mobile/set/add.htmlindex 4c9e97c8d..f78d29619 100644--- a/wger/manager/templates/mobile/set/add.html+++ b/wger/manager/templates/mobile/set/add.html@@ -33,16 +33,20 @@ $(document).on('pageinit', function(){-->{% block content %}-<form action="{{form_action}}"method="post"class="ym-form">{% csrf_token %}<table>- {% yaml_form_field form.exercises %}+ {% yaml_form_field form.exercise_list %}+ <tr>+ <td colspan="2">+ <div id="exercise-search-log">+ </td>+ </tr><tr>- <td style="text-align:right;">+ <td style="text-align:right;width:40%;"><label for="slider">{{form.sets.label}}</label></td><td>diff --git a/wger/manager/views/set.py b/wger/manager/views/set.pyindex 7a6603488..dae78ab70 100644--- a/wger/manager/views/set.py+++ b/wger/manager/views/set.py@@ -37,7 +37,9 @@ from wger.manager.models import Settingfrom wger.exercises.models import Exercise-from wger.manager.forms import SetForm+from wger.manager.forms import SetForm, SetFormMobile+from wger.utils.language import load_item_languages+from wger.config.models import LanguageConfiglogger = logging.getLogger('wger.custom')@@ -64,13 +66,27 @@ def create(request, day_pk):if day.get_owner_object().user != request.user:return HttpResponseForbidden()+ # Select the correct form depending on the flavour of the request+ if request.flavour == 'mobile':+ form_class = SetFormMobile+ else:+ form_class = SetForm+ form_class = SetFormMobile+context = {}formsets = []- form = SetForm(initial={'sets': Set.DEFAULT_SETS})+ form = form_class(initial={'sets': Set.DEFAULT_SETS})++ # For the mobile dropdown list we need to manually filter the exercises+ # by language and status+ if request.flavour == 'mobile':+ languages = load_item_languages(LanguageConfig.SHOW_ITEM_EXERCISES)+ form.fields['exercise_list'].queryset = Exercise.objects.filter(language__in=languages) \+ .filter(status__in=Exercise.EXERCISE_STATUS_OK)# If the form and all formsets validate, save themif request.method == "POST":- form = SetForm(request.POST)+ form = form_class(request.POST)if form.is_valid():for exercise in form.cleaned_data['exercises']:formset = SettingFormset(request.POST,