【问题标题】:How to wait for confirm dialog inside angular ui sortable callback如何在角度 ui 可排序回调中等待确认对话框
【发布时间】:2016-08-04 04:45:23
【问题描述】:

我正在使用可排序的 angular ui 在列表之间拖放项目。我想要做的是(在某些拖放条件下)有一个确认对话框,如果用户取消对话框,则将列表恢复为原始状态。我可以在更新事件中使用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

任何建议表示赞赏。

【问题讨论】:

    标签: angularjs bootstrap-modal jquery-ui-sortable angular-ui-sortable


    【解决方案1】:

    如果没有一些重大的黑客攻击,我无法让它工作,所以我最终没有在更新回调中使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 1970-01-01
      • 2010-12-17
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多