Angularjs 如何在angular ui sortable回调中等待确认对话框
我使用angular ui sortable在列表之间拖放项目。我希望能够做的是(在某些拖放条件下)有一个确认对话框,如果用户取消该对话框,则将列表恢复到其原始状态。我可以在更新事件中使用Angularjs 如何在angular ui sortable回调中等待确认对话框,angularjs,bootstrap-modal,jquery-ui-sortable,angular-ui-sortable,Angularjs,Bootstrap Modal,Jquery Ui Sortable,Angular Ui Sortable,我使用angular ui sortable在列表之间拖放项目。我希望能够做的是(在某些拖放条件下)有一个确认对话框,如果用户取消该对话框,则将列表恢复到其原始状态。我可以在更新事件中使用ui.item.sortable.cancel()方法,但是如果我使用返回承诺的模式,我就不知道如何在取消时恢复列表。以下是我控制器中的内容(modalService是一个引导$uibModal): 任何建议都值得赞赏。如果没有一些主要的技巧,我无法让它正常工作,因此我最终没有在更新回调中使用cancel()方
ui.item.sortable.cancel()
方法,但是如果我使用返回承诺的模式,我就不知道如何在取消时恢复列表。以下是我控制器中的内容(modalService是一个引导$uibModal):
任何建议都值得赞赏。如果没有一些主要的技巧,我无法让它正常工作,因此我最终没有在更新回调中使用cancel()方法,而是通过分配一些变量,将相应数组中的数据恢复到eth stop回调中的状态,如下所示:
$scope.sortableOptions =
handle: ' > span > span > .task-drag-icon',
connectWith: ".task-subset"
placeholder: "sortable-placeholder",
forcePlaceholderSize: true,
stop: (e, ui) ->
orig_index = ui.item.sortable.index
new_idex = ui.item.sortable.dropindex
sourceModel = ui.item.sortable.sourceModel
droptargetModel = ui.item.sortable.droptargetModel
model = ui.item.sortable.model
if sourceModel == 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"
, () ->
#put model back in orginal poisition
sourceModel.splice orig_index, 0, model
#remove from target array
droptargetModel.splice new_idex, 1
return
$scope.sortableOptions =
handle: ' > span > span > .task-drag-icon',
connectWith: ".task-subset"
placeholder: "sortable-placeholder",
forcePlaceholderSize: true,
stop: (e, ui) ->
orig_index = ui.item.sortable.index
new_idex = ui.item.sortable.dropindex
sourceModel = ui.item.sortable.sourceModel
droptargetModel = ui.item.sortable.droptargetModel
model = ui.item.sortable.model
if sourceModel == 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"
, () ->
#put model back in orginal poisition
sourceModel.splice orig_index, 0, model
#remove from target array
droptargetModel.splice new_idex, 1
return