Private
Public Access
1
0

done manual add and user_analysis_select

This commit is contained in:
2024-01-21 13:41:04 +01:00
parent d6bca69cfa
commit 7b84f659c5
2 changed files with 169 additions and 52 deletions

View File

@@ -14,21 +14,82 @@
</script> </script>
<script> <script>
$( document ).ready(function() { $( document ).ready(function() {
$('#id_workouttype').on('change', function(){ var boattypes = {
if ( '1x': '1x (single)',
$(this).val() == 'water' '2x': '2x (double)',
|| $(this).val() == 'coastal' '2x+': '2x+ (coxed double)',
|| $(this).val() == 'c-boat' '2-': '2- (pair)',
|| $(this).val() == 'churchboat' '2+': '2+ (coxed pair)',
) { '3x+': '3x+ (coxed triple)',
$('#id_boattype').toggle(true); '3x-': '3x- (triple)',
} else { '4x': '4x (quad)',
$('#id_boattype').toggle(false); '4x+': '4x+ (coxed quad)',
$('#id_boattype').val('1x'); '4-': '4- (four)',
} '4+': '4+ (coxed four)',
}); '8+': '8+ (eight)',
$('#id_workouttype').change(); '8x+': '8x+ (octuple scull)',
}); }
var ergtypes = {
'static': 'Concept2 static',
'dynamic': 'Concept2 dynamic',
'slides': 'Concept2 slides',
'rp3': 'RP3',
'waterrower': 'Water Rower',
'other': 'Other Indoor Rower',
}
$('#id_workouttype').on('change', function(){
if (
$(this).val() == 'water'
|| $(this).val() == 'coastal'
|| $(this).val() == 'c-boat'
|| $(this).val() == 'churchboat'
) {
var $el = $('#id_boattype');
$el.empty();
$.each(boattypes, function(key,value) {
if ( key == '{{ workout.boattype }}') {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
} else {
$el.append($("<option></option").attr("value", key).text(value));
}
});
$el.toggle(true);
}
else if (
$(this).val() == 'rower'
) {
var $el = $('#id_boattype');
$el.empty();
$.each(ergtypes, function(key,value) {
if ( key == '{{ workout.boattype }}') {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
} else {
$el.append($("<option></option").attr("value", key).text(value));
}
});
$el.toggle(true);
}
else {
$('#id_boattype').toggle(false);
$('#id_boattype').val('1x');
}
if (
$(this).val() == 'rower'
|| $(this).val() == 'dynamic'
|| $(this).val() == 'slides'
) {
$('#id_dragfactor').toggle(true);
} else {
$('#id_dragfactor').toggle(false);
$('#id_dragfactor').val('0');
}
});
$('#id_workouttype').change();
});
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -17,48 +17,104 @@
<script> <script>
$(function() { $(function() {
// Get the form fields and hidden div // Get the form fields and hidden div
var modality = $("#id_modality"); var modality = $("#id_modality");
var hidden = $("#id_waterboattype"); var hidden = $("#id_waterboattype");
var boattypes = {
'1x': '1x (single)',
'2x': '2x (double)',
'2x+': '2x+ (coxed double)',
'2-': '2- (pair)',
'2+': '2+ (coxed pair)',
'3x+': '3x+ (coxed triple)',
'3x-': '3x- (triple)',
'4x': '4x (quad)',
'4x+': '4x+ (coxed quad)',
'4-': '4- (four)',
'4+': '4+ (coxed four)',
'8+': '8+ (eight)',
'8x+': '8x+ (octuple scull)',
}
var ergtypes = {
'static': 'Concept2 static',
'dynamic': 'Concept2 dynamic',
'slides': 'Concept2 slides',
'rp3': 'RP3',
'waterrower': 'Water Rower',
'other': 'Other Indoor Rower',
}
// Hide the fields. // Hide the fields.
// Use JS to do this in case the user doesn't have JS // Use JS to do this in case the user doesn't have JS
// enabled. // enabled.
hidden.hide(); hidden.hide();
if (modality.val() == 'water') { if (modality.val() == 'water') {
hidden.show(); hidden.show();
} var $el = $('#id_waterboattype');
$el.empty();
$.each(boattypes, function(key,value) {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
});
$el.toggle(true);
} else if (modality.val() == 'rower') {
hidden.show();
var $el = $('#id_waterboattype');
$el.empty();
$.each(ergtypes, function(key,value) {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
});
$el.toggle(true);
}
// Setup an event listener for when the state of the // Setup an event listener for when the state of the
// checkbox changes. // checkbox changes.
modality.change(function() { modality.change(function() {
// Check to see if the checkbox is checked. // Check to see if the checkbox is checked.
// If it is, show the fields and populate the input. // If it is, show the fields and populate the input.
// If not, hide the fields. // If not, hide the fields.
var Value = modality.val(); var Value = modality.val();
var otwtypes = ['water','coastal','c-boat','churchboat'] var otwtypes = ['water','coastal','c-boat','churchboat']
if (otwtypes.includes(Value)) { if (otwtypes.includes(Value)) {
// Show the hidden fields. // Show the hidden fields.
hidden.show(); hidden.show();
} else { var $el = $('#id_waterboattype');
// Make sure that the hidden fields are indeed var $label = $("label[for='"+$el.attr('id') + "']")
// hidden. $el.empty();
hidden.hide(); $.each(boattypes, function(key,value) {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
});
$label.text("Water Boat Type")
$el.toggle(true);
} else if (Value == 'rower') {
hidden.show();
var $el = $('#id_waterboattype');
var $label = $("label[for='"+$el.attr('id') + "']")
$el.empty();
$.each(ergtypes, function(key,value) {
$el.append($("<option></option").attr("value", key).attr("selected", "selected").text(value));
});
$label.text("Erg Boat Type")
$el.toggle(true);
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the // You may also want to clear the value of the
// hidden fields here. Just in case somebody // hidden fields here. Just in case somebody
// shows the fields, enters data to them and then // shows the fields, enters data to them and then
// unticks the checkbox. // unticks the checkbox.
// //
// This would do the job: // This would do the job:
// //
// $("#hidden_field").val(""); // $("#hidden_field").val("");
} }
}); });
}); });