coffeescript-ui
Version:
Coffeescript User Interface System
146 lines (102 loc) • 3.4 kB
text/coffeescript
###
* coffeescript-ui - Coffeescript User Interface System (CUI)
* Copyright (c) 2013 - 2016 Programmfabrik GmbH
* MIT Licence
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
###
class CUI.ListViewRowMove extends CUI.ListViewDraggable
initOpts: ->
super()
row:
mandatory: true
check: CUI.ListViewRow
readOpts: ->
super()
= .getRowIdx()
= .getDisplayRowIdx()
= .getListView()
get_helper: (ev, gd, diff) ->
get_helper_contain_element: ->
.getBottom()
get_axis: ->
"y"
get_init_helper_pos: (node, gd) ->
rect = .getRowGridRect()
top: rect.top_abs
left: rect.left_abs
width: rect.width
height: rect.height
init_helper: ->
=
CUI.dom.append(.getGrid(), )
super()
do_drag: (ev, $target, diff) ->
super(ev, $target, diff)
cell = .getCellByTarget($target)
if cell
cell.clientX = ev.clientX()
cell.clientY = ev.clientY()
if cell.display_row_i >= .fixedRowsCount
return
cleanup_drag: (ev) ->
super(ev)
CUI.dom.remove()
= null
end_drag: (ev) ->
super(ev)
# console.debug "end drag...",
if not
return
source_node =
target_node = .getListViewRow(.row_i)
CUI.globalDrag.noClickKill = true
if source_node.moveRow
source_node.moveRow(, target_node, .after)
else
.moveRow(, .row_i, .after)
showHorizontalTargetMarker: (cell) ->
# if .after and cell.display_row_i < .rowsCount-1
# cell.display_row_i++
# .row_i = .getRowIdx(cell.display_row_i)
# .after = false
# check if the move targets the source
if .row_i == or
(.before_row_i == and .after == false) or
(.after_row_i == and .before == false)
= null
CUI.dom.hideElement()
else
CUI.dom.showElement()
CUI.dom.setStyle ,
# display: "block"
left: .left
top: .top
width: .width
showHorizontalTargetMarkerSetTarget: (cell) ->
= row_i: cell.row_i
# find out if the mouse points to the upper half or
# lower half of the row
row_rect = .getRowGridRect(cell.row_i)
# console.warn "row rect", cell.row_i, row_rect
if > 0
.before_row_i = .getRowIdx(-1)
if < .rowsCount-1
.after_row_i = .getRowIdx(+1)
diff = cell.clientY - row_rect.top_abs
# console.debug diff, cell.clientY, row_rect.top, row_rect.top_abs
# before
if diff < row_rect.height / 2
.after = false
.top = row_rect.top
else
.after = true
.top = row_rect.top + row_rect.height
# console.debug "target:", .before_row_i, .row_i, .after_row_i, .after
.width = row_rect.width
.left = row_rect.left
return