1 /*******************************************************************************
3 *******************************************************************************/
6 function elements_comparaison(devise_id
) {
7 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': devise_id
});
8 chargement_devise
.success(function(data
) {
12 $
('#elements-comparaison input').each(function() {
14 var montant
= data
.taux_euro
* parseFloat(input
.val());
15 input
.parent().find(".devise_euro").html(clean_float(montant
) + " EUR");
16 input
.parent().find(".devise").html(data
.devise_code
);
19 chargement_devise
.error(function(data
) {
20 alert(data
.responseText
);
24 /* filter les postes en fonction de l'implantation choisie */
25 function charger_postes(implantation_id
) {
26 var selected
= $
("#id_poste :selected").val();
27 var params
= {'implantation_id' : implantation_id
};
28 var chargement_p
= $
.getJSON('/dae/liste_postes', params
);
29 chargement_p
.success(function(data
) {
33 $
.each(data
, function(index
) {
35 if (data
[index][0] == selected
)
36 select
= " selected=selected ";
37 options
+= '<option ' + select
+ ' value="' + data
[index][0] + '">' + data
[index][1] + '</option>';
40 $
("#id_poste").html(options
);
44 /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */
45 function charger_valeurs_point(implantation_id
) {
46 var params
= {'implantation_id' : implantation_id
};
47 var chargement_vp
= $
.getJSON('/dae/liste_valeurs_point', params
);
48 chargement_vp
.success(function(data
) {
52 $
.each(data
, function() {
53 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
56 $
("#id_valeur_point_min").html(options
);
57 $
("#id_valeur_point_max").html(options
);
58 alert("Les valeurs de point et les postes ont été ajustés en fonction de cette implantation.");
62 /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction
63 est appelée À chaque modification du formulaire de classement. */
64 function recalculer_ligne(element
) {
65 var ligne
= element
.parents("tr");
66 var inputs
= ligne
.find("input, select");
68 var valeur_point_input
;
69 inputs
.each(function() {
72 if (input
.attr('id').match('id_classement*')) {
73 classement_id
= input
.val();
75 if (input
.attr('id').match('id_valeur_point*')) {
76 valeur_point_input
= input
;
78 if (input
.attr('id').match('id_salaire*')) {
79 salaire_input
= input
;
80 salaire
= clean_float(input
.val())
82 if (input
.attr('id').match('id_indemn*')) {
83 indemn
= clean_float(input
.val())
85 if (input
.attr('id').match('id_autre*')) {
86 autre
= clean_float(input
.val())
91 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement_id
});
92 chargement_coeff
.success(function(data
){
93 coeff
= data
.coefficient
;
95 /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
96 valeur_point_text
= valeur_point_input
.find(":selected").text();
97 if (valeur_point_text
== "")
100 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
102 salaire
= clean_float(valeur_point
* coeff
);
103 salaire_input
.val(salaire
);
105 taux_euro
= parseFloat(ligne
.find(".taux").html())
107 total
= salaire
+ indemn
+ autre
;
108 total_euro
= total
* taux_euro
;
110 ligne
.find(".total-devise").text(clean_float(total
));
111 ligne
.find(".total-euro").text(clean_float(total_euro
));
116 /* recalcule tout le classement */
117 function recalculer_tout() {
118 $
("#classement tr *[name*=devise]").each(function() {
119 recalculer_ligne($
(this));
123 $
(document
).ready(function() {
125 /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le
126 poste chargé dans la view (grâce à son id dans l'URL).*/
127 $
('#id_poste').change(function() {
128 window
.location
= '/dae/poste/' + $
(this).val();
131 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
133 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
134 var implantation_id
= $
("#id_implantation").val();
135 $
("#id_implantation").change(function() {
136 var implantation_id
= this.value
;
137 charger_postes(implantation_id
);
138 charger_valeurs_point(implantation_id
);
142 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
143 var vp_input
= $
(this);
144 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
146 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
147 chargement_devise
.success(function(data
) {
148 var selects
= ligne
.find("select");
149 selects
.each(function() {
151 if (s
.attr('id').match('id_devise*'))
153 ligne
.find(".taux").text(data
.taux_euro
)
154 ligne
.find(".devise_code").text(data
.devise_code
)
157 /* on synchronise les valeurs de points */
158 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
160 if (vp
.val() != vp_input
.val()) {
161 vp
.val(vp_input
.val())
167 chargement_devise
.error(function(data
) {
168 alert(data
.responseText
);
173 $
('#id_devise_min, #id_devise_max').change(function(e
) {
175 var ligne
= input
.parents("tr");
176 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
177 chargement_devise
.success(function(data
) {
178 ligne
.find(".taux").text(data
.taux_euro
)
179 ligne
.find(".devise_code").text(data
.devise_code
)
180 recalculer_ligne(input
);
182 chargement_devise
.error(function(data
) {
183 alert(data
.responseText
);
184 ligne
.find(".taux").text(0)
185 ligne
.find(".devise_code").text("???")
190 $
('#id_classement_min, #id_classement_max').change(function(e
) {
191 var classement
= $
(this);
192 recalculer_ligne(classement
);
195 /* refresh des totaux à chaque changement quelconque */
196 $
('#classement input, #classement select').change(function() {
197 recalculer_ligne($
(this));
200 /* au chargement, on calcule tout */
203 /* calcul de la différence en mois */
204 $
("#id_date_debut, #id_date_fin").focusout(function() {
209 /* on charge les postes reliés à cette implantation */
210 charger_postes($
("#id_implantation :selected").val());
212 $
('#id_devise_comparaison, #elements-comparaison input').change(function(e
) {
213 elements_comparaison($
('#id_devise_comparaison').val());
215 elements_comparaison($
('#id_devise_comparaison').val());