"use strict"; if (!$) { const $ = django.jQuery; } $(function(){ $('#id_departure').val('1'); $('#id_landing').val('1'); $('#id_rotation').val('0'); $('#id_twist').val('0'); $('#id_is_competitive').prop("checked", true); $('#id_age_boy').val('6'); $('#id_age_girl').val('6'); $('#id_long_label').keyup(function(){ $('#id_short_label').val($('#id_long_label').val()); }); $('#id_rotation_type').keyup(function(){ var rotation_type = parseInt($('#id_rotation_type').children(':selected').val()); if(rotation_type == 0) { $('#id_rotation').val('0'); $('#id_position').val('/'); $('id_twist').focus(); } }); $('#id_rotation, #id_twist').keyup(function(){ setDifficulty(); setLevel(); setNotation(); }); $('#id_position').change(function(){ setDifficulty(); setLevel(); setNotation(); }); $('#id_rotation_type').change(function(){ setNotation(); }); $('#difficulty').change(function(){ setLevel(); }); $('#id_level').keyup(function(){ $('#id_rank').val($('#id_level').val()); }); $('#id_notation').keyup(function(){ $('#id_simplyNotation').val($('#id_notation').val()); }); $('#id_age_boy').keyup(function(){ $('#id_age_girl').val($('#id_age_boy').val()); }); const setDifficulty = function() { if(typeof($('#id_rotation').val()) === "undefined" || typeof($('#id_twist').val()) === "undefined") return console.log('------------------------------------------------------------------------------------------') var sum = 0; var position = $('#id_position').val(); var nb_twist = parseInt($('#id_twist').val()); var nb_rotation = parseInt($('#id_rotation').val()); if(nb_rotation != '' && nb_rotation != 0) { sum = nb_rotation; /* calcul de base */ sum += Math.floor(nb_rotation/4); /* Bonus pour les saltos simple */ sum += Math.floor(nb_rotation/12); /* Bonus pour un triple */ sum += Math.floor(nb_rotation/16); /* Bonus pour un quadruple */ } if(nb_twist != '' && nb_twist != 0) sum += nb_twist; /* pour les simples sans vrille OU les multiples : bonus de position */ if ((nb_rotation == 4 && nb_twist == 0) || nb_rotation > 4) if(position == '/' || position == '<' || position == 'L') sum += Math.floor(nb_rotation/4); $('#id_difficulty').val((sum/10).toFixed(1)); }; const setLevel = function() { var level = 0; if(typeof($('#id_difficulty').val()) !== "undefined" && $('#id_difficulty').val() != '') { level = (parseFloat($('#id_difficulty').val())) * 10; if($('#id_position').val() == '/') level += 1; $('#id_level').val(level); $('#id_rank').val(level); } } const setNotation = function() { var rotation_type = parseInt($('#id_rotation_type').children(':selected').val()); var nb_rotation = parseInt($('#id_rotation').val()); var nb_twist = parseInt($('#id_twist').val()); var txt = ''; if((rotation_type.length != 0) && (rotation_type != 0) && (nb_rotation != 0) && !isNaN(nb_rotation)) { if(rotation_type == 1) txt += '.' + nb_rotation; else txt += nb_rotation + '.'; txt += ' '; if(nb_twist != 0) { var size = Math.ceil(nb_rotation/4); var temp = new Array(size); var digit = Math.floor(nb_twist/size); var rest = (size - (nb_twist % size)) - 1; for(var i = 0; i < size; i++) if(i > rest) temp[i] = digit + 1; else temp[i] = (digit == 0) ? '-' : digit; txt += temp.join(""); } else for(var i = 1; i <= Math.ceil(nb_rotation/4); i++) txt += '-'; if($('#id_position option:selected').val() != 0) txt += ' ' + $('#id_position option:selected').val(); $('#id_notation').val(txt); $('#id_simplified_notation').val(txt); } else { $('#id_notation').val('-'); $('#id_simplified_notation').val('-'); } }; // $('#position, #arrivalid').change(function(){ // var position = $('#position option:selected').val(); // // Création du nom long // // var txt = $('#figureid option:selected').attr('longLabel'); // var txt = $('#savedLongLabel').val(); // if((position.length != 0) && (position != "NULL")) // txt += ' '+$('#position option:selected').attr('data-longLabel'); // // $('#arrivalid').children(':selected') // plus rapide // if($('#arrivalid option:selected').attr('data-shortLabel') != "Debout") // txt += ', '+$('#arrivalid option:selected').attr('data-longLabel'); // $('#longLabel').val(txt); // // Création du nom court // // txt = $('#figureid option:selected').attr('shortLabel'); // txt = $('#savedShortLabel').val(); // if((position.length != 0) && (position != "NULL")) // txt += ' '+$('#position option:selected').attr('data-shortLabel'); // if($('#arrivalid option:selected').attr('data-shortLabel') != "Debout") // txt += ', '+$('#arrivalid option:selected').attr('data-shortLabel'); // $('#shortLabel').val(txt); // setNotation(); // setDifficulty(); // setLevel(); // }); // $('#arrivalid').change(function(){ // if($('#arrivalid option:selected').attr('competition') == 0) // $('#divCompetition').addClass("hide"); // else // $('#divCompetition').removeClass("hide"); // }); });