From a9e2b04477c968db7d4e255a2755523fd9bf9527 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 10 Apr 2019 14:12:18 +0200 Subject: Popup: BS style - Container: improve creation form - prevent container creation when the same reference exists - autocopy reference to location --- archaeological_warehouse/forms.py | 27 +++++++++++++---- ishtar_common/static/forms/container.js | 13 +++++++++ ishtar_common/static/js/ishtar.js | 2 +- ishtar_common/templates/window.html | 51 ++++++++++++++++++++------------- scss/custom.scss | 8 ++++++ version.py | 4 +-- 6 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 ishtar_common/static/forms/container.js diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 99855bf0b..05e0860cb 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -183,6 +183,8 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form): if 'person_in_charge' in dct and dct['person_in_charge']: dct['person_in_charge'] = models.Person.objects.get( pk=dct['person_in_charge']) + if not dct.get("spatial_reference_system", None): + dct.pop("spatial_reference_system") new_item = models.Warehouse(**dct) new_item.save() return new_item @@ -205,14 +207,14 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): old_reference = forms.CharField(label=_(u"Old reference"), required=False, max_length=200) container_type = forms.ChoiceField(label=_(u"Container type"), choices=[]) - location = forms.IntegerField( - label=_(u"Current location (warehouse)"), + responsible = forms.IntegerField( + label=_(u"Responsible warehouse"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse, new=True), validators=[valid_id(models.Warehouse)]) - responsible = forms.IntegerField( - label=_(u"Responsible warehouse"), + location = forms.IntegerField( + label=_(u"Current location (warehouse)"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse, new=True), @@ -223,11 +225,26 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): FieldType('container_type', models.ContainerType), ] + class Media: + js = ('forms/container.js',) + def __init__(self, *args, **kwargs): if 'limits' in kwargs: kwargs.pop('limits') super(ContainerForm, self).__init__(*args, **kwargs) + def clean(self): + cleaned_data = self.cleaned_data + warehouse = cleaned_data.get("location") + q = models.Container.objects.filter( + reference=cleaned_data.get("reference"), location__pk=warehouse) + if 'pk' in cleaned_data and cleaned_data['pk']: + q = q.exclude(pk=int(cleaned_data['pk'])) + if q.count(): + raise forms.ValidationError(_(u"This reference already exists for " + u"this warehouse.")) + return cleaned_data + def save(self, user): dct = self.cleaned_data dct['history_modifier'] = user @@ -256,7 +273,7 @@ class ContainerModifyForm(ContainerForm): def clean(self): # manage unique ID - cleaned_data = self.cleaned_data + cleaned_data = super(ContainerModifyForm, self).clean() index = cleaned_data.get("index") warehouse = cleaned_data.get("location") q = models.Container.objects.filter( diff --git a/ishtar_common/static/forms/container.js b/ishtar_common/static/forms/container.js new file mode 100644 index 000000000..517b3b86d --- /dev/null +++ b/ishtar_common/static/forms/container.js @@ -0,0 +1,13 @@ +$(document).ready(function(){ + var location_changed = false; + + $("#id_select_responsible").on("autocompleteselect", function(event, ui) { + if (location_changed) return; + $("#id_select_location").val(ui.item.label); + $("#id_location").val(ui.item.id); + }); + + $("#id_select_location").on("autocompleteselect", function(event, ui){ + location_changed = true; + }); +}); diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 0aac181ab..910ee92d0 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -672,7 +672,7 @@ function load_url(url, callback){ function open_window(url){ var newwindow = window.open( - url, '_blank', 'height=400,width=600,scrollbars=yes'); + url, '_blank', 'height=500,width=600,scrollbars=yes'); if (window.focus) {newwindow.focus()} return false; } diff --git a/ishtar_common/templates/window.html b/ishtar_common/templates/window.html index dcb4d4084..dc94b4aae 100644 --- a/ishtar_common/templates/window.html +++ b/ishtar_common/templates/window.html @@ -12,36 +12,47 @@ + {{form.media}} - + - + {% block extra_head %} {% endblock %} - -{% if new_item_label %} + + {% endif %} -
-

{{title}}

-
{% csrf_token %} - - {% for field in form %} - - - - {% endfor %} - -
{{ field.label_tag }}{{ field.errors }}{{field|safe}}
-
-
+$("#cancel-btn").click(function(){ + close(); +}); + - - diff --git a/scss/custom.scss b/scss/custom.scss index 4f854650a..791458d72 100644 --- a/scss/custom.scss +++ b/scss/custom.scss @@ -155,6 +155,14 @@ pre { overflow-y: auto; } +.window-pop{ + overflow: hidden; +} + +.window-pop .modal-body.body-scroll { + max-height: calc(100vh - 122px); +} + .modal-dialog.full { width: 98%; height: 98%; diff --git a/version.py b/version.py index 736846500..8dc56a47d 100644 --- a/version.py +++ b/version.py @@ -1,5 +1,5 @@ -# 2.1.dev.38 -VERSION = (2, 1, 'dev', 38) +# 2.1.dev.39 +VERSION = (2, 1, 'dev', 39) def get_version(): -- cgit v1.2.3