From 6d04714818868462556f1d21e9450e6a5e50b13a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Larchev=C3=AAque?= Date: Tue, 19 Apr 2011 09:33:28 -0400 Subject: [PATCH 1/1] filtrage des postes en fonction de limlpatantion --- project/dae/templates/dae/poste.html | 8 ++++---- project/dae/urls.py | 1 + project/dae/views.py | 29 +++++++++++++++++++++++++++++ project/media/js/dae-poste.js | 16 ++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/project/dae/templates/dae/poste.html b/project/dae/templates/dae/poste.html index 01b4203..f7ca38d 100644 --- a/project/dae/templates/dae/poste.html +++ b/project/dae/templates/dae/poste.html @@ -56,6 +56,10 @@ Demande d'autorisation d'embauche + + + + @@ -68,10 +72,6 @@ Demande d'autorisation d'embauche - - - - diff --git a/project/dae/urls.py b/project/dae/urls.py index 25e142d..7176f78 100644 --- a/project/dae/urls.py +++ b/project/dae/urls.py @@ -27,6 +27,7 @@ urlpatterns = patterns( url(r'^salaire/(.*)/(.*)/(.*)$', 'salaire', name='salaire'), url(r'^coefficient$', 'coefficient', name='dae_coefficient'), url(r'^liste_valeurs_point$', 'liste_valeurs_point', name='liste_valeurs_point'), + url(r'^liste_postes$', 'liste_postes', name='liste_postes'), url(r'^devise$', 'devise', name='dae_devise'), url(r'^devise/code$', 'devise_code', name='dae_devise_code'), url(r'^add-remun$', 'add_remun', name='add_remun'), diff --git a/project/dae/views.py b/project/dae/views.py index 7367162..6544926 100644 --- a/project/dae/views.py +++ b/project/dae/views.py @@ -453,6 +453,35 @@ def liste_valeurs_point(request): data.append({'id' : o.id, 'label' : o.__unicode__(), }) return HttpResponse(dumps(data)) +def liste_postes(request): + """ Appel AJAX : + input : implantation_id + output : JSON liste de valeur point + """ + method = request.method + params = getattr(request, method, []) + data = [] + + # Voir le code de _poste_choices dans forms.py + dae_ = dae.Poste.objects.filter(actif=True, id_rh__isnull=True) + copies = dae.Poste.objects.exclude(id_rh__isnull=True) + rh_postes_actifs = rh.Poste.objects.filter(actif=True) + + if 'implantation_id' in params and params.get('implantation_id') is not u"": + implantation_id = params.get('implantation_id') + dae_ = dae_.filter(implantation__id=implantation_id) + copies = copies.filter(implantation__id=implantation_id) + rh_postes_actifs = rh_postes_actifs.filter(implantation__id=implantation_id) + + 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]) + return HttpResponse(dumps(data)) + def devise(request): """ Appel AJAX : input : valeur_point diff --git a/project/media/js/dae-poste.js b/project/media/js/dae-poste.js index ade88ea..31b4179 100644 --- a/project/media/js/dae-poste.js +++ b/project/media/js/dae-poste.js @@ -2,6 +2,21 @@ * POSTE *******************************************************************************/ +/* filter les postes en fonction de l'implantation choisie */ +function charger_postes(implantation_id) { + var params = {'implantation_id' : implantation_id}; + var chargement_p = $.getJSON('/dae/liste_postes', params); + chargement_p.success(function(data) { + var items = []; + + var options = ""; + $.each(data, function(index) { + options += ''; + }); + + $("#id_poste").html(options); + }); +} /* Construction dynamique des valeurs de point en fonction de l'implantation choisie */ function charger_valeurs_point(implantation_id) { @@ -84,6 +99,7 @@ $(document).ready(function() { var implantation_id = $("#id_implantation").val(); $("#id_implantation").change(function() { var implantation_id = this.value; + charger_postes(implantation_id); charger_valeurs_point(implantation_id); }); -- 1.7.10.4
{{ form.implantation.label_tag }} :
{{ form.implantation.errors }}
{{ form.implantation }}
{{ form.poste.label_tag }} :
{{ form.poste.errors }}
{{ form.poste }}
{{ form.type_poste }}
{{ form.implantation.label_tag }} :
{{ form.implantation.errors }}
{{ form.implantation }}
{{ form.service.label_tag }} :
{{ form.service.errors }}
{{ form.service }}