general: make it possible to remove an association

This commit is contained in:
Frédéric Péters 2015-10-11 13:39:49 +02:00
parent 89b3ea5393
commit c125733041
5 changed files with 38 additions and 1 deletions

View File

@ -392,3 +392,8 @@ div#copies p {
div#copies p:first-child {
margin-left: 0;
}
div.add-formdef-reference > div {
display: inline-block;
width: calc(100% - 6em);
}

View File

@ -51,6 +51,28 @@ $(function() {
return false;
});
$('.qualif').delegate('a.remove', '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');
$.ajax({url: $(this).attr('href'),
method: 'GET',
success: function(data) {
$.ajax({url: $('.cell.qualif').data('zone-url'),
data: {source_type: source_type, source_pk: source_pk},
async: true,
dataType: 'html',
success: function(data) {
var zone = $('.cell.qualif');
$(zone).find('> div').replaceWith(data);
$(zone).find('select').select2();
}
});
}
});
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');

View File

@ -4,7 +4,10 @@
{% if associations|length %}
<ul>
{% for association in associations %}
<li>{{association.formdef_name}}</li>
<li>{{association.formdef_name}}
{% if not association.formdata_id %}
(<a class="remove" href="{% url 'ajax-remove-association' pk=association.id %}"></a>)</li>
{% endif %}
{% endfor %}
<li><a href="#" class="plus">{% trans 'Add another' %}</a></li>
</ul>

View File

@ -26,6 +26,8 @@ urlpatterns = patterns('',
url(r'^phone/$', 'welco.views.home_phone', name='home-phone'),
url(r'^ajax/qualification$', 'welco.views.qualification', name='qualif-zone'),
url(r'^ajax/qualification-done$', 'welco.views.qualification_done', name='qualif-done'),
url(r'^ajax/remove-association/(?P<pk>\w+)$',
'welco.views.remove_association', name='ajax-remove-association'),
url(r'^ajax/kb$', 'welco.kb.views.zone', name='kb-zone'),
url(r'^kb/$', 'welco.kb.views.page_list', name='kb-home'),

View File

@ -149,3 +149,8 @@ def wcs_summary(request, *args, **kwargs):
json_str = '%s(%s);' % (request.GET[variable], json_str)
break
return HttpResponse(json_str, content_type='application/javascript')
@login_required
def remove_association(request, *args, **kwargs):
Association.objects.filter(id=kwargs.get('pk')).delete()
return HttpResponseRedirect(resolve_url('home'))