fix deletable rows

This commit is contained in:
Felix Niklas 2015-11-05 16:25:52 +01:00
parent bad17f7cd5
commit 350fa9170c
2 changed files with 24 additions and 21 deletions

View file

@ -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

View file

@ -30,9 +30,6 @@
<% end %>
</th>
<% end %>
<% if @destroy: %>
<th><%- @T('Delete') %></th>
<% end %>
</tr>
</thead>
<tbody>
@ -88,6 +85,8 @@
<td<%- " class='#{ item.parentClass }'" if item.parentClass %><%- " 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: %>
<a href="<%- item.link %>" <% if item.target: %>target="<%= item.target %>"<% end %>>
@ -107,9 +106,6 @@
<% end %>
</td>
<% end %>
<% if @destroy: %>
<td data-type="destroy"><%- @Icon('trash') %></td>
<% end %>
</tr>
<% end %>
</tbody>