1 /*******************************************************************************
3 *******************************************************************************/
5 /* filter les postes en fonction de l'implantation choisie */
6 function charger_postes(implantation_id
) {
7 var selected
= $
("#id_poste :selected").val();
8 var params
= {'implantation_id' : implantation_id
};
9 var chargement_p
= $
.getJSON('/dae/liste_postes', params
);
10 chargement_p
.success(function(data
) {
14 $
.each(data
, function(index
) {
16 if (data
[index][0] == selected
)
17 select
= " selected=selected ";
18 options
+= '<option ' + select
+ ' value="' + data
[index][0] + '">' + data
[index][1] + '</option>';
21 $
("#id_poste").html(options
);
25 /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */
26 function charger_valeurs_point(implantation_id
) {
27 var params
= {'implantation_id' : implantation_id
};
28 var chargement_vp
= $
.getJSON('/dae/liste_valeurs_point', params
);
29 chargement_vp
.success(function(data
) {
33 $
.each(data
, function() {
34 options
+= '<option value="' + this.id
+ '">' + this.label
+ '</option>';
37 $
("#id_valeur_point_min").html(options
);
38 $
("#id_valeur_point_max").html(options
);
39 alert("Les valeurs de point et les postes ont été ajustés en fonction de cette implantation.");
43 /* Calcul des totaux dans les 2 devises, selon les champs sélectionnés. Cette fonction
44 est appelée À chaque modification du formulaire de classement. */
45 function recalculer_ligne(element
) {
46 var ligne
= element
.parents("tr");
47 var inputs
= ligne
.find("input, select");
49 var valeur_point_input
;
50 inputs
.each(function() {
53 if (input
.attr('id').match('id_classement*')) {
54 classement_id
= input
.val();
56 if (input
.attr('id').match('id_valeur_point*')) {
57 valeur_point_input
= input
;
59 if (input
.attr('id').match('id_salaire*')) {
60 salaire_input
= input
;
61 salaire
= clean_float(input
.val())
63 if (input
.attr('id').match('id_indemn*')) {
64 indemn
= clean_float(input
.val())
66 if (input
.attr('id').match('id_autre*')) {
67 autre
= clean_float(input
.val())
72 var chargement_coeff
= $
.getJSON("/dae/coefficient", {'classement': classement_id
});
73 chargement_coeff
.success(function(data
){
74 coeff
= data
.coefficient
;
76 /* on suggère un salaire de base en fonction du coefficient et de la valeur du point */
77 valeur_point_text
= valeur_point_input
.find(":selected").text();
78 if (valeur_point_text
== "")
81 valeur_point
= clean_float(valeur_point_text
.split(" ")[0]);
83 salaire
= clean_float(valeur_point
* coeff
);
84 salaire_input
.val(salaire
);
86 taux_euro
= clean_float(ligne
.find(".taux").html())
88 total
= salaire
+ indemn
+ autre
;
89 total_euro
= total
* taux_euro
;
91 ligne
.find(".total-devise").text(total
.toFixed(2));
92 ligne
.find(".total-euro").text(total_euro
.toFixed(2));
97 /* recalcule tout le classement */
98 function recalculer_tout() {
99 $
("#classement tr *[name*=devise]").each(function() {
100 recalculer_ligne($
(this));
104 $
(document
).ready(function() {
106 /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le
107 poste chargé dans la view (grâce à son id dans l'URL).*/
108 $
('#id_poste').change(function() {
109 window
.location
= '/dae/poste/' + $
(this).val();
112 /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été
114 Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */
115 var implantation_id
= $
("#id_implantation").val();
116 $
("#id_implantation").change(function() {
117 var implantation_id
= this.value
;
118 charger_postes(implantation_id
);
119 charger_valeurs_point(implantation_id
);
123 $
('#id_valeur_point_min, #id_valeur_point_max').change(function(e
) {
124 var vp_input
= $
(this);
125 var ligne
= vp_input
.parents("tr").parent(); // en fait on travaille sur tout le tableau dans ce cas!
127 var chargement_devise
= $
.getJSON("/dae/devise", {'valeur_point': this.value
});
128 chargement_devise
.success(function(data
) {
129 var selects
= ligne
.find("select");
130 selects
.each(function() {
132 if (s
.attr('id').match('id_devise*'))
134 ligne
.find(".taux").text(data
.taux_euro
)
135 ligne
.find(".devise_code").text(data
.devise_code
)
138 /* on synchronise les valeurs de points */
139 $
('#id_valeur_point_min, #id_valeur_point_max').each(function() {
141 if (vp
.val() != vp_input
.val()) {
142 vp
.val(vp_input
.val())
148 chargement_devise
.error(function(data
) {
149 alert(data
.responseText
);
154 $
('#id_devise_min, #id_devise_max').change(function(e
) {
156 var ligne
= input
.parents("tr");
157 var chargement_devise
= $
.getJSON("/dae/devise/code", {'devise': this.value
});
158 chargement_devise
.success(function(data
) {
159 ligne
.find(".taux").text(data
.taux_euro
)
160 ligne
.find(".devise_code").text(data
.devise_code
)
161 recalculer_ligne(input
);
163 chargement_devise
.error(function(data
) {
164 alert(data
.responseText
);
165 ligne
.find(".taux").text(0)
166 ligne
.find(".devise_code").text("???")
171 $
('#id_classement_min, #id_classement_max').change(function(e
) {
172 var classement
= $
(this);
173 recalculer_ligne(classement
);
176 /* refresh des totaux à chaque changement quelconque */
177 $
('#classement input, #classement select').change(function() {
178 recalculer_ligne($
(this));
181 /* au chargement, on calcule tout */
184 /* calcul de la différence en mois */
185 $
("#id_date_debut, #id_date_fin").focusout(function() {
190 /* on charge les postes reliés à cette implantation */
191 charger_postes($
("#id_implantation :selected").val());