From 350fa9170c4ef698e7069aeb73604d928d7e17be Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Thu, 5 Nov 2015 16:25:52 +0100 Subject: [PATCH] fix deletable rows --- .../_application_controller_table.coffee | 37 +++++++++++-------- .../app/views/generic/table.jst.eco | 8 +--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index a5bd39243..1cbb35935 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -9,6 +9,9 @@ class App.ControllerTable extends App.Controller elements: '.js-tableHead': 'tableHead' + events: + 'click .js-delete': 'deleteRow' + constructor: (params) -> super @@ -162,6 +165,15 @@ class App.ControllerTable extends App.Controller attribute.width = "#{@headerWidth[attribute.name]}px" @headers.push attribute + if destroy + @headers.push + name: 'destroy' + display: 'Delete' + width: '70px' + unresizable: true + parentClass: 'js-delete' + icon: 'trash' + if @orderDirection && @orderBy for header in @headers if header.name is @orderBy @@ -193,8 +205,6 @@ class App.ControllerTable extends App.Controller for callback in @callbackHeader @headers = callback(@headers) - @headers = @adjustHeaderWidths @headers - # group by if @groupBy @@ -297,19 +307,6 @@ class App.ControllerTable extends App.Controller callback(id, checked, e) ) - # bind on delete dialog - if @model && destroy - table.delegate('[data-type="destroy"]', 'click', (e) => - e.stopPropagation() - e.preventDefault() - itemId = $(e.target).parents('tr').data('id') - item = @model.find(itemId) - new App.ControllerGenericDestroyConfirm( - item: item - container: @container - ) - ) - # if we have a personalised table if @table_id @@ -347,6 +344,16 @@ class App.ControllerTable extends App.Controller table + # bind on delete dialog + deleteRow: (e) => + e.stopPropagation() + e.preventDefault() + itemId = $(e.target).parents('tr').data('id') + item = @model.find(itemId) + new App.ControllerGenericDestroyConfirm + item: item + container: @container + adjustHeaderWidths: (headers) -> if !@headers return diff --git a/app/assets/javascripts/app/views/generic/table.jst.eco b/app/assets/javascripts/app/views/generic/table.jst.eco index bcbdb3362..639da1700 100644 --- a/app/assets/javascripts/app/views/generic/table.jst.eco +++ b/app/assets/javascripts/app/views/generic/table.jst.eco @@ -30,9 +30,6 @@ <% end %> <% end %> - <% if @destroy: %> - <%- @T('Delete') %> - <% end %> @@ -88,6 +85,8 @@ <%- " title='#{ item.title }'" if item.title %><%- " style='text-align:#{ item.align }'" if item.align %>> <% if item.name is 'icon': %> <%- @Icon('task-state', item.class) %> + <% else if item.icon: %> + <%- @Icon(item.icon) %> <% else: %> <% if item.link: %> target="<%= item.target %>"<% end %>> @@ -107,9 +106,6 @@ <% end %> <% end %> - <% if @destroy: %> - <%- @Icon('trash') %> - <% end %> <% end %>