5f450b3ed3ed085ea8e82ef574f68fb48dd6b271
1 /*******************************************************************************
3 *******************************************************************************/
5 /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */
6 function charger_valeurs_point(implantation_id
) {
7 var params
= {'implantation_id' : implantation_id
};
8 var chargement_vp
= $
.getJSON('/dae/liste_valeurs_point', params
);
9 chargement_vp
.success(function(data
) {
13 $
.each(data
, function() {
14 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
17 $
("#id_valeur_point_min").html(options
);
18 $
("#id_valeur_point_max").html(options
);
19 alert("Les valeurs de point on été ajustées en fonction de cette implantation.");
23 /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction
24 est appelée À chaque modification du formulaire de classement. */
25 function recalculer_ligne(element
) {
26 var ligne
= element
.parents("tr");
27 var inputs
= ligne
.find("input, select");
29 var valeur_point_input
;
30 inputs
.each(function() {
32 if (input
.attr('id').match('id_coefficient*')) {
33 coeff
= clean_float(input
.val())
35 if (input
.attr('id').match('id_valeur_point*')) {
36 valeur_point_input
= input
;
38 if (input
.attr('id').match('id_salaire*')) {
39 salaire_input
= input
;
40 salaire
= clean_float(input
.val())
42 if (input
.attr('id').match('id_indemn*')) {
43 indemn
= clean_float(input
.val())
45 if (input
.attr('id').match('id_autre*')) {
46 autre
= clean_float(input
.val())
51 /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
52 valeur_point_text
= valeur_point_input
.find(":selected").text();
53 if (valeur_point_text
== "")
56 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
58 salaire
= clean_float(valeur_point
* coeff
);
59 salaire_input
.val(salaire
);
61 taux_euro
= clean_float(ligne
.find(".taux").html())
63 total
= salaire
+ indemn
+ autre
;
64 total_euro
= total
* taux_euro
;
66 ligne
.find(".total-devise").text(total
.toFixed(2));
67 ligne
.find(".total-euro").text(total_euro
.toFixed(2));
71 /* recalcule tout le classement */
72 function recalculer_tout() {
73 $
("#classement tr *[name*=devise]").each(function() {
74 recalculer_ligne($
(this));
78 $
(document
).ready(function() {
80 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
82 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
83 var implantation_id
= $
("#id_implantation").val();
84 $
("#id_implantation").change(function() {
85 var implantation_id
= this.value
;
86 charger_valeurs_point(implantation_id
);
90 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
91 var vp_input
= $
(this);
92 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
94 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
95 chargement_devise
.success(function(data
) {
96 var selects
= ligne
.find("select");
97 selects
.each(function() {
99 if (s
.attr('id').match('id_devise*'))
101 ligne
.find(".taux").text(data
.taux_euro
)
102 ligne
.find(".devise_code").text(data
.devise_code
)
105 /* on synchronise les valeurs de points */
106 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
108 if (vp
.val() != vp_input
.val()) {
109 vp
.val(vp_input
.val())
115 chargement_devise
.error(function(data
) {
116 alert(data
.responseText
);
121 $
('#id_devise_min, #id_devise_max').change(function(e
) {
123 var ligne
= input
.parents("tr");
124 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
125 chargement_devise
.success(function(data
) {
126 ligne
.find(".taux").text(data
.taux_euro
)
127 ligne
.find(".devise_code").text(data
.devise_code
)
128 recalculer_ligne(input
);
130 chargement_devise
.error(function(data
) {
131 alert(data
.responseText
);
132 ligne
.find(".taux").text(0)
133 ligne
.find(".devise_code").text("???")
138 $
('#id_classement_min, #id_classement_max').change(function(e
) {
139 var classement
= $
(this);
140 var ligne
= classement
.parents("tr");
141 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement
.val()});
142 chargement_coeff
.success(function(data
){
143 var inputs
= ligne
.find("input");
144 inputs
.each(function() {
146 if (input
.attr('id').match('id_coefficient*'))
147 input
.val(data
.coefficient
);
149 recalculer_ligne(classement
);
151 chargement_coeff
.error(function(data
){
155 /* refresh des totaux à chaque changement quelconque */
156 $
('#classement input, #classement select').change(function() {
157 recalculer_ligne($
(this));
160 /* au chargement, on calcule tout */