Commit | Line | Data |
---|---|---|
dfc31755 OL |
1 | /******************************************************************************* |
2 | * EMBAUCHE | |
3 | *******************************************************************************/ | |
4 | ||
179f6b49 OL |
5 | function activateDossierDropDowns() { |
6 | $('#id_classement, #id_devise').change(loadSalaire); | |
7 | } | |
8 | ||
9 | function loadSalaire() { | |
10 | $.getJSON('{% url salaire %}/' + $('#implantation').val() + '/' + | |
11 | $('#id_devise').val() + '/' + $('#id_classement').val(), | |
12 | function(data) { | |
13 | $('#id_salaire').val(data.salaire_devise); | |
14 | }); | |
15 | } | |
16 | ||
17 | function round2(n) { | |
18 | return Math.round(n * 100) / 100; | |
19 | } | |
20 | ||
21 | $('#global-cost input[id^="montant"]').live('keyup', function() { | |
22 | var value = $(this).val(), | |
23 | idParts = $(this).attr('id').split('-'), | |
24 | name = idParts[0], | |
25 | id = idParts[1]; | |
26 | if (name == 'montant') { | |
27 | $('#montant_mois-' + id).val(round2(value / 12)); | |
28 | } else { | |
29 | value = value * 12; | |
30 | $('#montant-' + id).val(round2(value)); | |
31 | } | |
32 | var taux = $('#taux_devise-' + id).val(); | |
33 | $('#montant_euro_mois-' + id).text(round2(value / taux / 12)); | |
34 | $('#montant_euro-' + id).text(round2(value / taux)); | |
35 | }); | |
36 | ||
37 | activateDossierDropDowns(); | |
38 | ||
39 | $('#type-remun').change(function() { | |
40 | if ($(this).val() != '') { | |
41 | $('#global-cost').html('<tr><td>Chargement...</td></tr>') | |
42 | .load('{% url add_remun %}/' + | |
43 | $('#dossier').val() + '/' + | |
44 | $(this).val(), function() { | |
45 | $('#type-remun').val(''); | |
46 | }); | |
47 | } | |
48 | }); | |
49 | ||
50 | /* Ajout des datespickers sur les inputs loadés via AJAX. | |
51 | On s'assure qu'on est pas dans le cas initial où ils sont déjà ajoutés. | |
52 | (La façon dont c'est fait requiert que les inputs soient uniquement dans la partie AJAX).*/ | |
53 | function datepicker() { | |
54 | var date_pickers = $(".datetimeshortcuts"); | |
55 | if (date_pickers.length == 0) | |
56 | DateTimeShortcuts.init(); | |
57 | } | |
58 | ||
59 | function activateEmployeDropDown() { | |
60 | $('#id_employe').change(loadEmploye); | |
61 | } | |
62 | ||
63 | function loadEmploye() { | |
64 | var employeUrl = '/dae/employe/' + $(this).val(); | |
65 | $('#form-employe').html('<tr><td>Chargement...</td></tr>') | |
66 | .load(employeUrl, activateEmployeDropDown); | |
67 | var dossierUrl = '/dae/dossier/' + $('#poste').val() + | |
68 | '/' + $(this).val(); | |
69 | $('#form-dossier').html('<tr><td>Chargement...</td></tr>') | |
70 | .load(dossierUrl, function() { | |
71 | datepicker(); | |
72 | activateDossierDropDowns(); | |
73 | }); | |
74 | } | |
75 | ||
dfc31755 | 76 | $(document).ready(function() { |
179f6b49 OL |
77 | |
78 | /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le | |
79 | poste chargé dans la view (grâce à son id dans l'URL).*/ | |
80 | $('#id_poste').change(function() { | |
81 | window.location = '/dae/embauche/' + $(this).val(); | |
82 | }); | |
83 | ||
84 | /* on lance le JS au chargement de la page, la toute première fois, | |
85 | puis on cable le change au select pour le rechargement. */ | |
86 | loadEmploye(); | |
87 | activateEmployeDropDown(); | |
88 | ||
dfc31755 | 89 | }); |