2 function clean_float(value
){
3 if (isNaN(value
) || value
== undefined
)
6 output
= parseFloat(value
);
7 output
= Math
.round(output
*100)/100;
11 /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */
12 function charger_valeurs_point(implantation_id
) {
13 var params
= {'implantation_id' : implantation_id
};
14 var chargement_vp
= $
.getJSON('/dae/liste_valeurs_point', params
);
15 chargement_vp
.success(function(data
) {
19 $
.each(data
, function() {
20 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
23 $
("#id_valeur_point_min").html(options
);
24 $
("#id_valeur_point_max").html(options
);
25 alert("Les valeurs de point on été ajustées en fonction de cette implantation.");
29 /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction
30 est appelée À chaque modification du formulaire de classement. */
31 function recalculer_ligne(element
) {
32 var ligne
= element
.parents("tr");
33 var inputs
= ligne
.find("input, select");
35 var valeur_point_input
;
36 inputs
.each(function() {
38 if (input
.attr('id').match('id_coefficient*')) {
39 coeff
= clean_float(input
.val())
41 if (input
.attr('id').match('id_valeur_point*')) {
42 valeur_point_input
= input
;
44 if (input
.attr('id').match('id_salaire*')) {
45 salaire_input
= input
;
46 salaire
= clean_float(input
.val())
48 if (input
.attr('id').match('id_indemn*')) {
49 indemn
= clean_float(input
.val())
51 if (input
.attr('id').match('id_autre*')) {
52 autre
= clean_float(input
.val())
57 /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
58 valeur_point_text
= valeur_point_input
.find(":selected").text();
59 if (valeur_point_text
== "")
62 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
64 salaire
= clean_float(valeur_point
* coeff
);
65 salaire_input
.val(salaire
);
67 taux_euro
= clean_float(ligne
.find(".taux").html())
69 total
= salaire
+ indemn
+ autre
;
70 total_euro
= total
* taux_euro
;
72 ligne
.find(".total-devise").text(total
.toFixed(2));
73 ligne
.find(".total-euro").text(total_euro
.toFixed(2));
77 /* recalcule tout le classement */
78 function recalculer_tout() {
79 $
("#classement tr *[name*=devise]").each(function() {
80 recalculer_ligne($
(this));
84 $
(document
).ready(function() {
86 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
88 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
89 var implantation_id
= $
("#id_implantation").val();
90 $
("#id_implantation").change(function() {
91 var implantation_id
= this.value
;
92 charger_valeurs_point(implantation_id
);
96 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
97 var vp_input
= $
(this);
98 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
100 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
101 chargement_devise
.success(function(data
) {
102 var selects
= ligne
.find("select");
103 selects
.each(function() {
105 if (s
.attr('id').match('id_devise*'))
107 ligne
.find(".taux").text(data
.taux_euro
)
108 ligne
.find(".devise_code").text(data
.devise_code
)
111 /* on synchronise les valeurs de points */
112 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
114 if (vp
.val() != vp_input
.val()) {
115 vp
.val(vp_input
.val())
119 recalculer_ligne(vp_input
);
121 chargement_devise
.error(function(data
) {
122 alert(data
.responseText
);
127 $
('#id_devise_min, #id_devise_max').change(function(e
) {
129 var ligne
= input
.parents("tr");
130 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
131 chargement_devise
.success(function(data
) {
132 ligne
.find(".taux").text(data
.taux_euro
)
133 ligne
.find(".devise_code").text(data
.devise_code
)
134 recalculer_ligne(input
);
136 chargement_devise
.error(function(data
) {
137 alert(data
.responseText
);
138 ligne
.find(".taux").text(0)
139 ligne
.find(".devise_code").text("???")
144 $
('#id_classement_min, #id_classement_max').change(function(e
) {
145 var classement
= $
(this);
146 var ligne
= classement
.parents("tr");
147 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement
.val()});
148 chargement_coeff
.success(function(data
){
149 var inputs
= ligne
.find("input");
150 inputs
.each(function() {
152 if (input
.attr('id').match('id_coefficient*'))
153 input
.val(data
.coefficient
);
155 recalculer_ligne(classement
);
157 chargement_coeff
.error(function(data
){
161 /* refresh des totaux à chaque changement quelconque */
162 $
('#classement input, #classement select').change(function() {
163 recalculer_ligne($
(this));
166 /* au chargement, on calcule tout */