Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions modules/directives/sortable/sortable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,30 @@ angular.module('ui.directives').directive 'uiSortable', ['ui.config', (uiConfig)
# Fetch saved and current position of dropped element
start = ui.item.data('ui-sortable-start')
end = ui.item.index()
ui.item.indexs =ui.item.index()

# if item is received not sort it again as it is in correct position
if ui.item.received == true
ui.item.received = false
else
# Reorder array and apply change to scope
ngModel.$modelValue.splice(end, 0, ngModel.$modelValue.splice(start, 1)[0])

scope.$apply()

onReceive = (e, ui) ->
# added item to array into correct position and set up flag
ngModel.$modelValue.splice(ui.item.indexs,0,ui.item.connectedData)
ui.item.received = true;
scope.$apply()

# Reorder array and apply change to scope
ngModel.$modelValue.splice(end, 0, ngModel.$modelValue.splice(start, 1)[0])
onRemove = (e, ui) ->
# copy data into item
if ngModel.$modelValue.length == 1
ui.item.connectedData = ngModel.$modelValue.splice(0,1)[0]
else
ui.item.connectedData = ngModel.$modelValue.splice(ui.item.index(),1)[0]

scope.$apply()

# If user provided 'start' callback compose it with onStart function
Expand All @@ -40,6 +61,20 @@ angular.module('ui.directives').directive 'uiSortable', ['ui.config', (uiConfig)
_update?(e, ui)
scope.$apply()

# If user provided 'receive' callback compose it with onReceive function
_receive = opts.receive
opts.receive = (e, ui) ->
onReceive(e, ui)
_receive?(e, ui)
scope.$apply();

# If user provided 'remove' callback compose it with onRemove function
_remove = opts.remove
opts.remove = (e, ui) ->
onRemove(e, ui)
_remove?(e, ui)
scope.$apply();

# Create sortable
element.sortable(opts)

Expand Down