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>
$( document ).ready(function() {
$('#id_workouttype').on('change', function(){
if (
$(this).val() == 'water'
|| $(this).val() == 'coastal'
|| $(this).val() == 'c-boat'
|| $(this).val() == 'churchboat'
) {
$('#id_boattype').toggle(true);
} else {
$('#id_boattype').toggle(false);
$('#id_boattype').val('1x');
}
});
$('#id_workouttype').change();
});
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',
}
$('#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>
{% endblock %}

View File

@@ -16,49 +16,105 @@
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
var hidden = $("#id_waterboattype");
// Get the form fields and hidden div
var modality = $("#id_modality");
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.
// Use JS to do this in case the user doesn't have JS
// enabled.
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
hidden.hide();
if (modality.val() == 'water') {
hidden.show();
}
if (modality.val() == 'water') {
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
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
var otwtypes = ['water','coastal','c-boat','churchboat']
if (otwtypes.includes(Value)) {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
// Setup an event listener for when the state of the
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
var otwtypes = ['water','coastal','c-boat','churchboat']
if (otwtypes.includes(Value)) {
// Show the hidden fields.
hidden.show();
var $el = $('#id_waterboattype');
var $label = $("label[for='"+$el.attr('id') + "']")
$el.empty();
$.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
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});