summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-01-13 23:08:11 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-01-13 23:08:11 +0100
commita9ecb02b0e07f61ba6485922c8f762c2c258a7b9 (patch)
treea9b1296864a5be9db26af399a14aadb87de96c27
parentc4134e27d21b7b641a3b68c78cdf6e08cfb15557 (diff)
downloadIshtar-a9ecb02b0e07f61ba6485922c8f762c2c258a7b9.tar.bz2
Ishtar-a9ecb02b0e07f61ba6485922c8f762c2c258a7b9.zip
Manage many additions for archaeological sites (refs #3043)
-rw-r--r--archaeological_operations/forms.py2
-rw-r--r--archaeological_operations/views.py2
-rw-r--r--ishtar_common/static/js/ishtar.js18
-rw-r--r--ishtar_common/templates/window.html2
-rw-r--r--ishtar_common/views.py5
5 files changed, 24 insertions, 5 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 90977416b..51836e1fe 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -741,7 +741,7 @@ class OperationFormGeneral(forms.Form):
def clean(self):
cleaned_data = self.cleaned_data
# verify the logic between start date and excavation end date
- if cleaned_data['excavation_end_date']:
+ if cleaned_data.get('excavation_end_date'):
if not self.cleaned_data['start_date']:
raise forms.ValidationError(
_(u"If you want to set an excavation end date you have to "
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 256985f50..a10f63e88 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -84,7 +84,7 @@ def autocomplete_archaeologicalsite(request):
return HttpResponse(data, mimetype='text/plain')
new_archaeologicalsite = new_item(models.ArchaeologicalSite,
- ArchaeologicalSiteForm)
+ ArchaeologicalSiteForm, many=True)
def autocomplete_operation(request, non_closed=True):
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 4d11fcde3..c50d050ef 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -146,6 +146,24 @@ function save_and_close_window(name_label, name_pk, item_name, item_pk){
self.close();
}
+function save_and_close_window_many(name_label, name_pk, item_name, item_pk){
+ var main_page = opener.document;
+ var lbl_ = jQuery(main_page).find("#"+name_label);
+ var val_ = jQuery(main_page).find("#"+name_pk);
+ if (val_.val()){
+ var v = lbl_.val();
+ v = v.slice(0, v.lastIndexOf(","));
+ lbl_.val(v + ", " + item_name + ", ");
+ val_.val(val_.val() + ", " + item_pk);
+ lbl_.change();
+ } else {
+ jQuery(main_page).find("#"+name_label).val(item_name);
+ jQuery(main_page).find("#"+name_pk).val(item_pk);
+ }
+ opener.focus();
+ self.close();
+}
+
function multiRemoveItem(selItems, name, idx){
for(id in selItems){
if(selItems[id] == idx){
diff --git a/ishtar_common/templates/window.html b/ishtar_common/templates/window.html
index c8e187728..7c9249ff0 100644
--- a/ishtar_common/templates/window.html
+++ b/ishtar_common/templates/window.html
@@ -23,7 +23,7 @@
<body>
{% if new_item_label %}
<script type='text/javascript' language='javascript'>
-save_and_close_window("{{parent_name}}", "{{parent_pk}}", "{{new_item_label}}", "{{new_item_pk}}");
+save_and_close_window{% if many %}_many{% endif %}("{{parent_name}}", "{{parent_pk}}", "{{new_item_label}}", "{{new_item_pk}}");
</script>
{% endif %}
<div id="window_content">
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 1320517ff..1f2bc7f67 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -821,13 +821,14 @@ def autocomplete_author(request):
return HttpResponse(data, mimetype='text/plain')
-def new_item(model, frm):
+def new_item(model, frm, many=False):
def func(request, parent_name, limits=''):
model_name = model._meta.object_name
if not check_permission(request, 'add_' + model_name.lower()):
not_permitted_msg = ugettext(u"Operation not permitted.")
return HttpResponse(not_permitted_msg)
- dct = {'title': unicode(_(u'New %s' % model_name.lower()))}
+ dct = {'title': unicode(_(u'New %s' % model_name.lower())),
+ 'many': many}
if request.method == 'POST':
dct['form'] = frm(request.POST, limits=limits)
if dct['form'].is_valid():