khana/static/js/skill.js

175 lines
5.6 KiB
JavaScript

if (!$) {
$ = django.jQuery;
}
$(function(){
$('#id_longLabel').keyup(function(){
$('#id_shortLabel').val($('#id_longLabel').val());
});
$('#id_rotationType').keyup(function(){
var rotationtype = parseInt($('#id_rotationType').children(':selected').val());
if(rotationtype == 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_rotationType').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_ageBoy').keyup(function(){
$('#id_age_girl').val($('#id_age_boy').val());
});
setDifficulty = function()
{
var sum = 0;
if(typeof($('#id_rotation').val()) !== "undefined" && $('#id_rotation').val() != "") {
// calcul de base
var nbrotation = parseInt($('#id_rotation').val());
sum = nbrotation;
// calcul des boni
sum += Math.floor(nbrotation/4); /* Bonus pour les saltos simple */
sum += Math.floor(nbrotation/12); /* Bonus pour un triple */
sum += Math.floor(nbrotation/16); /* Bonus pour un quadruple */
/* pour les simples SANS vrille ou les multiples */
if ((nbrotation != 4) && ((typeof($('#id_twist').val()) !== "undefined") || ($('#id_twist').val() != '') || (parseInt($('#id_twist').val()) != 0)))
/* Bonus de position */
if($('#id_position').val() == '/' || $('#id_position').val() == '<' || $('#id_position').val() == 'L')
sum += Math.floor(nbrotation/4);
}
if(typeof($('#id_twist').val()) !== "undefined" && $('#id_twist').val() != '')
sum += parseInt($('#id_twist').val());
$('#id_difficulty').val((sum/10).toFixed(1));
};
setLevel = function()
{
var difficulty = 0;
if(typeof($('#id_difficulty').val()) !== "undefined" && $('#id_difficulty').val() != '') {
difficulty = (parseFloat($('#id_difficulty').val())) * 10;
if($('#id_position').val() == '/')
difficulty += 1;
$('#id_level').val(difficulty);
$('#id_rank').val(difficulty);
}
}
setNotation = function()
{
var rotationtype = parseInt($('#id_rotationType').children(':selected').val());
var nbrotation = parseInt($('#id_rotation').val());
var nbtwist = parseInt($('#id_twist').val());
if((rotationtype.length != 0) && (rotationtype != 0) && (nbrotation != 0)) {
if(rotationtype == 1)
txt = '.'+nbrotation;
else
txt = nbrotation+'.';
txt += ' ';
if(nbtwist != 0) {
var size = Math.ceil(nbrotation/4);
var temp = new Array(size);
var digit = Math.floor(nbtwist/size);
var rest = (size - (nbtwist % 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(nbrotation/4); i++)
txt += '-';
if($('#id_position option:selected').val() != 0)
txt += ' ' + $('#id_position option:selected').val();
$('#id_notation').val(txt);
$('#id_simplyNotation').val(txt);
} else {
$('#id_notation').val('-');
$('#id_simplyNotation').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");
// });
});