简体   繁体   English

Angular + Dragula-放下事件确认

[英]Angular + Dragula - Confirm on drop event

I would like to show a confirm modal dialog (UI Kit) when i drop an element in a new bag (I am using angular 1.4.8 and angular-dragula) . 当我将元素放入新包中时(我使用angular 1.4.8和angular-dragula),我想显示一个确认模式对话框(UI Kit)。 If I click ok, I want to continue the process, but if I click NO, i would like the element to come back to his origin bag. 如果单击“确定”,我想继续该过程,但是如果单击“否”,我希望该元素返回到他的原始包。

This is my code so far : 到目前为止,这是我的代码:

dragulaService.options($scope, 'tasks', {
    revertOnSpill: true
});

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id == 'done') {
        UIkit.modal.confirm("Are you sure?", function(){
            console.log('drag confirmed');
        }, function(){
            // the function cancelling the drop...
        });
    } else {
        console.log('drag confirmed - no modal required');
    }
});

So far my dialog is showing perfectly, and if I click NO, the event is triggered, I just cant find how to cancel the drop ( I tried to find on dragula's documentation, but couldnt make it work. 到目前为止,我的对话框显示得非常完美,如果我单击“否”,则事件被触发,我只是无法找到取消取消操作的方法(我试图在dragula的文档中找到,但是无法使其工作。

Thank you. 谢谢。

I think you will have to do this manually, Dragula doesn't seem to provide a built-in mechanism for this. 我认为您将必须手动执行此操作,Dragula似乎并未为此提供内置的机制。 Once an item is dropped into the container, it is added to the DOM. 将项目放入容器后,便将其添加到DOM。

You will have to remove the element and put it back to the source container. 您将必须删除元素并将其放回源容器。

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id === "done" && source[0].id !== "done") {
        UIkit.modal.confirm("Are you sure?", function(){}, function(){
            $(el).remove();
            $(source).append(el);
        });
    }
});

I added the source[0].id !== "done" to prevent the modal popping up if you reorder items in the "Done" container. 我添加了source[0].id !== "done"以防止在您对“ Done”容器中的项目重新排序时弹出模式。

Also note that this doesn't take the previous ordering of the source container into account. 还要注意,这并未考虑源容器的先前顺序。 It just appends the element as the last element. 它只是将元素追加为最后一个元素。

JSFiddle available here . JSFiddle 在这里可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM