diff --git a/apps/note/tables.py b/apps/note/tables.py index ad57c265a6010a10ca6014595f47543744eb840a..bfb6030353c334aec5ea2f46e76087f80c94cdcc 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -56,7 +56,11 @@ class HistoryTable(tables.Table): def render_valid(self, value): return "✔" if value else "✖" - +# function delete_button(id) provided in template file +delete_template = """ + <button id="{{ record.pk }}" class="btn btn-danger" onclick="delete_button(this.id)"> {{ delete_trans }}</a> +""" + class AliasTable(tables.Table): class Meta: attrs = { @@ -69,13 +73,9 @@ class AliasTable(tables.Table): show_header = False name = tables.Column(attrs={'td': {'class': 'text-center'}}) - delete = tables.LinkColumn('member:user_alias_delete', - args=[A('pk')], - attrs={ - 'td': {'class': 'col-sm-2'}, - 'a': {'class': 'btn btn-danger'}}, - text='delete', accessor='pk') - + delete = tables.TemplateColumn(template_code=delete_template, + extra_context={"delete_trans":_('delete')}, + attrs={'td':{'class': 'col-sm-1'}}) class ButtonTable(tables.Table): class Meta: attrs = { @@ -90,10 +90,16 @@ class ButtonTable(tables.Table): model = TransactionTemplate + edit = tables.LinkColumn('note:template_update', + args=[A('pk')], + attrs={ + 'td': {'class': 'col-sm-1'}, + 'a': {'class': 'btn btn-primary'}}, + text=_('edit'), accessor='pk') - delete = tables.TemplateColumn(template_code=""" - <button id="{{ record.pk }}" class="btn btn-danger" onclick="delete_button(this.id)"> delete </a> - """) + delete = tables.TemplateColumn(template_code=delete_template, + extra_context={"delete_trans":_('delete')}, + attrs={'td':{'class':'col-sm-1'}}) def render_amount(self, value): return pretty_money(value) diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index ea227ea8eccf9d01b6a1ea743dd97ad32dfdafac..50421f68c533008382f3b3aa400b1179faf2b27c 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -63,15 +63,13 @@ function search_field_moved(secondfield) { $.ajax({ url:"/api/note/transaction/template/"+button_id, method:"DELETE", - headers: { - "X-CSRFTOKEN": CSRF_TOKEN - }, - success: function(){ - addMsg('{% trans "button successfully deleted "%}','success'); - $("#buttons_table").load('{% url "note:template_list" %} #buttons_tables'); - }, - error: addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' ) - }); -} + headers: {"X-CSRFTOKEN": CSRF_TOKEN} + }) + .done(function(){ + addMsg('{% trans "button successfully deleted "%}','success'); + $("#buttons_table").load("{% url 'note:template_list' %} #buttons_table"); + }) + .fail(addMsg(' {% trans "Unable to delete button "%} #' + button_id,'danger' )); + } </script> {% endblock %}