From 25410b227f0543c620328e2a7f9452f5f0af337e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Wed, 13 Apr 2011 14:47:10 -0400 Subject: [PATCH] split JS files --- project/dae/templates/dae/poste.html | 1 + project/media/js/dae-poste.js | 163 ++++++++++++++++++++++++++++++++++ project/media/js/dae.js | 160 --------------------------------- 3 files changed, 164 insertions(+), 160 deletions(-) create mode 100644 project/media/js/dae-poste.js diff --git a/project/dae/templates/dae/poste.html b/project/dae/templates/dae/poste.html index c3759e3..4b05140 100644 --- a/project/dae/templates/dae/poste.html +++ b/project/dae/templates/dae/poste.html @@ -24,6 +24,7 @@ Demande d'autorisation d'embauche {{ form.media }} + ' + this.label + ''; + }); + + $("#id_valeur_point_min").html(options); + $("#id_valeur_point_max").html(options); + alert("Les valeurs de point on été ajustées en fonction de cette implantation."); + }); +} + +/* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction +est appelée À chaque modification du formulaire de classement. */ +function recalculer_ligne(element) { + var ligne = element.parents("tr"); + var inputs = ligne.find("input, select"); + var salaire_input; + var valeur_point_input; + inputs.each(function() { + var input = $(this); + if (input.attr('id').match('id_coefficient*')) { + coeff = clean_float(input.val()) + } + if (input.attr('id').match('id_valeur_point*')) { + valeur_point_input = input; + } + if (input.attr('id').match('id_salaire*')) { + salaire_input = input; + salaire = clean_float(input.val()) + } + if (input.attr('id').match('id_indemn*')) { + indemn = clean_float(input.val()) + } + if (input.attr('id').match('id_autre*')) { + autre = clean_float(input.val()) + } + + }); + + /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */ + valeur_point_text = valeur_point_input.find(":selected").text(); + if (valeur_point_text == "") + valeur_point = 0; + else + valeur_point = clean_float(valeur_point_text.split(" ")[0]); + + salaire = clean_float(valeur_point * coeff); + salaire_input.val(salaire); + + taux_euro = clean_float(ligne.find(".taux").html()) + total = 0; + total = salaire + indemn + autre; + total_euro = total * taux_euro; + + ligne.find(".total-devise").text(total.toFixed(2)); + ligne.find(".total-euro").text(total_euro.toFixed(2)); + +} + +/* recalcule tout le classement */ +function recalculer_tout() { + $("#classement tr *[name*=devise]").each(function() { + recalculer_ligne($(this)); + }); +} + +$(document).ready(function() { + + /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été + sélectionnée. + Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ + var implantation_id = $("#id_implantation").val(); + $("#id_implantation").change(function() { + var implantation_id = this.value; + charger_valeurs_point(implantation_id); + }); + + + $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) { + var vp_input = $(this); + var ligne = vp_input.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas! + + var chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value}); + chargement_devise.success(function(data) { + var selects = ligne.find("select"); + selects.each(function() { + var s = $(this); + if (s.attr('id').match('id_devise*')) + s.val(data.devise) + ligne.find(".taux").text(data.taux_euro) + ligne.find(".devise_code").text(data.devise_code) + }); + + /* on synchronise les valeurs de points */ + $('#id_valeur_point_min, #id_valeur_point_max').each(function() { + var vp = $(this); + if (vp.val() != vp_input.val()) { + vp.val(vp_input.val()) + } + }); + + recalculer_ligne(vp_input); + }); + chargement_devise.error(function(data) { + alert(data.responseText); + }); + + }); + + $('#id_devise_min, #id_devise_max').change(function(e) { + var input = $(this); + var ligne = input.parents("tr"); + var chargement_devise = $.getJSON("/dae/devise/code", {'devise': this.value}); + chargement_devise.success(function(data) { + ligne.find(".taux").text(data.taux_euro) + ligne.find(".devise_code").text(data.devise_code) + recalculer_ligne(input); + }); + chargement_devise.error(function(data) { + alert(data.responseText); + ligne.find(".taux").text(0) + ligne.find(".devise_code").text("???") + }); + + }); + + $('#id_classement_min, #id_classement_max').change(function(e) { + var classement = $(this); + var ligne = classement.parents("tr"); + var chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement.val()}); + chargement_coeff.success(function(data){ + var inputs = ligne.find("input"); + inputs.each(function() { + var input = $(this); + if (input.attr('id').match('id_coefficient*')) + input.val(data.coefficient); + }); + recalculer_ligne(classement); + }); + chargement_coeff.error(function(data){ + }); + }); + + /* refresh des totaux à chaque changement quelconque */ + $('#classement input, #classement select').change(function() { + recalculer_ligne($(this)); + }); + + /* au chargement, on calcule tout */ + recalculer_tout(); + +}); diff --git a/project/media/js/dae.js b/project/media/js/dae.js index 9528e47..7504ecf 100644 --- a/project/media/js/dae.js +++ b/project/media/js/dae.js @@ -7,163 +7,3 @@ function clean_float(value){ output = Math.round(output*100)/100; return output; } - -/* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ -function charger_valeurs_point(implantation_id) { - var params = {'implantation_id' : implantation_id}; - var chargement_vp = $.getJSON('/dae/liste_valeurs_point', params); - chargement_vp.success(function(data) { - var items = []; - - var options = ""; - $.each(data, function() { - options += ''; - }); - - $("#id_valeur_point_min").html(options); - $("#id_valeur_point_max").html(options); - alert("Les valeurs de point on été ajustées en fonction de cette implantation."); - }); -} - -/* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction -est appelée À chaque modification du formulaire de classement. */ -function recalculer_ligne(element) { - var ligne = element.parents("tr"); - var inputs = ligne.find("input, select"); - var salaire_input; - var valeur_point_input; - inputs.each(function() { - var input = $(this); - if (input.attr('id').match('id_coefficient*')) { - coeff = clean_float(input.val()) - } - if (input.attr('id').match('id_valeur_point*')) { - valeur_point_input = input; - } - if (input.attr('id').match('id_salaire*')) { - salaire_input = input; - salaire = clean_float(input.val()) - } - if (input.attr('id').match('id_indemn*')) { - indemn = clean_float(input.val()) - } - if (input.attr('id').match('id_autre*')) { - autre = clean_float(input.val()) - } - - }); - - /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */ - valeur_point_text = valeur_point_input.find(":selected").text(); - if (valeur_point_text == "") - valeur_point = 0; - else - valeur_point = clean_float(valeur_point_text.split(" ")[0]); - - salaire = clean_float(valeur_point * coeff); - salaire_input.val(salaire); - - taux_euro = clean_float(ligne.find(".taux").html()) - total = 0; - total = salaire + indemn + autre; - total_euro = total * taux_euro; - - ligne.find(".total-devise").text(total.toFixed(2)); - ligne.find(".total-euro").text(total_euro.toFixed(2)); - -} - -/* recalcule tout le classement */ -function recalculer_tout() { - $("#classement tr *[name*=devise]").each(function() { - recalculer_ligne($(this)); - }); -} - -$(document).ready(function() { - - /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été - sélectionnée. - Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ - var implantation_id = $("#id_implantation").val(); - $("#id_implantation").change(function() { - var implantation_id = this.value; - charger_valeurs_point(implantation_id); - }); - - - $('#id_valeur_point_min, #id_valeur_point_max').change(function(e) { - var vp_input = $(this); - var ligne = vp_input.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas! - - var chargement_devise = $.getJSON("/dae/devise", {'valeur_point': this.value}); - chargement_devise.success(function(data) { - var selects = ligne.find("select"); - selects.each(function() { - var s = $(this); - if (s.attr('id').match('id_devise*')) - s.val(data.devise) - ligne.find(".taux").text(data.taux_euro) - ligne.find(".devise_code").text(data.devise_code) - }); - - /* on synchronise les valeurs de points */ - $('#id_valeur_point_min, #id_valeur_point_max').each(function() { - var vp = $(this); - if (vp.val() != vp_input.val()) { - vp.val(vp_input.val()) - } - }); - - recalculer_ligne(vp_input); - }); - chargement_devise.error(function(data) { - alert(data.responseText); - }); - - }); - - $('#id_devise_min, #id_devise_max').change(function(e) { - var input = $(this); - var ligne = input.parents("tr"); - var chargement_devise = $.getJSON("/dae/devise/code", {'devise': this.value}); - chargement_devise.success(function(data) { - ligne.find(".taux").text(data.taux_euro) - ligne.find(".devise_code").text(data.devise_code) - recalculer_ligne(input); - }); - chargement_devise.error(function(data) { - alert(data.responseText); - ligne.find(".taux").text(0) - ligne.find(".devise_code").text("???") - }); - - }); - - $('#id_classement_min, #id_classement_max').change(function(e) { - var classement = $(this); - var ligne = classement.parents("tr"); - var chargement_coeff = $.getJSON("/dae/coefficient", {'classement': classement.val()}); - chargement_coeff.success(function(data){ - var inputs = ligne.find("input"); - inputs.each(function() { - var input = $(this); - if (input.attr('id').match('id_coefficient*')) - input.val(data.coefficient); - }); - recalculer_ligne(classement); - }); - chargement_coeff.error(function(data){ - }); - }); - - /* refresh des totaux à chaque changement quelconque */ - $('#classement input, #classement select').change(function() { - recalculer_ligne($(this)); - }); - - /* au chargement, on calcule tout */ - recalculer_tout(); - -}); -- 1.7.10.4