Allow the user to select a referenced liaison. Fixes #381
- Legacy-Id: 2538
This commit is contained in:
parent
20032758a0
commit
73f9fe310b
|
@ -3,6 +3,7 @@ from email.utils import parseaddr
|
|||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
from django.forms.util import ErrorList
|
||||
from django.forms.fields import email_re
|
||||
from django.template.loader import render_to_string
|
||||
|
@ -12,7 +13,7 @@ from ietf.liaisons.accounts import (can_add_outgoing_liaison, can_add_incoming_l
|
|||
from ietf.liaisons.models import LiaisonDetail, Uploads, OutgoingLiaisonApproval, SDOs
|
||||
from ietf.liaisons.utils import IETFHM
|
||||
from ietf.liaisons.widgets import (FromWidget, ReadOnlyWidget, ButtonWidget,
|
||||
ShowAttachmentsWidget)
|
||||
ShowAttachmentsWidget, RelatedLiaisonWidget)
|
||||
|
||||
|
||||
class LiaisonForm(forms.ModelForm):
|
||||
|
@ -33,11 +34,13 @@ class LiaisonForm(forms.ModelForm):
|
|||
require=['id_attach_title', 'id_attach_file'],
|
||||
required_label='title and file'),
|
||||
required=False)
|
||||
related_to = forms.ModelChoiceField(LiaisonDetail.objects.all(), label=u'Related Liaison', widget=RelatedLiaisonWidget, required=False)
|
||||
|
||||
fieldsets = [('From', ('from_field', 'replyto')),
|
||||
('To', ('organization', 'to_poc')),
|
||||
('Other email addresses', ('response_contact', 'technical_contact', 'cc1')),
|
||||
('Purpose', ('purpose', 'purpose_text', 'deadline_date')),
|
||||
('References', ('related_to', )),
|
||||
('Liaison Statement', ('title', 'body', 'attachments')),
|
||||
('Add attachment', ('attach_title', 'attach_file', 'attach_button')),
|
||||
]
|
||||
|
@ -318,7 +321,7 @@ class EditLiaisonForm(LiaisonForm):
|
|||
model = LiaisonDetail
|
||||
fields = ('from_raw_body', 'to_body', 'to_poc', 'cc1', 'last_modified_date', 'title',
|
||||
'response_contact', 'technical_contact', 'purpose_text', 'body',
|
||||
'deadline_date', 'purpose', 'replyto', )
|
||||
'deadline_date', 'purpose', 'replyto', 'related_to')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(EditLiaisonForm, self).__init__(*args, **kwargs)
|
||||
|
|
|
@ -28,4 +28,5 @@ urlpatterns += patterns('ietf.liaisons.views',
|
|||
url(r'^for_approval/(?P<object_id>\d+)/$', 'liaison_approval_detail', name='liaison_approval_detail'),
|
||||
url(r'^add/$', 'add_liaison', name='add_liaison'),
|
||||
url(r'^ajax/get_info/$', 'get_info', name='get_info'),
|
||||
url(r'^ajax/liaison_list/$', 'ajax_liaison_list', name='ajax_liaison_list'),
|
||||
)
|
||||
|
|
|
@ -167,3 +167,12 @@ def liaison_detail(request, object_id):
|
|||
def liaison_edit(request, object_id):
|
||||
liaison = get_object_or_404(LiaisonDetail, pk=object_id)
|
||||
return add_liaison(request, liaison=liaison)
|
||||
|
||||
def ajax_liaison_list(request):
|
||||
public_liaisons = LiaisonDetail.objects.filter(Q(approval__isnull=True)|Q(approval__approved=True)).order_by("-submitted_date")
|
||||
|
||||
return object_list(request, public_liaisons,
|
||||
allow_empty=True,
|
||||
template_name='liaisons/liaisondetail_simple_list.html',
|
||||
extra_context={}
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db.models.query import QuerySet
|
||||
from django.forms.widgets import Select, Widget
|
||||
from django.forms.widgets import Select, Widget, TextInput
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
|
||||
|
@ -64,3 +65,33 @@ class ShowAttachmentsWidget(Widget):
|
|||
html += u'No files attached'
|
||||
html += u'</div></div>'
|
||||
return mark_safe(html)
|
||||
|
||||
|
||||
class RelatedLiaisonWidget(TextInput):
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
if not value:
|
||||
value = ''
|
||||
title = ''
|
||||
noliaison = 'inline'
|
||||
deselect = 'none'
|
||||
else:
|
||||
from ietf.liaisons.models import LiaisonDetail
|
||||
liaison = LiaisonDetail.objects.get(pk=value)
|
||||
title = liaison.title
|
||||
if not title:
|
||||
files = liaison.uploads_set.all()
|
||||
if files:
|
||||
title = files[0].file_title
|
||||
else:
|
||||
title = 'Liaison #%s' % liaison.pk
|
||||
noliaison = 'none'
|
||||
deselect = 'inline'
|
||||
html = u'<span class="noRelated" style="display: %s;">No liaison selected</span>' % noliaison
|
||||
html += u'<span class="relatedLiaisonWidgetTitle">%s</span>' % title
|
||||
html += u'<input type="hidden" name="%s" class="relatedLiaisonWidgetValue" value="%s" /> ' % (name, value)
|
||||
html += u'<span style="display: none;" class="listURL">%s</span> ' % reverse('ajax_liaison_list')
|
||||
html += u'<div style="display: none;" class="relatedLiaisonWidgetDialog" id="related-dialog" title="Select a liaison"></div> '
|
||||
html += '<input type="button" id="id_%s" value="Select liaison" /> ' % name
|
||||
html += '<input type="button" style="display: %s;" id="id_no_%s" value="Deselect liaison" />' % (deselect, name)
|
||||
return mark_safe(html)
|
||||
|
|
32
ietf/templates/liaisons/liaisondetail_simple_list.html
Normal file
32
ietf/templates/liaisons/liaisondetail_simple_list.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
<table class="ietf-table" width="100%">
|
||||
<tr><th width="9%">Date</th><th width="20%">From</th><th width="20%">To</th><th width="50%">Title</th></tr>
|
||||
|
||||
{% for liaison in object_list %}
|
||||
<tr class="{% cycle oddrow,evenrow %}">
|
||||
<td style="white-space:nowrap;">{{ liaison.submitted_date|date:"Y-m-d" }}</td>
|
||||
<td>{{ liaison.from_body|escape }}</td>
|
||||
<td>
|
||||
{% if liaison.by_secretariat %}
|
||||
{% if liaison.submitter_email %}
|
||||
<a href="mailto:{{ liaison.submitter_email}}">{{ liaison.submitter_name|escape }}</a>
|
||||
{% else %}
|
||||
{{ liaison.submitter_name|escape }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ liaison.to_body|escape }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if liaison.by_secretariat %}
|
||||
{% for file in liaison.uploads_set.all %}
|
||||
<a href="https://datatracker.ietf.org/documents/LIAISON/file{{ file.file_id }}{{ file.file_extension }}">{{ file.file_title|escape }}</a><br/>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<a href="{{ liaison.detail_id }}/">{{ liaison.title|escape }}</a>
|
||||
{% endif %}
|
||||
<span style="display: none" class="liaisonPK">{{ liaison.pk }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
BIN
static/images/ajax-loader.gif
Normal file
BIN
static/images/ajax-loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 847 B |
|
@ -140,6 +140,9 @@
|
|||
var cancel = form.find('#id_cancel');
|
||||
var cancel_dialog = form.find('#cancel-dialog');
|
||||
var config = {};
|
||||
var related_trigger = form.find('#id_related_to');
|
||||
var related_dialog = form.find('#related-dialog');
|
||||
var unrelate_trigger = form.find('#id_no_related_to');
|
||||
|
||||
var readConfig = function() {
|
||||
var confcontainer = form.find('.formconfig');
|
||||
|
@ -232,6 +235,47 @@
|
|||
cancel_dialog.dialog("open");
|
||||
};
|
||||
|
||||
var getRelatedLink = function() {
|
||||
link = $(this).text();;
|
||||
pk = $(this).nextAll('.liaisonPK').text();
|
||||
widget = related_trigger.parent();
|
||||
widget.find('.relatedLiaisonWidgetTitle').text(link);
|
||||
widget.find('.relatedLiaisonWidgetValue').val(pk);
|
||||
widget.find('.noRelated').hide();
|
||||
unrelate_trigger.show();
|
||||
related_dialog.dialog('close');
|
||||
return false;
|
||||
};
|
||||
|
||||
var selectNoRelated = function() {
|
||||
widget = $(this).parent();
|
||||
widget.find('.relatedLiaisonWidgetTitle').text('');
|
||||
widget.find('.noRelated').show();
|
||||
widget.find('.relatedLiaisonWidgetValue').val('');
|
||||
$(this).hide();
|
||||
return false;
|
||||
};
|
||||
|
||||
var selectRelated = function() {
|
||||
widget = $(this).parent();
|
||||
url = widget.find('.listURL').text();
|
||||
title = widget.find('.relatedLiaisonWidgetTitle');
|
||||
related_dialog.html('<img src="/images/ajax-loader.gif" />');
|
||||
related_dialog.dialog('open');
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
async: true,
|
||||
dataType: 'html',
|
||||
success: function(response){
|
||||
related_dialog.html(response);
|
||||
related_dialog.find('a').click(getRelatedLink);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
|
||||
var initTriggers = function() {
|
||||
organization.change(updateInfo);
|
||||
organization.change(checkOtherSDO);
|
||||
|
@ -239,6 +283,8 @@
|
|||
reply.keyup(updateFrom);
|
||||
purpose.change(updatePurpose);
|
||||
cancel.click(cancelForm);
|
||||
related_trigger.click(selectRelated);
|
||||
unrelate_trigger.click(selectNoRelated);
|
||||
};
|
||||
|
||||
var updateOnInit = function() {
|
||||
|
@ -275,6 +321,14 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
related_dialog.dialog({
|
||||
height: 400,
|
||||
width: 800,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
autoOpen: false
|
||||
});
|
||||
};
|
||||
|
||||
var initForm = function() {
|
||||
|
|
Loading…
Reference in a new issue