Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use modal dialogs in the mobile version as well

Roland Geider3d06c45d937e
diff --git a/wger/config/templates/language/overview.html b/wger/config/templates/language/overview.html
index b2da9d2a6..c48ffba7a 100644
--- a/wger/config/templates/language/overview.html
+++ b/wger/config/templates/language/overview.html
@@ -29,7 +29,7 @@
{% block sidebar %}
<h3>{% trans "Options" %}</h3>
<p>
- <a href="{% url 'config:language-add' %}" {% auto_link_css flavour %}>
+ <a href="{% url 'config:language-add' %}" {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/folder-new.svg' %}"
width="32"
height="32"
diff --git a/wger/core/static/js/workout-manager-mobile.js b/wger/core/static/js/workout-manager-mobile.js
index a0028e063..e54026431 100644
--- a/wger/core/static/js/workout-manager-mobile.js
+++ b/wger/core/static/js/workout-manager-mobile.js
@@ -8,21 +8,6 @@
"use strict";
-/*
- * Open a modal dialog for form editing
- */
-function form_modal_dialog() {
- // Unbind all other click events so we don't do this more than once
- $(".modal-dialog").off();
-
- // Load the edit dialog when the user clicks on an edit link
- $(".modal-dialog").click(function (e) {
- e.preventDefault();
- window.location.href = $(this).attr("href");
- });
-}
-
-
/*
* Handle external links with a Web Activity when in Firefox OS
*/
diff --git a/wger/core/static/js/workout-manager.js b/wger/core/static/js/workout-manager.js
index 361c4d93c..23b4c9083 100644
--- a/wger/core/static/js/workout-manager.js
+++ b/wger/core/static/js/workout-manager.js
@@ -209,22 +209,26 @@ function form_modal_dialog() {
e.preventDefault();
var targetUrl = $(this).attr("href");
+ // It's not possible to have more than one modal open at any time, so close them
+ $('.modal').modal('hide');
+
// Show a loader while we fetch the real page
$("#ajax-info-content").html('<div style="text-align:center;">' +
'<img src="/static/images/loader.svg" ' +
'width="48" ' +
'height="48"> ' +
'</div>');
- //$("#wger-ajax-info").modal({title: 'Loading...'});
+ $("#ajax-info-title").html('Loading...');
$("#wger-ajax-info").modal("show");
$("#ajax-info-content").load(targetUrl + " .form-horizontal",
function(responseText, textStatus, XMLHttpRequest){
// Initialise datepickers for any date input
+ if (typeof $.datepicker !== "undefined") {
$('#ajax-info-content input[type="date"]').datepicker({autoclose: true,
- language: $('html').attr('lang'),
- });
+ language: $('html').attr('lang')});
+ }
if (textStatus == "error") {
$("#ajax-info-title").html("Sorry but an error occured")
@@ -238,7 +242,20 @@ function form_modal_dialog() {
}
// Set the new title
- $("#ajax-info-title").html($(responseText).find("#page-title").html());
+ var modal_title = '';
+ if ($(responseText).find("#page-title").length > 0) {
+ // Complete HTML page
+ modal_title = $(responseText).find("#page-title").html();
+ console.log('aaaa');
+ console.log(modal_title);
+ }
+ else {
+ // Page fragment
+ modal_title = $(responseText).filter("#page-title").html();
+ console.log('bbbb');
+ console.log(modal_title);
+ }
+ $("#ajax-info-title").html(modal_title);
// If there is a form in the modal dialog (there usually is) prevent the submit
// button from submitting it and do it here with an AJAX request. If there
diff --git a/wger/core/templates/base_empty.html b/wger/core/templates/base_empty.html
new file mode 100644
index 000000000..79c5b1716
--- /dev/null
+++ b/wger/core/templates/base_empty.html
@@ -0,0 +1,23 @@
+{% block template %}
+<h2 id="page-title" class="page-header">{% block title %}{% endblock %}</h2>
+<div class="row">
+ <div class="col-sm-8" id="main-content">
+ {% if messages and not no_messages %}
+ {% for message in messages %}
+ <div class="alert {% if message.tags == 'warning'%}alert-error{% elif message.tags == 'info' %}alert-info{% elif message.tags == 'success' %}alert-success{% endif %}">
+ <a href="#" class="close extra-bold" data-dismiss="alert">&times;</a>
+ {{message}}
+ </div>
+ {% endfor %}
+ {% endif %}
+
+ <div id="content">
+ {% block content %}{% endblock %}
+ </div>
+ </div>
+ <div class="col-sm-4" id="main-sidebar">
+ {% block sidebar %}
+ {% endblock %}
+ </div>
+</div>
+{% endblock %}
diff --git a/wger/core/templates/delete.html b/wger/core/templates/delete.html
index f4d06387e..91f5a0a8b 100644
--- a/wger/core/templates/delete.html
+++ b/wger/core/templates/delete.html
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends extend_template %}
{% load i18n %}
{% load staticfiles %}
{% load wger_extras %}
diff --git a/wger/core/templates/form.html b/wger/core/templates/form.html
index 4d3e9c85f..9f3e1e238 100644
--- a/wger/core/templates/form.html
+++ b/wger/core/templates/form.html
@@ -1,4 +1,4 @@
-{% extends "base.html" %}
+{% extends extend_template %}
{% load i18n %}
{% load staticfiles %}
{% load wger_extras %}
diff --git a/wger/core/templates/mobile/template.html b/wger/core/templates/mobile/template.html
index e92b6f3f3..8297e0ce6 100644
--- a/wger/core/templates/mobile/template.html
+++ b/wger/core/templates/mobile/template.html
@@ -42,7 +42,6 @@
<script src="{% static 'js/jquery.js' %}" type="text/javascript"></script>
<script src="{% static 'js/jquery-ui.js' %}" type="text/javascript"></script>
<script src="{% static 'js/bootstrap.min.js' %}" type="text/javascript"></script>
- <script src="{% static 'js/bootstrap-datepicker/bootstrap-datepicker.min.js' %}" type="text/javascript"></script>
<script src="{% static 'js/d3.js' %}"></script>
<script src="{% static 'js/workout-manager.js' %}" type="text/javascript"></script>
<script src="{% static 'js/workout-manager-mobile.js' %}" type="text/javascript"></script>
@@ -56,6 +55,9 @@
$('[data-toggle=offcanvas]').click(function () {
$('.row-offcanvas').toggleClass('active')
});
+
+ // Init the modal dialog for editing forms
+ form_modal_dialog();
});
</script>
{% endcompress %}
diff --git a/wger/core/views/misc.py b/wger/core/views/misc.py
index e5d6d34ce..86ebb3077 100644
--- a/wger/core/views/misc.py
+++ b/wger/core/views/misc.py
@@ -157,6 +157,7 @@ class FeedbackClass(FormView):
context['form_action'] = reverse('core:feedback')
context['submit_text'] = _('Send')
context['contribute_url'] = reverse('software:contribute')
+ context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'
return context
def get_form_class(self):
diff --git a/wger/core/views/user.py b/wger/core/views/user.py
index d4ecbb343..e5a637d0e 100644
--- a/wger/core/views/user.py
+++ b/wger/core/views/user.py
@@ -113,6 +113,7 @@ def registration(request):
template_data['form_fields'] = [i for i in form]
template_data['form_action'] = reverse('core:registration')
template_data['submit_text'] = _('Register')
+ template_data['extend_template'] = 'base.html'
return render(request, 'form.html', template_data)
diff --git a/wger/manager/templates/mobile/schedule/view.html b/wger/manager/templates/mobile/schedule/view.html
index 54567713d..211458886 100644
--- a/wger/manager/templates/mobile/schedule/view.html
+++ b/wger/manager/templates/mobile/schedule/view.html
@@ -23,7 +23,7 @@
<a href="{% url 'step-edit' step.id %}"
title="{% trans 'Edit' %}"
- class="btn btn-default btn-block">
+ class="btn btn-default btn-block wger-modal-dialog">
<img src="{% static 'images/icons/edit.svg' %}"
width="22"
height="22"
@@ -58,11 +58,11 @@
</div>
</a>
{% empty %}
- <a href="{% url 'step-add' schedule.id %}" class="list-group-item wger-list-group-item">
+ <a href="{% url 'step-add' schedule.id %}" class="list-group-item wger-list-group-item wger-modal-dialog">
{% trans "No workouts found." %}<br>{% trans "Add one now." %}
</a>
{% endfor %}
- <a href="{% url 'step-add' schedule.id %}" class="list-group-item list-group-item-success">
+ <a href="{% url 'step-add' schedule.id %}" class="list-group-item list-group-item-success wger-modal-dialog">
<span class="glyphicon glyphicon-plus"></span>
{% trans "Add workout" %}
</a>
@@ -99,7 +99,7 @@ than once.{% endblocktrans %}</p>
<p>
<a href="{% url 'schedule-edit' schedule.id %}"
- class="btn btn-default btn-block">
+ class="btn btn-default btn-block wger-modal-dialog">
<img src="{% static 'images/icons/edit.svg' %}"
width="32"
height="32"
@@ -110,7 +110,7 @@ than once.{% endblocktrans %}</p>
<p>
<a href="{% url 'schedule-delete' schedule.id %}"
- class="btn btn-default btn-block">
+ class="btn btn-default btn-block wger-modal-dialog">
<img src="{% static 'images/icons/trash.svg' %}"
width="32"
height="32"
diff --git a/wger/manager/templates/mobile/tags/render_day.html b/wger/manager/templates/mobile/tags/render_day.html
index 71999968f..42c91d384 100644
--- a/wger/manager/templates/mobile/tags/render_day.html
+++ b/wger/manager/templates/mobile/tags/render_day.html
@@ -34,7 +34,7 @@
{% endif %}
<a href="{% url 'day-edit' day.obj.id %}"
title="{% trans 'Edit' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/edit.svg' %}"
width="22"
height="22"
@@ -71,8 +71,8 @@
</div>
<div class="modal-body">
<a href="{% url 'wger.manager.views.set.edit' set.obj.id %}"
- title="{% trans 'Delete' %}"
- {% auto_link_css flavour %}>
+ title="{% trans 'Edit' %}"
+ {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/edit.svg' %}"
width="16"
height="16"
@@ -95,7 +95,7 @@
title="{{ exercise.obj.name }}"
{% auto_link_css flavour %}>
{{ exercise.obj.name }}
- </a>
+ </a>
{% endfor %}
</div>
</div>
diff --git a/wger/manager/templates/mobile/workout/calendar.html b/wger/manager/templates/mobile/workout/calendar.html
index bc1f3750f..37b54fdd2 100644
--- a/wger/manager/templates/mobile/workout/calendar.html
+++ b/wger/manager/templates/mobile/workout/calendar.html
@@ -81,10 +81,10 @@ $(document).ready(function() {
{% if session %}
<a href="{% url 'workout-session-edit' session.pk %}"
- class="btn btn-default btn-block">{% trans "Edit workout session" %}</a>
+ class="btn btn-default btn-block wger-modal-dialog">{% trans "Edit workout session" %}</a>
{% else %}
<a href="{% url 'workout-session-add' first_log.workout_id date|date:'Y' date|date:'m' date|date:'d' %}"
- class="btn btn-default btn-block">{% trans "Add workout impression" %}</a>
+ class="btn btn-default btn-block wger-modal-dialog">{% trans "Add workout impression" %}</a>
{% endif %}
diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.html
index 03c86c18d..3062b395f 100644
--- a/wger/manager/templates/mobile/workout/view.html
+++ b/wger/manager/templates/mobile/workout/view.html
@@ -11,6 +11,13 @@
{% block scripts %}
<script>
+function custom_modal_init()
+{
+ // Set up the edit set functions on modal dialogs
+ init_edit_set();
+}
+
+
$(document).ready(function() {
/*
* Show/Hide the comments to the exercises
@@ -52,7 +59,7 @@ $(document).ready(function() {
{% empty %}
<div class="list-group">
- <a href="{% url 'day-add' workout.id %}" class="list-group-item list-group-item-success">
+ <a href="{% url 'day-add' workout.id %}" class="list-group-item list-group-item-success wger-modal-dialog">
{% trans "No days for this workout." %}<br>
{% trans "Add training day." %}
</a>
@@ -61,7 +68,7 @@ $(document).ready(function() {
<p style="margin-top:2em;">
- <a href="{% url 'day-add' workout.id %}" {% auto_link_css flavour %}>
+ <a href="{% url 'day-add' workout.id %}" {% auto_link_css flavour "wger-modal-dialog" %}>
{% trans "Add training day" %}
</a>
@@ -134,7 +141,7 @@ $(document).ready(function() {
{% trans "View weight log" %}
</a>
-<a href="{% url 'workout-edit' workout.id %}" {% auto_link_css flavour %}>
+<a href="{% url 'workout-edit' workout.id %}" {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/edit.svg' %}"
width="32"
height="32"
@@ -152,7 +159,7 @@ $(document).ready(function() {
{% trans "Export calendar file" %}
</a>
-<a href="{% url 'workout-copy' workout.id %}" {% auto_link_css flavour %}>
+<a href="{% url 'workout-copy' workout.id %}" {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/copy.svg' %}"
width="32"
height="32"
@@ -161,7 +168,7 @@ $(document).ready(function() {
{% trans "Make a copy of this workout" %}
</a>
-<a href="{% url 'workout-delete' workout.id %}" {% auto_link_css flavour %}>
+<a href="{% url 'workout-delete' workout.id %}" {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/trash.svg' %}"
width="32"
height="32"
diff --git a/wger/manager/templates/tags/render_day.html b/wger/manager/templates/tags/render_day.html
index 148f75c06..2c6c2c01f 100644
--- a/wger/manager/templates/tags/render_day.html
+++ b/wger/manager/templates/tags/render_day.html
@@ -113,7 +113,7 @@ $(document).ready(function() {
<tr>
<td colspan="2">
<a href="{% url 'set-add' day.obj.id %}"
- class="wger-modal-dialog btn btn-default btn-block">
+ class="wger-modal-dialog btn btn-default btn-block wger-modal-dialog">
{% trans "No exercises selected for this day." %}
{% trans "Add one now." %}
</a>
diff --git a/wger/manager/views/workout.py b/wger/manager/views/workout.py
index f0b2b7325..94daf8030 100644
--- a/wger/manager/views/workout.py
+++ b/wger/manager/views/workout.py
@@ -167,6 +167,7 @@ def copy_workout(request, pk):
template_data['form_action'] = reverse('workout-copy', kwargs={'pk': workout.id})
template_data['form_fields'] = [workout_form['comment']]
template_data['submit_text'] = _('Copy')
+ template_data['extend_template'] = 'base_empty.html' if request.is_ajax() else 'base.html'
return render(request, 'form.html', template_data)
diff --git a/wger/nutrition/templates/mobile/plan/view.html b/wger/nutrition/templates/mobile/plan/view.html
index a61dce73c..3f5ca0367 100644
--- a/wger/nutrition/templates/mobile/plan/view.html
+++ b/wger/nutrition/templates/mobile/plan/view.html
@@ -63,7 +63,7 @@ $(document).ready(function() {
</a>
<a href="{% url 'meal-edit' meal.id %}"
title="{% trans 'Edit' %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/edit.svg' %}"
width="22"
height="22"
@@ -195,7 +195,7 @@ $(document).ready(function() {
</div>
{% empty %}
<a href="{% url 'meal-add' plan.id %}"
- data-role="button">
+ {% auto_link_css flavour "wger-modal-dialog" %}>
{% trans "No meals for this plan." %}<br>
{% trans "Add one now." %}
</a>
@@ -203,7 +203,7 @@ $(document).ready(function() {
<p style="margin-top:2em;">
<a href="{% url 'meal-add' plan.id %}"
- {% auto_link_css flavour %}>{% trans "Add a new meal" %}</a>
+ {% auto_link_css flavour "wger-modal-dialog" %}>{% trans "Add a new meal" %}</a>
</p>
@@ -345,7 +345,7 @@ $(document).ready(function() {
</a>
<a href="{% url 'nutrition-edit' plan.id %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/edit.svg' %}"
width="32"
height="32"
@@ -363,7 +363,7 @@ $(document).ready(function() {
</a>
<a href="{% url 'nutrition-delete' plan.id %}"
- {% auto_link_css flavour %}>
+ {% auto_link_css flavour "wger-modal-dialog" %}>
<img src="{% static 'images/icons/trash.svg' %}"
width="32"
height="32"
diff --git a/wger/utils/generic_views.py b/wger/utils/generic_views.py
index e6901ba7e..cb9946e3f 100644
--- a/wger/utils/generic_views.py
+++ b/wger/utils/generic_views.py
@@ -142,6 +142,10 @@ class WgerFormMixin(ModelFormMixin, WgerPermissionMixin):
# Text used in the submit button
context['submit_text'] = self.submit_text
+ # Template to extend. For AJAX requests we don't need the rest of the
+ # template, only the form
+ context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'
+
return context
def dispatch(self, request, *args, **kwargs):
@@ -245,6 +249,10 @@ class WgerDeleteMixin(ModelFormMixin, WgerPermissionMixin):
# Additional delete message
context['delete_message'] = self.delete_message
+ # Template to extend. For AJAX requests we don't need the rest of the
+ # template, only the form
+ context['extend_template'] = 'base_empty.html' if self.request.is_ajax() else 'base.html'
+
return context
def dispatch(self, request, *args, **kwargs):