Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Move the add_exercise to the workout-manager file

Roland Geider38196ee8fc71
diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.js
index bc31d5f34..46431b233 100644
--- a/manager/static/js/workout-manager.js
+++ b/manager/static/js/workout-manager.js
@@ -252,9 +252,40 @@ function init_ingredient_autocompleter()
}
+/*
+ * Returns a random hex string. This is useful, e.g. to add a unique ID to generated
+ * HTML elements
+ */
function hex_random()
{
return Math.floor(
Math.random() * 0x10000 /* 65536 */
).toString(16);
-}
\ No newline at end of file
+}
+
+
+/*
+ * Template-like function that adds form elements to the ajax exercise selection
+ * in the edit set page
+ */
+function add_exercise(exercise)
+{
+ result_div = '<div id="DIV-ID" class="ajax-exercise-select"> \
+<a href="#"> \
+<img src="/static/images/icons/status-off.svg" \
+ width="14" \
+ height="14" \
+ alt="Delete"> \
+</a> EXERCISE \
+<input type="hidden" name="exercises" value="EXCERCISE-ID"> \
+</div>';
+
+ // Replace the values into the 'template'
+ result_div = result_div.replace('DIV-ID', hex_random());
+ result_div = result_div.replace('EXERCISE', exercise.value);
+ result_div = result_div.replace('EXCERCISE-ID', exercise.id);
+
+ $(result_div).prependTo("#exercise-search-log");
+ $("#exercise-search-log").scrollTop(0);
+}
+
diff --git a/manager/templates/set/edit.html b/manager/templates/set/edit.html
index 5e60e56f2..6b9fa58a4 100644
--- a/manager/templates/set/edit.html
+++ b/manager/templates/set/edit.html
@@ -15,26 +15,6 @@
<script src="{% static 'js/workout-manager.js' %}"></script>
<script>
-function add_exercise(exercise)
-{
- result_div = '<div id="DIV-ID" class="ajax-exercise-select"> \
-<a href="#"> \
-<img src="{% static "images/icons/status-off.svg" %}" \
- width="14" \
- height="14" \
- alt="{% trans "Delete" %}"> \
-</a> EXERCISE \
-<input type="hidden" name="exercises" value="EXCERCISE-ID"> \
-</div>';
-
- // Replace the values into the 'template'
- result_div = result_div.replace('DIV-ID', hex_random());
- result_div = result_div.replace('EXERCISE', exercise.value);
- result_div = result_div.replace('EXCERCISE-ID', exercise.id);
-
- $(result_div).prependTo("#exercise-search-log");
- $("#exercise-search-log").scrollTop(0);
-}
$(document).ready(function() {