summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-10 14:12:18 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-24 19:42:35 +0200
commita9e2b04477c968db7d4e255a2755523fd9bf9527 (patch)
treefef7928af296fc1e5005c101c6426af7bcf12ae6
parent38c9a7b344940126627a799a64880be47a71f925 (diff)
downloadIshtar-a9e2b04477c968db7d4e255a2755523fd9bf9527.tar.bz2
Ishtar-a9e2b04477c968db7d4e255a2755523fd9bf9527.zip
Popup: BS style - Container: improve creation form
- prevent container creation when the same reference exists - autocopy reference to location
-rw-r--r--archaeological_warehouse/forms.py27
-rw-r--r--ishtar_common/static/forms/container.js13
-rw-r--r--ishtar_common/static/js/ishtar.js2
-rw-r--r--ishtar_common/templates/window.html51
-rw-r--r--scss/custom.scss8
-rw-r--r--version.py4
6 files changed, 77 insertions, 28 deletions
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 @@
</script>
<script language="javascript" type="text/javascript" src="{{JQUERY_URL}}?ver={{VERSION}}"></script>
<script language="javascript" type="text/javascript" src="{{JQUERY_UI_URL}}jquery-ui.js?ver={{VERSION}}"></script>
+ <script language="javascript" type="text/javascript" src="{{STATIC_URL}}bootstrap/bootstrap.js?ver={{VERSION}}"></script>
<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/chosen/chosen.jquery.min.js?ver={{VERSION}}"></script>
<script language="javascript" type="text/javascript" src="{{STATIC_URL}}js/ishtar.js?ver={{VERSION}}"></script>
{{form.media}}
- <link type="text/css" href="{{JQUERY_UI_URL}}jquery-ui.css?ver={{VERSION}}" rel="stylesheet" />
+ <link rel="stylesheet" href="{{STATIC_URL}}bootstrap/bootstrap.css?ver={{VERSION}}">
<link type="text/css" href="{{STATIC_URL}}js/chosen/chosen.min.css?ver={{VERSION}}" rel="stylesheet" />
- <link rel="stylesheet" href="{{STATIC_URL}}media/style.css?ver={{VERSION}}" />
+ <link rel="stylesheet" href="{{STATIC_URL}}media/styles.css?ver={{VERSION}}" />
{% block extra_head %}
{% endblock %}
</head>
-<body>
-{% if new_item_label %}
+<body class="window-pop">
+<div class="modal-content">
+ <div class="modal-header">
+ <h2>{{title}}</h2>
+ </div>
+
+ <form action="." method="post" class='form'>{% csrf_token %}
+ <div class="modal-body body-scroll">
+ <div class="form">
+ {% include "blocks/bs_form_snippet.html" %}
+ </div>
+ </div>
+
+ <div class="modal-footer">
+ <input type="submit" class="btn btn-primary" id="submit_new_item"
+ value="{% trans 'Add' %}"/>
+ <button type="button" id="cancel-btn" class="btn btn-secondary">
+ {% trans 'Cancel' %}</button>
+ </div>
+
+
+ </form>
+</div>
<script type='text/javascript' language='javascript'>
+{% if new_item_label %}
save_and_close_window{% if many %}_many{% endif %}("{{parent_name}}", "{{parent_pk}}", "{{new_item_label|safe}}", "{{new_item_pk}}");
-</script>
{% endif %}
-<div id="window_content">
- <h3>{{title}}</h3>
- <form action="." method="post" class='form'>{% csrf_token %}
- <table>
- {% for field in form %}
- <tr{% if field.field.required %} class='required'{% endif %}>
- <th>{{ field.label_tag }}</th>
- <td>{{ field.errors }}{{field|safe}}</td>
- </tr>{% endfor %}
- <tr><td colspan='2' class='submit_button'><input type="submit" id="submit_new_item" value="{% trans "Add" %}"/></td></tr>
- </table>
- </form>
- </div>
+$("#cancel-btn").click(function(){
+ close();
+});
+</script>
-</div>
</body>
-
</html>
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():