From 4bce4d2496119dbeae99683692f1df20946c304d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Tue, 19 Apr 2011 16:52:30 -0400 Subject: [PATCH] filtrage JS implantation, famille --- project/dae/forms.py | 8 ++++++-- project/dae/templates/dae/poste.html | 2 +- project/dae/views.py | 6 ++---- project/media/js/dae-poste.js | 17 +++++++++++++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/project/dae/forms.py b/project/dae/forms.py index 543f384..2b667dd 100644 --- a/project/dae/forms.py +++ b/project/dae/forms.py @@ -9,6 +9,10 @@ from datamaster_modeles import models as ref from dae import models as dae from rh_v1 import models as rh +def label_poste_display(poste): + """Formate un visuel pour un poste dans une liste déroulante""" + label = u"%s - %s [%s]" %(poste.type_poste, poste.type_poste.famille_emploi.nom, poste.id) + return label class PostePieceForm(inlineformset_factory(dae.Poste, dae.PostePiece)): pass @@ -155,8 +159,8 @@ class PosteForm(WorkflowFormMixin): rhv1 = rhv1.select_related(depth=1) return [('', 'Nouveau poste')] + \ - sorted([('dae-%s' % p.id, unicode(p)) for p in dae_ | copies] + - [('rh-%s' % p.id, unicode(p)) for p in rhv1], + sorted([('dae-%s' % p.id, label_poste_display(p)) for p in dae_ | copies] + + [('rh-%s' % p.id, label_poste_display(p)) for p in rhv1], key=lambda t: t[1]) def clean(self): diff --git a/project/dae/templates/dae/poste.html b/project/dae/templates/dae/poste.html index f7ca38d..4c2908c 100644 --- a/project/dae/templates/dae/poste.html +++ b/project/dae/templates/dae/poste.html @@ -61,7 +61,7 @@ Demande d'autorisation d'embauche {{ form.poste.label_tag }} :
{{ form.poste.errors }} - {{ form.poste }} + {{ form.poste }} Au changement de ce menu, la page va être rechargée. {{ form.nom.label_tag }} :
{{ form.nom.errors }} diff --git a/project/dae/views.py b/project/dae/views.py index 6544926..7b3c514 100644 --- a/project/dae/views.py +++ b/project/dae/views.py @@ -476,10 +476,8 @@ def liste_postes(request): id_copies = [p.id_rh_id for p in copies.all()] rhv1 = rh_postes_actifs.exclude(id__in=id_copies) rhv1 = rhv1.select_related(depth=1) - data = [('', 'Nouveau poste')] + \ - sorted([('dae-%s' % p.id, unicode(p)) for p in dae_ | copies] + - [('rh-%s' % p.id, unicode(p)) for p in rhv1], - key=lambda t: t[1]) + + data = [('', 'Nouveau poste')] + sorted([('dae-%s' % p.id, label_poste_display(p)) for p in dae_ | copies] + [('rh-%s' % p.id, label_poste_display(p)) for p in rhv1], key=lambda t: t[1]) return HttpResponse(dumps(data)) def devise(request): diff --git a/project/media/js/dae-poste.js b/project/media/js/dae-poste.js index 31b4179..320f508 100644 --- a/project/media/js/dae-poste.js +++ b/project/media/js/dae-poste.js @@ -4,6 +4,7 @@ /* filter les postes en fonction de l'implantation choisie */ function charger_postes(implantation_id) { + var selected = $("#id_poste :selected").val(); var params = {'implantation_id' : implantation_id}; var chargement_p = $.getJSON('/dae/liste_postes', params); chargement_p.success(function(data) { @@ -11,7 +12,10 @@ function charger_postes(implantation_id) { var options = ""; $.each(data, function(index) { - options += ''; + select = ""; + if (data[index][0] == selected) + select = " selected=selected "; + options += ''; }); $("#id_poste").html(options); @@ -32,7 +36,7 @@ function charger_valeurs_point(implantation_id) { $("#id_valeur_point_min").html(options); $("#id_valeur_point_max").html(options); - alert("Les valeurs de point on été ajustées en fonction de cette implantation."); + alert("Les valeurs de point et les postes ont été ajustés en fonction de cette implantation."); }); } @@ -93,6 +97,12 @@ function recalculer_tout() { $(document).ready(function() { + /* Lorsqu'on choisit un poste dans la liste on recharge la page avec le + poste chargé dans la view (grâce à son id dans l'URL).*/ + $('#id_poste').change(function() { + window.location = '/dae/poste/' + $(this).val(); + }); + /* La fonctionnalité de présélection, est activé uniquement si aucune implantation n'a déjà été sélectionnée. Lorsque l'implantation est changée, on ajuste les valeurs de points en fonction de cette sélection */ @@ -182,5 +192,8 @@ $(document).ready(function() { contrat_mois(); }); contrat_mois(); + + /* on charge les postes reliés à cette implantation */ + charger_postes($("#id_implantation :selected").val()); }); -- 1.7.10.4