From 9de9c530fe7e48379f0ba0d49ca8e576975728bc Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 31 May 2018 19:24:28 +0200 Subject: Widget: add a restore button on inadequate clean of a value --- archaeological_finds/forms.py | 2 +- .../templates/blocks/JQueryAutocomplete.js | 7 ++++ ishtar_common/widgets.py | 41 +++++++++++++++++----- version.py | 4 +-- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index ac58780f0..5614118ec 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -101,7 +101,7 @@ class RecordFormSelection(CustomForm, forms.Form): base_models = ['get_first_base_find'] associated_models = {'get_first_base_find__context_record': ContextRecord} get_first_base_find__context_record = forms.IntegerField( - label=_(u"Context record"), required=False, + label=_(u"Context record"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-contextrecord'), associated_model=ContextRecord), diff --git a/ishtar_common/templates/blocks/JQueryAutocomplete.js b/ishtar_common/templates/blocks/JQueryAutocomplete.js index 53a5e18ae..2d2bbad9d 100644 --- a/ishtar_common/templates/blocks/JQueryAutocomplete.js +++ b/ishtar_common/templates/blocks/JQueryAutocomplete.js @@ -23,6 +23,13 @@ $(function() { $('#id_select_{{field_id}}').val(null); }); + $(document).on("click", '#id_{{field_id}}_previous_button', function(){ + $('#id_{{field_id}}').val($('#id_{{field_id}}_previous').val()); + $('#id_select_{{field_id}}').val( + $('#id_{{field_id}}_previous_label').html() + ); + $('#id_{{field_id}}').change(); + }); {% if dynamic_limit %}{% for item_id in dynamic_limit %} $('#{{item_id}}').change(function(){ diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index ca4036f4c..ec3f8b011 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -411,16 +411,39 @@ class JQueryAutoComplete(forms.TextInput): new = u''\ u'+' % url_new - html += u"""%(new)s\ -\ + + old_value = "" + if 'value' in attrs_select and attrs_select['value']: + old_value = u""" + {} {} + +""".format( + _(u"Previous value:"), + attrs_hidden['id'] + u"_previous_label", + attrs_select['value'], + attrs_hidden['id'] + u"_previous_button", + ) + attrs_hidden_previous = attrs_hidden.copy() + attrs_hidden_previous['name'] += u"_previous" + attrs_hidden_previous['id'] += u"_previous" + old_value += u"".format( + flatatt(attrs_hidden_previous)) + + html += u""" +{new}\ +\ +{old_value} - """ % { - 'attrs_select': flatatt(attrs_select), - 'attrs_hidden': flatatt(attrs_hidden), - 'js': self.render_js(name), - 'new': new - } + {js}//--> + """.format( + old_value=old_value, + attrs_select=flatatt(attrs_select), + attrs_hidden=flatatt(attrs_hidden), + js=self.render_js(name), new=new + ) return html diff --git a/version.py b/version.py index 88072ec7f..880866b43 100644 --- a/version.py +++ b/version.py @@ -1,5 +1,5 @@ -# 2.1.master.3 -VERSION = (2, 1, 'master', 3) +# 2.1.master.4 +VERSION = (2, 1, 'master', 4) def get_version(): -- cgit v1.2.3