Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Move some JS to external file, hide links to PDF in Firefox OS

Roland Geiderdadb3bb53db8
diff --git a/wger/exercises/templates/mobile/muscles/overview.html b/wger/exercises/templates/mobile/muscles/overview.html
index 963e5207a..c4da7c6fa 100644
--- a/wger/exercises/templates/mobile/muscles/overview.html
+++ b/wger/exercises/templates/mobile/muscles/overview.html
@@ -10,42 +10,14 @@
{% block title %}{% trans "Muscle overview" %}{% endblock %}
-{% block header %}
+{% block header %}{% endblock %}
+
+
+{% block scripts %}
<script>
+$( document ).off("pageinit").on("pageinit", function() {
+ console.log('Pageinit muscle list');
-function highlight_muscle(element)
-{
- var div_id = $(element).data('target');
- var is_front = ($(element).data('isFront') == 'True') ? 'front' : 'back';
- var muscle_id = div_id.match(/\d+/);
- var muscle_name = $(element).data('name');
-
- // Reset all other highlighted muscles
- $('.muscle').removeClass('muscle-active');
- $('.muscle').addClass('muscle-inactive');
-
- // Hightligh the current one
- $(element).removeClass('muscle-inactive');
- $(element).addClass('muscle-active');
-
- {% if perms.exercises %}
- $('#muscle-edit-box').show();
- $('.muscle-edit-name').html(muscle_name);
- $('#muscle-edit-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/edit/");
- $('#muscle-delete-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/delete/");
- {% endif %}
-
- // Set the corresponding background
- $('#muscle-system').css('background-image',
- 'url(/static/images/muscles/main/muscle-' + muscle_id + '.svg),'
- + 'url(/static/images/muscles/muscular_system_' + is_front + '.svg)');
-
- // Show the corresponding exercises
- $('.exercise-list').hide();
- $('#' + div_id).show();
-}
-
-$(document).on('pageinit', function(){
//Prefetch the background images
{% for muscle in muscle_list|first %}
prefetch_images(['/static/images/muscles/main/muscle-' + {{muscle.id}} + '.svg']);
@@ -54,12 +26,12 @@ $(document).on('pageinit', function(){
// Hightlight the first element
- highlight_muscle($('.muscle').first());
+ highlight_muscle($('.muscle').first(), {%if perms.exercises%}true{%else%}false{%endif%});
// Highlight on tap
$('.muscle').on( "tap", function(e) {
e.preventDefault();
- highlight_muscle(this);
+ highlight_muscle(this, {%if perms.exercises%}true{%else%}false{%endif%});
});
});
</script>
diff --git a/wger/exercises/templates/muscles/overview.html b/wger/exercises/templates/muscles/overview.html
index 36c0b8c45..e19a29271 100644
--- a/wger/exercises/templates/muscles/overview.html
+++ b/wger/exercises/templates/muscles/overview.html
@@ -12,39 +12,6 @@
{% block header %}
<script>
-
-function highlight_muscle(element)
-{
- var div_id = $(element).data('target');
- var is_front = ($(element).data('isFront') == 'True') ? 'front' : 'back';
- var muscle_id = div_id.match(/\d+/);
- var muscle_name = $(element).data('name');
-
- // Reset all other highlighted muscles
- $('.muscle').removeClass('muscle-active');
- $('.muscle').addClass('muscle-inactive');
-
- // Hightligh the current one
- $(element).removeClass('muscle-inactive');
- $(element).addClass('muscle-active');
-
- {% if perms.exercises %}
- $('#muscle-edit-box').show();
- $('.muscle-edit-name').html(muscle_name);
- $('#muscle-edit-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/edit/");
- $('#muscle-delete-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/delete/");
- {% endif %}
-
- // Set the corresponding background
- $('#muscle-system').css('background-image',
- 'url(/static/images/muscles/main/muscle-' + muscle_id + '.svg),'
- + 'url(/static/images/muscles/muscular_system_' + is_front + '.svg)');
-
- // Show the corresponding exercises
- $('.exercise-list').hide();
- $('#' + div_id).show();
-}
-
$(document).ready(function() {
//Prefetch the background images
{% for muscle in muscle_list|first %}
@@ -54,12 +21,12 @@ $(document).ready(function() {
// Hightlight the first element
- highlight_muscle($('.muscle').first());
+ highlight_muscle($('.muscle').first(), {%if perms.exercises%}true{%else%}false{%endif%});
// Highlight on hover
$('.muscle').hover(function(e) {
e.preventDefault();
- highlight_muscle(this);
+ highlight_muscle(this, {%if perms.exercises%}true{%else%}false{%endif%});
});
});
</script>
diff --git a/wger/manager/static/js/workout-manager.js b/wger/manager/static/js/workout-manager.js
index c1433a740..753f47b63 100644
--- a/wger/manager/static/js/workout-manager.js
+++ b/wger/manager/static/js/workout-manager.js
@@ -965,3 +965,40 @@ function prefetch_images(imageArray)
});
}
+
+
+/*
+ * Highlight a muscle in the overview
+ */
+function highlight_muscle(element, perms_exercises)
+{
+ var div_id = $(element).data('target');
+ var is_front = ($(element).data('isFront') == 'True') ? 'front' : 'back';
+ var muscle_id = div_id.match(/\d+/);
+ var muscle_name = $(element).data('name');
+
+ // Reset all other highlighted muscles
+ $('.muscle').removeClass('muscle-active');
+ $('.muscle').addClass('muscle-inactive');
+
+ // Hightligh the current one
+ $(element).removeClass('muscle-inactive');
+ $(element).addClass('muscle-active');
+
+ if (perms_exercises)
+ {
+ $('#muscle-edit-box').show();
+ $('.muscle-edit-name').html(muscle_name);
+ $('#muscle-edit-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/edit/");
+ $('#muscle-delete-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/delete/");
+ }
+
+ // Set the corresponding background
+ $('#muscle-system').css('background-image',
+ 'url(/static/images/muscles/main/muscle-' + muscle_id + '.svg),'
+ + 'url(/static/images/muscles/muscular_system_' + is_front + '.svg)');
+
+ // Show the corresponding exercises
+ $('.exercise-list').hide();
+ $('#' + div_id).show();
+}
\ No newline at end of file
diff --git a/wger/manager/templates/mobile/index.html b/wger/manager/templates/mobile/index.html
index 7b2808f1b..881aa1883 100644
--- a/wger/manager/templates/mobile/index.html
+++ b/wger/manager/templates/mobile/index.html
@@ -12,12 +12,9 @@
<p>
<a href="{% url 'wger.manager.views.workout.view' current_workout.id %}"
data-role="button"
- data-mini="true">
- {% if current_workout.comment %}
- {{ current_workout.comment }}
- {% else %}
- {% trans "Workout" %}
- {% endif %}
+ data-mini="true"
+ data-ajax="false">
+ {{ current_workout }}
</a>
</p>
– {{ current_workout.creation_date }}
diff --git a/wger/manager/templates/mobile/workout/log.html b/wger/manager/templates/mobile/workout/log.html
index 8d1126765..7346f9fd7 100644
--- a/wger/manager/templates/mobile/workout/log.html
+++ b/wger/manager/templates/mobile/workout/log.html
@@ -6,16 +6,20 @@
{% block title %}{% trans "Weight log for workout" %}{% endblock %}
-{% block header %}
+
+{% block header %}{% endblock %}
+
+
+{% block scripts %}
<script type="text/javascript">
$(document).on('pageinit', function(){
// Init the data toggle for the weight log tables
toggle_weight_log_table();
});
-
</script>
{% endblock %}
+
{% block content %}
{% if workout.comment %}
<p>
@@ -52,14 +56,14 @@ $(document).on('pageinit', function(){
-->
- {% for exercise, date_list in exercise_log.items %}
+ {% for exercise, date_list in exercise_log.items %}
<ul data-role="listview"
style="margin-top: 3em;">
<li>
<a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>
</li>
</ul>
-
+
{% if date_list.log_by_date %}
{% with list=date_list.log_by_date %}
{% render_weight_log list date_list.div_uuid %}
@@ -116,5 +120,4 @@ entry.{% endblocktrans %}</p>
<p>{% blocktrans %}If on a single day there is more than one entry with the
same number of repetitions, but different weights, only the entry with the
higher weight is shown in the diagram.{% endblocktrans %}</p>
-
{% endblock %}
diff --git a/wger/manager/templates/mobile/workout/overview.html b/wger/manager/templates/mobile/workout/overview.html
index ee48ffd5e..56a626cef 100644
--- a/wger/manager/templates/mobile/workout/overview.html
+++ b/wger/manager/templates/mobile/workout/overview.html
@@ -9,7 +9,7 @@
<ul data-role="listview" data-inset="false">
{% for workout in workouts %}
<li>
- <a href="{% url 'wger.manager.views.workout.view' workout.id %}">
+ <a href="{% url 'wger.manager.views.workout.view' workout.id %}" data-ajax="false">
<h3>{{ workout }}</h3>
<p>{{ workout.creation_date }}</p>
</a>
diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.html
index c985fb3a4..aa723792f 100644
--- a/wger/manager/templates/mobile/workout/view.html
+++ b/wger/manager/templates/mobile/workout/view.html
@@ -6,27 +6,40 @@
{% block title %}{% trans "Workout" %} – {{ workout.creation_date }}{% endblock %}
-{% block header %}
+{% block header %}{% endblock %}
+
+
+{% block scripts %}
<script>
-$(document).on('pageinit', function () {
- // Allow the sets to be sortable
- //setup_sortable();
-
- // Show/Hide the comments to the exercises
- {% if user.userprofile.show_comments %}
- showComment = 1;
+$( document ).off("pageinit").on("pageinit", function() {
+ console.log('Pageinit workout view');
+ /*
+ * Show/Hide the comments to the exercises
+ */
+ {% if user.userprofile.show_comments %}
+ showComment = 1;
$(".exercise-comments").show();
{% else %}
- showComment = 0;
+ showComment = 0;
$(".exercise-comments").hide();
{% endif %}
-
- toggle_comments();
- });
+ toggle_comments();
+
+ /*
+ * At the moment (Oct. 2013), firefox OS has no possibility to download
+ * authenticated files, like these PDFs: when using web activities, we
+ * can only pass the PDF's URL to the reader but this will fail, since that
+ * application is not authenticated.
+ */
+ if(typeof MozActivity != 'undefined') {
+ $(".pdf-button").remove();
+ }
+});
</script>
{% endblock %}
-{% block content %}
+
+{% block content %}
{% if workout.comment %}
<p>
<span class="dimmed">{{workout.comment}}</span>
@@ -132,8 +145,7 @@ $(document).on('pageinit', function () {
</a>
<a href="{% url 'workout-log' workout.id %}"
- data-role="button"
- data-ajax="false">
+ data-role="button">
<img src="{% static 'images/icons/statistics.svg' %}"
width="32"
height="32"
diff --git a/wger/nutrition/templates/mobile/plan/view.html b/wger/nutrition/templates/mobile/plan/view.html
index bf24a2e4f..94948c7d8 100644
--- a/wger/nutrition/templates/mobile/plan/view.html
+++ b/wger/nutrition/templates/mobile/plan/view.html
@@ -26,6 +26,16 @@ $(document).ready(function() {
useEnglishIngredients = 0;
$('#english-ingredients-status').attr("src", "{% static 'images/icons/status-off.svg' %}");
{% endif %}
+
+ /*
+ * At the moment (Oct. 2013), firefox OS has no possibility to download
+ * authenticated files, like these PDFs: when using web activities, we
+ * can only pass the PDF's URL to the reader but this will fail, since that
+ * application is not authenticated.
+ */
+ if(typeof MozActivity != 'undefined') {
+ $(".pdf-button").remove();
+ }
});
</script>
{% endblock %}
@@ -279,8 +289,8 @@ $(document).ready(function() {
<h3>{% trans "Options" %}</h3>
<a href="{% url 'wger.nutrition.views.plan.export_pdf' plan.id %}"
- target="_blank"
- data-role="button">
+ class="pdf-button">
+ data-role="button"
<img src="{% static 'images/icons/save.svg' %}"
width="32"
height="32"