diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/templates/blocks/JQueryAutocomplete.js | 7 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 41 |
2 files changed, 39 insertions, 9 deletions
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'<span class="input-group-append">'\ u'<a href="#" class="add-button input-group-text" '\ u'onclick="open_window(\'%s\');">+</a></span></div>' % url_new - html += u"""<input%(attrs_select)s/>%(new)s\ -<input type="hidden"%(attrs_hidden)s/>\ + + old_value = "" + if 'value' in attrs_select and attrs_select['value']: + old_value = u"""<span class='previous-value'> + <em>{}</em> <span id="{}">{}</span> + <button class="btn btn-secondary small-button" type="button" + id="{}"> + <i class="fa fa-refresh" aria-hidden="true"></i> + </button> +</span>""".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"<input type='hidden'{}>".format( + flatatt(attrs_hidden_previous)) + + html += u""" +<input{attrs_select}/>{new}\ +<input type="hidden"{attrs_hidden}/>\ +{old_value} <script type="text/javascript"><!--// - %(js)s//--></script> - """ % { - 'attrs_select': flatatt(attrs_select), - 'attrs_hidden': flatatt(attrs_hidden), - 'js': self.render_js(name), - 'new': new - } + {js}//--></script> + """.format( + old_value=old_value, + attrs_select=flatatt(attrs_select), + attrs_hidden=flatatt(attrs_hidden), + js=self.render_js(name), new=new + ) return html |