From 01191cd000d53d2f9dbecb4454c8fc51071e5f2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Thu, 14 Apr 2011 16:12:40 -0400 Subject: [PATCH] JS diff mois contrat --- project/dae/templates/dae/poste.html | 2 +- project/media/js/dae-poste.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/project/dae/templates/dae/poste.html b/project/dae/templates/dae/poste.html index a2125fd..ff00c04 100644 --- a/project/dae/templates/dae/poste.html +++ b/project/dae/templates/dae/poste.html @@ -137,7 +137,7 @@ Demande d'autorisation d'embauche -

Pour une durée indéterminée, spécifier uniquement la date de début.

+

Pour une durée indéterminée, spécifier uniquement la date de début.

{{ form.regime_travail_nb_heure_semaine.label_tag }} :
diff --git a/project/media/js/dae-poste.js b/project/media/js/dae-poste.js index 5f450b3..f8c9fdb 100644 --- a/project/media/js/dae-poste.js +++ b/project/media/js/dae-poste.js @@ -2,6 +2,7 @@ * POSTE *******************************************************************************/ + /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ function charger_valeurs_point(implantation_id) { var params = {'implantation_id' : implantation_id}; @@ -75,6 +76,25 @@ function recalculer_tout() { }); } +/* stocker le texte par défaut à afficher */ +var note_duree_indeterminee = ""; + +function contrat_mois() { + if (note_duree_indeterminee == "") + note_duree_indeterminee = $("#note-duree").html(); + var debut = $("#id_date_debut").val(); + var fin = $("#id_date_fin").val(); + if (debut == "" || fin == "") + note = note_duree_indeterminee; + else { + var d1 = new Date(debut); + var d2 = new Date(fin); + var duree = Math.round((d2-d1) / (1000*60*60*24) / (365/12)); + note = duree + " mois"; + } + $("#note-duree").html(note); +} + $(document).ready(function() { /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été @@ -160,4 +180,10 @@ $(document).ready(function() { /* au chargement, on calcule tout */ recalculer_tout(); + /* calcul de la différence en mois */ + $("#id_date_debut, #id_date_fin").focusout(function() { + contrat_mois(); + }); + contrat_mois(); + }); -- 1.7.10.4