general: make it possible to qualify with an user (#8173)
This commit is contained in:
parent
bdce2a3e99
commit
414162b52f
|
@ -1,7 +1,7 @@
|
|||
{% load i18n %}
|
||||
<div class="contact">
|
||||
<input type="hidden" id="current-selected-user" name="current-selected-user" value="{{user_id}}"/>
|
||||
<h3>{{user_display_name}}</h3>
|
||||
<h3>{{user_display_name}} <button class="save">✓</button></h3>
|
||||
{% if user_var_address or user_var_city %}
|
||||
<p>{{user_var_address}} / {{user_var_zipcode}} {{user_var_city}}</p>
|
||||
{% endif %}
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
<button id="create-new-contact">+</button>
|
||||
|
||||
<div class="contact">
|
||||
{% if contact_user_id %}
|
||||
<ul class="result"><a data-page-slug="{{contact_user_id}}">...</a></ul>
|
||||
<script>$('.contact .result a').trigger('click');</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="back-to-empty">
|
||||
<a href="#" class="reset">{% trans 'Back to search' %}</a>
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
import json
|
||||
|
||||
from django import template
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.http import HttpResponse
|
||||
from django.template import RequestContext
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from welco.qualif.models import Association
|
||||
from welco.utils import get_wcs_data
|
||||
|
||||
class HomeZone(object):
|
||||
|
@ -39,6 +41,16 @@ class ContactsZone(TemplateView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ContactsZone, self).get_context_data(**kwargs)
|
||||
if 'source_pk' in self.request.GET:
|
||||
try:
|
||||
association = Association.objects.get(
|
||||
source_type_id=self.request.GET['source_type'],
|
||||
source_pk=self.request.GET['source_pk'])
|
||||
except Association.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
context['contact_user_id'] = association.user_id
|
||||
|
||||
return context
|
||||
|
||||
zone = csrf_exempt(ContactsZone.as_view())
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('qualif', '0003_association_comments'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='association',
|
||||
name='user_id',
|
||||
field=models.CharField(max_length=50, null=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -52,12 +52,16 @@ class Association(models.Model):
|
|||
source = generic.GenericForeignKey('source_type', 'source_pk')
|
||||
triaged = models.BooleanField(default=False)
|
||||
comments = models.TextField(blank=True, verbose_name=_('Comments'))
|
||||
user_id = models.CharField(max_length=50, null=True)
|
||||
|
||||
formdefs = models.ManyToManyField(FormdefReference)
|
||||
formdatas = models.ManyToManyField(FormdataReference)
|
||||
|
||||
def push(self, request, context):
|
||||
# push validated request to wcs
|
||||
if context:
|
||||
context = context.copy()
|
||||
context['user_id'] = self.user_id
|
||||
for formdef in self.formdefs.all():
|
||||
formdata_id = push_wcs_formdata(request, formdef.reference, context)
|
||||
reference = '%s:%s' % (formdef.reference, formdata_id)
|
||||
|
|
|
@ -24,12 +24,33 @@ $(function() {
|
|||
$(zone).find('> div').replaceWith(data);
|
||||
$(zone).find('select').select2();
|
||||
$(zone).removeClass('has-page-displayed');
|
||||
$(zone).removeClass('has-contact-displayed');
|
||||
},
|
||||
error: function(error) { console.log(':(', error); }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.contacts').delegate('button.save', 'click', function() {
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
var selected_user_id = $('#current-selected-user').val();
|
||||
$.ajax({url: $('.cell.qualif').data('zone-url'),
|
||||
data: {user_id: selected_user_id,
|
||||
source_type: source_type,
|
||||
source_pk: source_pk},
|
||||
method: 'POST',
|
||||
dataType: 'html',
|
||||
success: function(data) {
|
||||
$('div.contacts h3').effect('highlight');
|
||||
$('.cell.qualif > div').replaceWith(data);
|
||||
$('.qualif').find('select').select2();
|
||||
},
|
||||
error: function(error) { console.log(':/', error); }
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.qualif').delegate('button.add', 'click', function() {
|
||||
var formdef_reference = $('#id_formdef_reference').val();
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if association %}
|
||||
{% if association.user_id %}
|
||||
<input id="association-user-id" type="hidden" value="{{association.user_id}}"/>
|
||||
{% endif %}
|
||||
|
||||
{% if association.formdefs.count %}
|
||||
<ul>
|
||||
{% for formdef in association.formdefs.all %}
|
||||
<li>{{formdef.name}}</li>
|
||||
|
@ -17,13 +21,13 @@
|
|||
</ul>
|
||||
<p>(<a rel="popup" data-inplace-submit="true" href="{% url 'alfortville-copies' pk=association.id %}">{% trans 'Copies' %}</a>)</p>
|
||||
{% endif %}
|
||||
<div class="add-formdef-reference" {% if association %}style="display: none"{% endif %}>
|
||||
<div class="add-formdef-reference" {% if association.formdefs.count %}style="display: none"{% endif %}>
|
||||
<div>
|
||||
{{form.formdef_reference}}
|
||||
</div>
|
||||
<button class="add">{% trans 'Add' %}</button>
|
||||
</div>
|
||||
{% if association %}
|
||||
{% if association.formdefs.count %}
|
||||
<button class="done" data-action-url="{% url 'qualif-done' %}">{% trans 'Done' %}</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
|
|
@ -86,11 +86,15 @@ class Qualification(TemplateView):
|
|||
source_pk=request.POST['source_pk'])
|
||||
if created:
|
||||
association.save()
|
||||
formdef_ref, created = FormdefReference.objects.get_or_create(
|
||||
reference=request.POST['formdef_reference'])
|
||||
if created:
|
||||
formdef_ref.save()
|
||||
association.formdefs.add(formdef_ref)
|
||||
if 'formdef_reference' in request.POST:
|
||||
formdef_ref, created = FormdefReference.objects.get_or_create(
|
||||
reference=request.POST['formdef_reference'])
|
||||
if created:
|
||||
formdef_ref.save()
|
||||
association.formdefs.add(formdef_ref)
|
||||
if 'user_id' in request.POST:
|
||||
association.user_id = request.POST['user_id']
|
||||
association.save()
|
||||
request.GET = request.POST
|
||||
return self.get(request)
|
||||
|
||||
|
|
Loading…
Reference in New Issue