Self hosted FLOSS fitness/workout, nutrition and weight tracker
Move the add set form to the bootstrap design
Roland Geider2187525699bf
diff --git a/wger/manager/forms.py b/wger/manager/forms.pyindex 4c233d60e..5e26e52fc 100644--- a/wger/manager/forms.py+++ b/wger/manager/forms.py@@ -30,6 +30,7 @@ from django.utils.translation import ugettext as _from captcha.fields import ReCaptchaFieldfrom wger.exercises.models import Exercise+from wger.exercises.models import ExerciseCategoryfrom wger.manager.models import WorkoutSessionfrom wger.manager.models import Workoutfrom wger.manager.models import Day@@ -37,6 +38,7 @@ from wger.manager.models import Setfrom wger.manager.models import Settingfrom wger.manager.models import WorkoutLogfrom wger.utils.widgets import TranslatedSelectMultiple+from wger.utils.widgets import TranslatedSelectfrom wger.utils.widgets import ExerciseAjaxSelectfrom wger.utils.constants import DATE_FORMATSfrom wger.utils.widgets import Html5DateInput@@ -87,6 +89,10 @@ class SetFormMobile(ModelForm):'''Don't use the autocompleter when accessing the mobile version'''+ categories_list = ModelChoiceField(ExerciseCategory.objects,+ empty_label=_('All categories'),+ label=_('Categories'),+ widget=TranslatedSelect())exercise_list = ModelChoiceField(Exercise.objects)class Meta:@@ -94,7 +100,7 @@ class SetFormMobile(ModelForm):exclude = ('order', 'exerciseday')# We need to overwrite the init method here because otherwise Django- # will outut a default help text, regardless of the widget used+ # will output a default help text, regardless of the widget used# https://code.djangoproject.com/ticket/9321def __init__(self, *args, **kwargs):super(SetFormMobile, self).__init__(*args, **kwargs)diff --git a/wger/manager/models.py b/wger/manager/models.pyindex 1370dc356..9d6849a3a 100644--- a/wger/manager/models.py+++ b/wger/manager/models.py@@ -473,7 +473,7 @@ class Set(models.Model):Model for a set of exercises'''DEFAULT_SETS = 4- MAX_SETS = 7+ MAX_SETS = 10exerciseday = models.ForeignKey(Day,verbose_name=_('Exercise day'))diff --git a/wger/manager/templates/mobile/set/add.html b/wger/manager/templates/mobile/set/add.htmlindex 21f95c32f..f69d68f9a 100644--- a/wger/manager/templates/mobile/set/add.html+++ b/wger/manager/templates/mobile/set/add.html@@ -1,7 +1,5 @@{% extends "base.html" %}-{% load i18n %}-{% load staticfiles %}-{% load wger_extras %}+{% load i18n staticfiles wger_extras %}<!--@@ -16,12 +14,57 @@-->{% block header %}<script>-$(document).on('pageinit', function(){+$(document).ready(function() {init_edit_set();// Slider to set the number of sets- $( "#id_sets" ).on( "slidestop", function(event, ui) {+ $("#id_sets").on("change", function() {+update_all_exercise_formset();+ $('#id_sets_value').html($("#id_sets").val());+ });+++ // Update the exercise list when the categories change+ $("#id_categories_list").on("change", function() {++ // Remember to filter by exercise language+ $.get('/api/v2/language/?short_name=' + get_current_language(), function(data){+ var language_pk = data.results[0].id;+ var category_pk = $("#id_categories_list").val();+ var base_url = '/api/v2/exercise/';+ var filter = '?limit=999&language=' + language_pk;++ if (category_pk != '') {+ filter += '&category=' + category_pk;+ }++ $.get(base_url + filter, function(data){++ // Sort the results by name, at the moment it's not possible+ // to search and sort the API at the same time+ data.results.sort(function(a, b) {+ if (a.name < b.name) {+ return -1;+ }+ if (a.name > b.name) {+ return 1;+ }+ return 0+ });++ // Remove existing options+ $('#id_exercise_list')+ .find('option')+ .remove();++ // ..and add the new ones+ $("#id_exercise_list").append(new Option('---------', ''));+ $.each(data.results, function(index, exercise) {+ $("#id_exercise_list").append(new Option(exercise.name, exercise.id));+ });+ });+ });});});</script>@@ -35,48 +78,48 @@ $(document).on('pageinit', function(){<form action="{{form_action}}"method="post">-{% csrf_token %}-<table>+ {% csrf_token %}+ {% render_form_field form.categories_list %}{% render_form_field form.exercise_list %}- <tr>- <td colspan="2">- <div id="exercise-search-log"></div>- </td>- </tr>- <tr>- <td style="text-align:right;width:40%;">- <label for="id_sets">{{form.sets.label}}</label>- </td>- <td>- <input name="sets" id="id_sets" min="1" max="10" value="{{ form.sets.value }}" type="range">- </td>- </tr>- <tr>- <td colspan="2">- <p class="dimmed">{% blocktrans %}If you do the same repetitions for all sets,+ <div class="form-group">+ <div class="col-md-offset-3 col-md-9">+ <div id="exercise-search-log"></div>+ </div>+ </div>++ <div div class="form-group">+ <div class="col-md-3">+ <label for="id_sets" class="control-label">+ {{form.sets.label}}+ - <span id="id_sets_value">{{ form.sets.value }}</span>+ </label>+ </div>+ <div class="col-md-9">+ <input name="sets"+ id="id_sets"+ min="1"+ max="10"+ value="{{ form.sets.value }}"+ type="range"+ class="form-control">+ </div>+ </div>+ <div div class="form-group">+ <div class="col-md-3">+ <span class="text-muted">{% blocktrans %}If you do the same repetitions for all sets,you can just enter one value: e.g. for 4 sets just enter one "10" for the repetitions, this-automatically becomes "4 x 10".{% endblocktrans %}</p>- </td>- </tr>+automatically becomes "4 x 10".{% endblocktrans %}</span>+ </div>+ </div>+- <tr>- <td colspan="2">- <div id="formsets">+ <div div class="form-group">+ <div class="col-md-3" id="formsets">{% for formset in formsets %}{% include 'set/formset.html' with exercise=formset.exercise formset=formset.formset %}{% endfor %}- </div>- </td>- </tr>- <tr>- <td colspan="2">- <a href="{% url 'core:index' %}"- data-role="button"- data-rel="back"- data-mini="true">{% trans "Cancel" %}</a>- <input type="submit" value="{% trans 'Save' %}" id="form-save">- </td>- </tr>-</table>+ </div>+ </div>+ {% render_form_submit %}</form>{% endblock %}\ No newline at end of file