Commit | Line | Data |
---|---|---|
dfc31755 OL |
1 | /******************************************************************************* |
2 | * EMBAUCHE | |
3 | *******************************************************************************/ | |
66796c1f OL |
4 | function proposition_comparaison(devise_id) { |
5 | var chargement_devise = $.getJSON("/dae/devise/code", {'devise': devise_id}); | |
6 | chargement_devise.success(function(data) { | |
7 | var salaire = $("#id_salaire").val(); | |
8 | var montant = parseFloat(data.taux_euro) * parseFloat(salaire); | |
9 | $("#salaire-propose-euros").html(clean_float(montant)); | |
10 | }); | |
11 | chargement_devise.error(function(data) { | |
12 | alert(data.responseText); | |
13 | }); | |
14 | } | |
dfc31755 | 15 | |
179f6b49 OL |
16 | function activateDossierDropDowns() { |
17 | $('#id_classement, #id_devise').change(loadSalaire); | |
18 | } | |
19 | ||
20 | function loadSalaire() { | |
66796c1f | 21 | $.getJSON('/dae/salaire/' + $('#implantation').val() + '/' + |
179f6b49 OL |
22 | $('#id_devise').val() + '/' + $('#id_classement').val(), |
23 | function(data) { | |
66796c1f OL |
24 | $('#id_salaire').val(clean_float(data.salaire_devise)); |
25 | $('#id_salaire').trigger('change'); | |
179f6b49 OL |
26 | }); |
27 | } | |
28 | ||
29 | function round2(n) { | |
30 | return Math.round(n * 100) / 100; | |
31 | } | |
32 | ||
57bd966c OL |
33 | function remun_totaux() { |
34 | var total_cout = 0; | |
35 | $("tr.cout td.cumulable").each(function() { | |
36 | total_cout += clean_float($(this).html()); | |
37 | }); | |
38 | $("#sous-total-cout").html(total_cout); | |
39 | ||
40 | var total_aide = 0; | |
41 | $("tr.aide td.cumulable").each(function() { | |
42 | total_aide += clean_float($(this).html()); | |
43 | }); | |
44 | $("#sous-total-aide").html(total_aide); | |
45 | ||
46 | var total = total_cout - total_aide; | |
47 | $("#remun-total").html(total); | |
48 | ||
49 | } | |
50 | ||
179f6b49 OL |
51 | $('#global-cost input[id^="montant"]').live('keyup', function() { |
52 | var value = $(this).val(), | |
53 | idParts = $(this).attr('id').split('-'), | |
54 | name = idParts[0], | |
55 | id = idParts[1]; | |
56 | if (name == 'montant') { | |
57 | $('#montant_mois-' + id).val(round2(value / 12)); | |
58 | } else { | |
59 | value = value * 12; | |
60 | $('#montant-' + id).val(round2(value)); | |
61 | } | |
62 | var taux = $('#taux_devise-' + id).val(); | |
057763bc OL |
63 | $('#montant_euro_mois-' + id).text(clean_float(round2(value / taux / 12))); |
64 | $('#montant_euro-' + id).text(clean_float(round2(value / taux))); | |
57bd966c | 65 | remun_totaux(); |
179f6b49 OL |
66 | }); |
67 | ||
68 | activateDossierDropDowns(); | |
69 | ||
179f6b49 OL |
70 | /* Ajout des datespickers sur les inputs loadés via AJAX. |
71 | On s'assure qu'on est pas dans le cas initial où ils sont déjà ajoutés. | |
72 | (La façon dont c'est fait requiert que les inputs soient uniquement dans la partie AJAX).*/ | |
73 | function datepicker() { | |
74 | var date_pickers = $(".datetimeshortcuts"); | |
75 | if (date_pickers.length == 0) | |
76 | DateTimeShortcuts.init(); | |
77 | } | |
78 | ||
79 | function activateEmployeDropDown() { | |
80 | $('#id_employe').change(loadEmploye); | |
81 | } | |
82 | ||
83 | function loadEmploye() { | |
84 | var employeUrl = '/dae/employe/' + $(this).val(); | |
85 | $('#form-employe').html('<tr><td>Chargement...</td></tr>') | |
86 | .load(employeUrl, activateEmployeDropDown); | |
87 | var dossierUrl = '/dae/dossier/' + $('#poste').val() + | |
88 | '/' + $(this).val(); | |
89 | $('#form-dossier').html('<tr><td>Chargement...</td></tr>') | |
90 | .load(dossierUrl, function() { | |
91 | datepicker(); | |
92 | activateDossierDropDowns(); | |
72db8238 | 93 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() {contrat_mois();}); |
179f6b49 OL |
94 | }); |
95 | } | |
96 | ||
dfc31755 | 97 | $(document).ready(function() { |
179f6b49 OL |
98 | |
99 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le | |
100 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
101 | $('#id_poste').change(function() { | |
102 | window.location = '/dae/embauche/' + $(this).val(); | |
103 | }); | |
104 | ||
105 | /* on lance le JS au chargement de la page, la toute première fois, | |
106 | puis on cable le change au select pour le rechargement. */ | |
72db8238 | 107 | //loadEmploye(); |
179f6b49 OL |
108 | activateEmployeDropDown(); |
109 | ||
72db8238 OL |
110 | /* calcul de la différence en mois */ |
111 | $("#id_contrat_date_debut, #id_contrat_date_fin").focusout(function() { | |
112 | contrat_mois(); | |
113 | }); | |
114 | contrat_mois(); | |
115 | ||
057763bc OL |
116 | /* Ajouter une ligne aux couts globals */ |
117 | $('#type-remun').change(function() { | |
118 | if ($(this).val() != '') { | |
119 | $('#global-cost').html('<tr><td>Chargement...</td></tr>') | |
120 | .load('/dae/add-remun/' + | |
121 | $('#dossier').val() + '/' + | |
122 | $(this).val(), function() { | |
123 | $('#type-remun').val(''); | |
124 | }); | |
125 | } | |
126 | }); | |
57bd966c | 127 | remun_totaux(); |
057763bc OL |
128 | |
129 | ||
dfc31755 | 130 | }); |