Maintenance: Do table related bindings only on table - not whold @el to get them destroyed on replaceing/re-render table.
This commit is contained in:
parent
dadb564d1f
commit
2e8415d5d0
1 changed files with 27 additions and 28 deletions
|
@ -100,6 +100,7 @@ class App.ControllerTable extends App.Controller
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click .js-sort': 'sortByColumn'
|
'click .js-sort': 'sortByColumn'
|
||||||
|
'click .js-page': 'paginate'
|
||||||
|
|
||||||
overviewAttributes: undefined
|
overviewAttributes: undefined
|
||||||
#model: App.TicketPriority,
|
#model: App.TicketPriority,
|
||||||
|
@ -339,6 +340,7 @@ class App.ControllerTable extends App.Controller
|
||||||
@sortList()
|
@sortList()
|
||||||
bulkIds = @getBulkSelected()
|
bulkIds = @getBulkSelected()
|
||||||
container = @renderTableContainer()
|
container = @renderTableContainer()
|
||||||
|
table = container.filter('.table')
|
||||||
if !rows
|
if !rows
|
||||||
rows = @renderTableRows()
|
rows = @renderTableRows()
|
||||||
@currentRows = clone(rows)
|
@currentRows = clone(rows)
|
||||||
|
@ -373,10 +375,10 @@ class App.ControllerTable extends App.Controller
|
||||||
|
|
||||||
if hit
|
if hit
|
||||||
for event, callback of item.events
|
for event, callback of item.events
|
||||||
do (container, event, callback) ->
|
do (table, event, callback) ->
|
||||||
if cursorMap[event]
|
if cursorMap[event]
|
||||||
container.find("tbody > tr > td:nth-child(#{position})").css('cursor', cursorMap[event])
|
table.find("tbody > tr > td:nth-child(#{position})").css('cursor', cursorMap[event])
|
||||||
container.on(event, "tbody > tr > td:nth-child(#{position})",
|
table.on(event, "tbody > tr > td:nth-child(#{position})",
|
||||||
(e) ->
|
(e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
id = $(e.target).parents('tr').data('id')
|
id = $(e.target).parents('tr').data('id')
|
||||||
|
@ -387,10 +389,10 @@ class App.ControllerTable extends App.Controller
|
||||||
if !_.isEmpty(@bindRow)
|
if !_.isEmpty(@bindRow)
|
||||||
if @bindRow.events
|
if @bindRow.events
|
||||||
for event, callback of @bindRow.events
|
for event, callback of @bindRow.events
|
||||||
do (container, event, callback) ->
|
do (table, event, callback) ->
|
||||||
if cursorMap[event]
|
if cursorMap[event]
|
||||||
container.find('tbody > tr').css( 'cursor', cursorMap[event] )
|
table.find('tbody > tr').css( 'cursor', cursorMap[event] )
|
||||||
container.on(event, 'tbody > tr',
|
table.on(event, 'tbody > tr',
|
||||||
(e) ->
|
(e) ->
|
||||||
id = $(e.target).parents('tr').data('id')
|
id = $(e.target).parents('tr').data('id')
|
||||||
callback(id, e)
|
callback(id, e)
|
||||||
|
@ -400,8 +402,8 @@ class App.ControllerTable extends App.Controller
|
||||||
if @bindCheckbox
|
if @bindCheckbox
|
||||||
if @bindCheckbox.events
|
if @bindCheckbox.events
|
||||||
for event, callback of @bindCheckbox.events
|
for event, callback of @bindCheckbox.events
|
||||||
do (container, event, callback) ->
|
do (table, event, callback) ->
|
||||||
container.delegate('input[name="bulk"]', event, (e) ->
|
table.delegate('input[name="bulk"]', event, (e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
id = $(e.currentTarget).parents('tr').data('id')
|
id = $(e.currentTarget).parents('tr').data('id')
|
||||||
checked = $(e.currentTarget).prop('checked')
|
checked = $(e.currentTarget).prop('checked')
|
||||||
|
@ -412,19 +414,19 @@ class App.ControllerTable extends App.Controller
|
||||||
if @tableId
|
if @tableId
|
||||||
|
|
||||||
# enable resize column
|
# enable resize column
|
||||||
container.on('mousedown', '.js-col-resize', @onColResizeMousedown)
|
table.on('mousedown', '.js-col-resize', @onColResizeMousedown)
|
||||||
container.on('click', '.js-col-resize', @stopPropagation)
|
table.on('click', '.js-col-resize', @stopPropagation)
|
||||||
|
|
||||||
# enable checkbox bulk selection
|
# enable checkbox bulk selection
|
||||||
if @checkbox
|
if @checkbox
|
||||||
|
|
||||||
# click first tr>td, catch click
|
# click first tr>td, catch click
|
||||||
container.delegate('tr > td:nth-child(1)', 'click', (e) ->
|
table.delegate('tr > td:nth-child(1)', 'click', (e) ->
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
)
|
)
|
||||||
|
|
||||||
# bind on full bulk click
|
# bind on full bulk click
|
||||||
container.delegate('input[name="bulk_all"]', 'change', (e) =>
|
table.delegate('input[name="bulk_all"]', 'change', (e) =>
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
clicks = []
|
clicks = []
|
||||||
if $(e.currentTarget).prop('checked')
|
if $(e.currentTarget).prop('checked')
|
||||||
|
@ -473,21 +475,7 @@ class App.ControllerTable extends App.Controller
|
||||||
$(@).width( originals.eq(index).outerWidth() )
|
$(@).width( originals.eq(index).outerWidth() )
|
||||||
return helper
|
return helper
|
||||||
update: @dndCallback
|
update: @dndCallback
|
||||||
container.find('tbody').sortable(dndOptions)
|
table.find('tbody').sortable(dndOptions)
|
||||||
|
|
||||||
# click on pager
|
|
||||||
container.delegate('.js-page', 'click', (e) =>
|
|
||||||
e.stopPropagation()
|
|
||||||
page = $(e.currentTarget).attr 'data-page'
|
|
||||||
if @pagerAjax
|
|
||||||
@navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}"
|
|
||||||
else
|
|
||||||
render = =>
|
|
||||||
@shownPage = page
|
|
||||||
@renderTableFull()
|
|
||||||
App.QueueManager.add('tableRender', render)
|
|
||||||
App.QueueManager.run('tableRender')
|
|
||||||
)
|
|
||||||
|
|
||||||
@el.html(container)
|
@el.html(container)
|
||||||
@setBulkSelected(bulkIds)
|
@setBulkSelected(bulkIds)
|
||||||
|
@ -673,6 +661,18 @@ class App.ControllerTable extends App.Controller
|
||||||
page = parseInt(page)
|
page = parseInt(page)
|
||||||
@objects.slice(page * @shownPerPage, (page + 1) * @shownPerPage)
|
@objects.slice(page * @shownPerPage, (page + 1) * @shownPerPage)
|
||||||
|
|
||||||
|
paginate: (e) =>
|
||||||
|
e.stopPropagation()
|
||||||
|
page = $(e.currentTarget).attr('data-page')
|
||||||
|
if @pagerAjax
|
||||||
|
@navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}"
|
||||||
|
else
|
||||||
|
render = =>
|
||||||
|
@shownPage = page
|
||||||
|
@renderTableFull()
|
||||||
|
App.QueueManager.add('tableRender', render)
|
||||||
|
App.QueueManager.run('tableRender')
|
||||||
|
|
||||||
sortList: =>
|
sortList: =>
|
||||||
return if _.isEmpty(@objects)
|
return if _.isEmpty(@objects)
|
||||||
|
|
||||||
|
@ -836,7 +836,6 @@ class App.ControllerTable extends App.Controller
|
||||||
id = $(e.currentTarget).parents('tr').data('id')
|
id = $(e.currentTarget).parents('tr').data('id')
|
||||||
name = e.currentTarget.getAttribute('data-table-action')
|
name = e.currentTarget.getAttribute('data-table-action')
|
||||||
@runAction(name, id)
|
@runAction(name, id)
|
||||||
console.log 'onActionButtonClicked'
|
|
||||||
|
|
||||||
runAction: (name, id) =>
|
runAction: (name, id) =>
|
||||||
action = _.findWhere @actions, name: name
|
action = _.findWhere @actions, name: name
|
||||||
|
|
Loading…
Reference in a new issue