bevacqua / angularjs-dragula

:ok_hand: Drag and drop so simple it hurts
https://bevacqua.github.io/angularjs-dragula
MIT License
509 stars 110 forks source link

How can I use drop event inside dragulaservice.options? #49

Closed flashimxd closed 8 years ago

flashimxd commented 8 years ago

I was using dragular (jquery version), and now, I just started to use the angular version. But, I can't handle the Drop event inside the options of dragular service. I'm trying to use this way:

dragulaService.options($scope, 'tasks', {

          moves: function (el, source, handle, sibling) {
            return true;                  
          },
          accepts: function (el, target, source, sibling) { 

           var owner_id   = parseInt($($(el).find('li')[0]).attr('userid')),
               user_id    = $cookies.getObject('user').id,
               user_name  = $(el).find('img')[0].title,
               id         = $(el).find('h3').html(),
               id         = id.replace(/#/g, "");

            if(user_id != owner_id){

                ngDialog.open({ 
                    plain: true,
                     template:'<p>Tem certeza que deseja assumir essa tarefa destinada há '+user_name+' ?</p>\
                     <div class="ngdialog-buttons"><button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog(0)">\
                     Não</button><button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="confirm()">Sim</button></div>',
                    scope: $scope
                });

                $scope.confirm =function(){

                    $scope.setOwner(id, user_id);
                    ngDialog.close();
                }

                return false;
            }

            console.log(target.id); 

            switch(source.id){
                case "A":
                    return target.id == "D";
                break;

                case "D":
                    return target.id !== "P";
                break;

                case "T":
                    return true;
                break;

                case "P":
                    return true;
                break;
            }

          },
          revertOnSpill: false,               
          removeOnSpill: false                
        });

Where I can put the drop event to know when the "task" is dropped in another place?

PS:: sorry for the bad english..

flashimxd commented 8 years ago

I solved the problem using:

$scope.$on('tasks.drop', function (container, el, target, source) { //dothings }

thx!