[英]How to wait for confirm dialog inside angular ui sortable callback
我正在使用angular ui sortable在列表之間拖放項目。 我想做的是(在某些拖放條件下)有一個確認對話框,如果用戶取消了該對話框,則將列表恢復為原始狀態。 我可以在update事件中使用ui.item.sortable.cancel()
方法,但是如果我使用返回承諾的模式,則無法弄清楚如何在取消時恢復列表。 這是我的控制器中的內容(modalService是一個引導$ 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
任何建議表示贊賞。
如果沒有一些主要的技巧,我將無法正常工作,因此我最終沒有在更新回調中使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.