我使用angular ui sortable来在列表之间拖放项目。我希望能够做的是(在某些拖放条件下)有一个确认对话框,如果用户取消对话框,则将列表恢复到原始状态。我可以在更新事件中使用ui.item.sortable.cancel()
方法,但如果我使用返回promise的模式,我无法弄清楚如何在取消时恢复列表。这是我在控制器中的内容(modalService是一个bootstrap $ uibModal):
$scope.sortableOptions =
handle: ' > span > span > .task-drag-icon',
connectWith: ".task-subset"
placeholder: "sortable-placeholder",
forcePlaceholderSize: true,
update: (e, ui) ->
if ui.item.sortable.sourceModel == ui.item.sortable.droptargetModel #sort was within the same list
#some other logic here.....
else
droptarget_element = ui.item.sortable.droptarget
if droptarget_element.attr('ng-model') == "task.subTasks"
#need the user to confirm here if they really want to do this drag/drop
modalOptions =
closeButtonText: 'Cancel'
actionButtonText: 'Make SubTask'
headerText: 'Make SubTask?'
bodyText: 'This action will remove any existing task groups as it will become a child task. Is this OK?'
modalService.showModal({}, modalOptions).then (result) ->
console.log "accpted"
, () ->
console.log "cancelled"
#need to call ui.item.sortable.cancel() here, but I cant because the update callback has finished already!!!!
console.log "finished - gets to here immediately as modalService is asyncronous"
return
任何建议表示赞赏。