summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-09-06 18:18:07 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-10-24 12:06:08 +0200
commit23fb7114d46ffae071891fb0bbdd6521dd4d5265 (patch)
tree7752e884cbbd4d1b696ad252961fa2e815c216c3
parent51a031f2f708e6ab890b2a506c0cdcccdfbe47fb (diff)
downloadIshtar-23fb7114d46ffae071891fb0bbdd6521dd4d5265.tar.bz2
Ishtar-23fb7114d46ffae071891fb0bbdd6521dd4d5265.zip
Quick action: manage ajax form
-rw-r--r--archaeological_finds/forms.py91
-rw-r--r--archaeological_finds/views.py3
-rw-r--r--ishtar_common/forms.py5
-rw-r--r--ishtar_common/static/js/ishtar.js69
-rw-r--r--ishtar_common/templates/base.html3
-rw-r--r--ishtar_common/templates/blocks/bs_form_snippet.html1
-rw-r--r--ishtar_common/templates/ishtar/qa_form.html31
-rw-r--r--ishtar_common/views.py18
-rw-r--r--scss/custom.scss1
9 files changed, 156 insertions, 66 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 5fb77433e..1605c4d6a 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -319,79 +319,79 @@ class FindForm(CustomForm, ManageOldType):
class QAFindFormMulti(QAForm):
form_admin_name = _(u"Find - Quick action - Modify")
form_slug = "find-quickaction-modify"
- base_models = ['get_first_base_find', 'object_types', 'material_types',
- 'communicabilities']
+ base_models = ['get_first_base_find', 'qa_object_types',
+ 'qa_material_types', 'qa_communicabilities']
associated_models = {
- 'material_types': models.MaterialType,
- 'object_types': models.ObjectType,
- 'communicabilities': models.CommunicabilityType,
- 'checked_type': models.CheckedType,
+ 'qa_material_types': models.MaterialType,
+ 'qa_object_types': models.ObjectType,
+ 'qa_communicabilities': models.CommunicabilityType,
+ 'qa_checked_type': models.CheckedType,
}
MULTI = True
REPLACE_FIELDS = [
- 'manufacturing_place', 'checked_type', 'check_date'
+ 'qa_manufacturing_place', 'qa_checked_type', 'qa_check_date'
]
HEADERS = {
- 'label': FormHeader(_(u"Identification")),
- 'description': FormHeader(_(u"Description")),
- 'checked_type': FormHeader(_(u"Sheet"))
+ 'qa_label': FormHeader(_(u"Identification")),
+ 'qa_description': FormHeader(_(u"Description")),
+ 'qa_checked_type': FormHeader(_(u"Sheet"))
}
SINGLE_FIELDS = [
- 'label', 'denomination', 'previous_id',
- 'get_first_base_find__excavation_id', 'museum_id', 'seal_number',
- 'mark'
+ 'qa_label', 'qa_denomination', 'qa_previous_id',
+ 'qa_get_first_base_find__excavation_id', 'qa_museum_id',
+ 'qa_seal_number', 'qa_mark'
]
- label = forms.CharField(
+ qa_label = forms.CharField(
label=_(u"Free ID"),
validators=[validators.MaxLengthValidator(60)])
- denomination = forms.CharField(label=_(u"Denomination"), required=False)
- previous_id = forms.CharField(label=_("Previous ID"), required=False)
- get_first_base_find__excavation_id = forms.CharField(
+ qa_denomination = forms.CharField(label=_(u"Denomination"), required=False)
+ qa_previous_id = forms.CharField(label=_("Previous ID"), required=False)
+ qa_get_first_base_find__excavation_id = forms.CharField(
label=_(u"Excavation ID"), required=False)
- museum_id = forms.CharField(label=_(u"Museum ID"), required=False)
- seal_number = forms.CharField(label=_(u"Seal number"), required=False)
- mark = forms.CharField(label=_(u"Mark"), required=False)
+ qa_museum_id = forms.CharField(label=_(u"Museum ID"), required=False)
+ qa_seal_number = forms.CharField(label=_(u"Seal number"), required=False)
+ qa_mark = forms.CharField(label=_(u"Mark"), required=False)
- description = forms.CharField(label=_(u"Description"),
+ qa_description = forms.CharField(label=_(u"Description"),
widget=forms.Textarea, required=False)
- material_types = widgets.Select2MultipleField(
+ qa_material_types = widgets.Select2MultipleField(
label=_(u"Material types"), required=False
)
- object_types = widgets.Select2MultipleField(
+ qa_object_types = widgets.Select2MultipleField(
label=_(u"Object types"), required=False,
)
- decoration = forms.CharField(
+ qa_decoration = forms.CharField(
label=_(u"Decoration"), widget=forms.Textarea,
required=False)
- inscription = forms.CharField(
+ qa_inscription = forms.CharField(
label=_(u"Inscription"), widget=forms.Textarea,
required=False)
- manufacturing_place = forms.CharField(
+ qa_manufacturing_place = forms.CharField(
label=_(u"Manufacturing place"), required=False)
- communicabilities = widgets.Select2MultipleField(
+ qa_communicabilities = widgets.Select2MultipleField(
label=_(u"Communicability"), required=False
)
- comment = forms.CharField(
+ qa_comment = forms.CharField(
label=_(u"Comment"), required=False,
widget=forms.Textarea)
- dating_comment = forms.CharField(
+ qa_dating_comment = forms.CharField(
label=_(u"Comment on dating"), required=False,
widget=forms.Textarea)
- checked_type = forms.ChoiceField(label=_(u"Check"), required=False)
- check_date = forms.DateField(
- initial=get_now, label=_(u"Check date"), widget=DatePicker)
+ qa_checked_type = forms.ChoiceField(label=_(u"Check"), required=False)
+ qa_check_date = forms.DateField(
+ label=_(u"Check date"), widget=DatePicker, required=False)
TYPES = [
- FieldType('material_types', models.MaterialType, is_multiple=True),
- FieldType('object_types', models.ObjectType, is_multiple=True),
- FieldType('communicabilities', models.CommunicabilityType,
+ FieldType('qa_material_types', models.MaterialType, is_multiple=True),
+ FieldType('qa_object_types', models.ObjectType, is_multiple=True),
+ FieldType('qa_communicabilities', models.CommunicabilityType,
is_multiple=True),
- FieldType('checked_type', models.CheckedType, is_multiple=True),
+ FieldType('qa_checked_type', models.CheckedType),
]
@@ -405,7 +405,7 @@ class QAFindFormSingle(QAFindFormMulti):
if not self.items or \
not self.items[0].get_first_base_find(
).context_record.operation.operation_type.judiciary:
- self.fields.pop('seal_number')
+ self.fields.pop('qa_seal_number')
class PreservationForm(CustomForm, ManageOldType):
@@ -414,14 +414,15 @@ class PreservationForm(CustomForm, ManageOldType):
form_slug = "find-030-preservation"
base_models = ['alteration', 'alteration_cause',
'preservation_to_consider', 'integritie', 'remarkabilitie']
- associated_models = {'alteration': models.AlterationType,
- 'alteration_cause': models.AlterationCauseType,
- 'treatment_emergency': models.TreatmentEmergencyType,
- 'conservatory_state': models.ConservatoryState,
- 'preservation_to_consider': models.TreatmentType,
- 'remarkabilitie': models.RemarkabilityType,
- 'integritie': models.IntegrityType,
- }
+ associated_models = {
+ 'alteration': models.AlterationType,
+ 'alteration_cause': models.AlterationCauseType,
+ 'treatment_emergency': models.TreatmentEmergencyType,
+ 'conservatory_state': models.ConservatoryState,
+ 'preservation_to_consider': models.TreatmentType,
+ 'remarkabilitie': models.RemarkabilityType,
+ 'integritie': models.IntegrityType,
+ }
integritie = forms.MultipleChoiceField(
label=_(u"Integrity / interest"), choices=[],
widget=widgets.Select2Multiple, required=False)
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index ca575a889..850890894 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -598,5 +598,4 @@ def reset_wizards(request):
class QAFindForm(QAItemEditForm):
model = models.Find
- form_class = QAFindFormSingle
- form_class_multi = QAFindFormMulti
+ form_class = QAFindFormMulti
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 106b68c14..2e249e472 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -455,6 +455,8 @@ class IshtarForm(forms.Form):
if not getattr(profile, profile_key):
for field_key in self.PROFILE_FILTER[profile_key]:
self.fields.pop(field_key)
+ if getattr(self, 'confirm', True):
+ return
for field in self.TYPES:
self._init_type(field)
for k in self.fields:
@@ -646,11 +648,14 @@ class QAForm(CustomForm, ManageOldType):
def __init__(self, *args, **kwargs):
self.items = kwargs.pop('items')
+ self.confirm = kwargs.pop('confirm')
super(QAForm, self).__init__(*args, **kwargs)
for k in self.fields.keys():
if self.MULTI and k in self.SINGLE_FIELDS:
self.fields.pop(k)
continue
+ if self.confirm:
+ self.fields[k].widget = forms.HiddenInput()
if self.MULTI and k not in self.REPLACE_FIELDS:
self.fields[k].label = unicode(self.fields[k].label) + \
unicode(u" - append to existing")
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 483da495c..2750efcc2 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -413,7 +413,23 @@ $(document).on("click", '#progress-content', function(){
$('.modal-progress').hide();
});
-function long_wait(){
+
+var closed_wait = true;
+
+function short_wait(check_wait){
+ if (check_wait && closed_wait){
+ return
+ }
+ closed_wait = false;
+ $('.modal-progress').modal('show');
+ $('.progress-1').show('slow');
+}
+
+function long_wait(check_wait){
+ if (check_wait && closed_wait){
+ return
+ }
+ closed_wait = false;
$('.modal-progress').modal('show');
$('.progress-1').show('slow');
setTimeout(function(){
@@ -430,11 +446,12 @@ function long_wait(){
}, 180000);
setTimeout(function(){
$('.progress-4').hide('slow');
- long_wait();
+ long_wait(true);
}, 240000);
}
function close_wait(){
+ closed_wait = true;
$('.modal-progress').modal('hide');
if (current_modal){
$('body').addClass('modal-open');
@@ -771,12 +788,48 @@ var dt_generate_qa_url = function (table, url){
}
url += value + "/";
return url;
-}
+};
var dt_qa_open = function (url){
- long_wait();
- $('#modal-dynamic-form').load(url, function(){
- close_wait();
- $('#modal-dynamic-form').modal("show");
+ short_wait();
+ $.ajax({
+ url: url,
+ cache: false,
+ success: function(data, textStatus, jqXHR) {
+ close_wait();
+ var text = jqXHR.responseText;
+ $('#modal-dynamic-form').html(text);
+ var response = $(text);
+ var responseScript = response.find("script");
+ $.each(responseScript, function(idx, val){
+ eval(val.text);
+ }
+ );
+ $('#modal-dynamic-form').modal("show");
+ },
+ error: function() {
+ close_wait();
+ }
});
-}
+};
+
+var ajax_post = function(url, data, target, callback){
+ $.ajax({
+ url : url,
+ type : "POST",
+ data : data,
+ success : function(data) {
+ close_wait();
+ $(target).html(data);
+ if(callback) callback();
+ },
+ error : function(xhr,errmsg,err) {
+ close_wait();
+ $(target).html("<div class='alert-box alert'>Oops! We have encountered an error: "
+ + errmsg + "</div>");
+ console.log(xhr.status + ": " + xhr.responseText);
+ if(callback) callback();
+ }
+ });
+
+};
diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html
index b9270d910..bce02f61d 100644
--- a/ishtar_common/templates/base.html
+++ b/ishtar_common/templates/base.html
@@ -141,7 +141,8 @@
{% trans "Time to take a coffee?" %} <i class="fa fa-coffee" aria-hidden="true"></i></span>
<span class='progress-detail progress-4'>
{% trans "Time to take another coffee?" %} <i class="fa fa-coffee" aria-hidden="true"></i></span>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"
+ onclick="closed_wait = true;return true;">
<span aria-hidden="true">&times;</span>
</button>
</div>
diff --git a/ishtar_common/templates/blocks/bs_form_snippet.html b/ishtar_common/templates/blocks/bs_form_snippet.html
index f122b33f2..0f5f9d83d 100644
--- a/ishtar_common/templates/blocks/bs_form_snippet.html
+++ b/ishtar_common/templates/blocks/bs_form_snippet.html
@@ -12,6 +12,7 @@
</div>{% endif %}
{% endfor %}
+{% csrf_token %}
{% for field in form.visible_fields %}
{% if form.SEARCH_AND_SELECT %}
{{field}}
diff --git a/ishtar_common/templates/ishtar/qa_form.html b/ishtar_common/templates/ishtar/qa_form.html
index 2df3775ea..f3a4cf559 100644
--- a/ishtar_common/templates/ishtar/qa_form.html
+++ b/ishtar_common/templates/ishtar/qa_form.html
@@ -1,30 +1,57 @@
{% load i18n inline_formset table_form %}
<div class="modal-dialog modal-lg modal-dialog-centered">
- <div class="modal-content" id='progress-content'>
+ <div class="modal-content">
<div class="modal-header">
<h2>{{page_name|safe}}</h2>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
- <form enctype="multipart/form-data" action="." method="post">{% csrf_token %}
+ <form enctype="multipart/form-data" action="{{url}}" method="post"
+ id="qa-action">{% csrf_token %}
<div class="modal-body body-scroll">
<div class='form'>
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
{% bs_form form %}
+ {% if confirm %}{% for field in form %}
+ {% if field.value %}
+ <label>{{field.label}}</label> {{ field.value }}
+ {% endif %}
+ {% endfor %}{% endif %}
</div>
</div>
<div class="modal-footer">
<button type="submit" id="submit_form" name='validate'
value="validate" class="btn btn-success">
+ {% if confirm %}
+ {% trans "Confirm" %}
+ {% else %}
{% trans "Modify" %}
+ {% endif %}
+ </button>
+ <button type="button" data-dismiss="modal"
+ aria-label="Close" class="btn btn-secondary">
+ {% trans "Cancel" %}
</button>
</div>
</form>
</div>
</div>
+<script type="text/javascript">
+ $('#qa-action').on('submit', function(event){
+ event.preventDefault();
+ $('#modal-dynamic-form').modal("hide");
+ short_wait();
+ ajax_post(
+ "{{url}}", $(this).serialize(), "#modal-dynamic-form",
+ function(){
+ $('#modal-dynamic-form').modal("show");
+ }
+ );
+ });
+</script>
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 8b22048f2..3704106d2 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -1817,31 +1817,33 @@ class QAItemEditForm(IshtarMixin, LoginRequiredMixin, FormView):
if not self.model.QA_EDIT.is_available(
user=request.user, session=request.session, obj=item):
raise Http404()
-
+ self.confirm = kwargs.get('confirm', False) and True
+ self.url = request.get_full_path()
return super(QAItemEditForm, self).dispatch(request, *args, **kwargs)
def get_form_class(self):
- if len(self.items) > 1:
+ if len(self.items) > 1 and self.form_class_multi:
return self.form_class_multi
return self.form_class
def get_form_kwargs(self):
kwargs = super(QAItemEditForm, self).get_form_kwargs()
kwargs['items'] = self.items
+ kwargs['confirm'] = self.confirm
return kwargs
def get_context_data(self, **kwargs):
data = super(QAItemEditForm, self).get_context_data(**kwargs)
data['page_name'] = u"{} &ndash; {}".format(
self.model._meta.verbose_name, self.model.QA_EDIT.text)
+ data['url'] = self.url
+ data['confirm'] = self.confirm
return data
-
-
- def get_success_url(self, basket):
- return reverse('select_itemsinbasket',
- kwargs={'pk': basket})
-
def form_valid(self, form):
+ if not self.confirm:
+ self.confirm = True
+ return self.render_to_response(
+ self.get_context_data(form=self.get_form()))
return HttpResponseRedirect(self.get_success_url(
form.cleaned_data['basket']))
diff --git a/scss/custom.scss b/scss/custom.scss
index 076522366..1b23c0c33 100644
--- a/scss/custom.scss
+++ b/scss/custom.scss
@@ -194,6 +194,7 @@ div.dt-buttons{
background-color: #f8f9fa;
border-color: #f8f9fa;
color: $gray-500;
+ cursor: not-allowed;
}
.small-button{