riktar / jkanban

Vanilla Javascript plugin for manage kanban boards
https://www.riccardotartaglia.it/jkanban/
Apache License 2.0
1.06k stars 296 forks source link

Howto read DropTo option value for a specific board? #144

Closed bairog closed 2 years ago

bairog commented 2 years ago

Hello and thank you for your awesome library. As I can see dropEl callback fires even if item cannot be dragged to the target board (DragTo option of the source board doesn't have target board Id in it). I need to identify such situations (and don't perform all logic that is called in case of "allowed" drag). I've started with the following code but I have no idea howto read DropTo option value here (I pass an extra jKanban value in my function because I need it to find a board):

function onDropEl(jKanban, el, target, source, sibling) {
    //FIRST variant to get targetBoardId
    var targetBoardId = target.parentElement.getAttribute('data-id');

    //SECOND variant to get targetBoardId - which of two is the correct one???
    var targetBoardId2 = target.parentElement.dataset.id;

    var targetBoard = jKanban.findBoard(targetBoardId);
   //Howto read DropTo option value here??? 

}
xscode-auto-reply[bot] commented 2 years ago

Thanks for opening a new issue. The team has been notified and will review it as soon as possible. For urgent issues and priority support, visit https://xscode.com/riktar/jkanban

bairog commented 2 years ago

@marcosrocha85 maybe you can help me and answer some of that questions?

marcosrocha85 commented 2 years ago

@bairog you can find a lot of others past "problems" in Closed issues. I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this https://github.com/riktar/jkanban/issues/22.

bairog commented 2 years ago

I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this #22.

Thank you I've used your code sample

var allowedBoards = [];
jkanban.options.boards.map(function (board) {
     if (board.id === $(source.parentElement).data("id")) {
          board.dragTo.map(function (_board) {
               if (allowedBoards.indexOf(_board) === -1) {
                    allowedBoards.push(_board);
               }
          });

          return allowedBoards[0];
     }

     return allowedBoards[0];
});

if (allowedBoards.length > 0 && allowedBoards.indexOf($(target.parentElement).data("id")) === -1) {
       kanban.drake.cancel(true);
       return;
}

but slightly modified and simplified it:

var allowedBoards = jkanban.options.boards.filter(b => b.id === source.parentElement.dataset.id)[0].dragTo;

if (allowedBoards.indexOf(target.parentElement.dataset.id) === -1) {
        jkanban.drake.cancel(true);
        return;
}
marcosrocha85 commented 2 years ago

I suggest you to take a look and try to figure out if some solution fits your needs. For instance, look at this #22.

Thank you I've used your code sample

var allowedBoards = [];
jkanban.options.boards.map(function (board) {
     if (board.id === $(source.parentElement).data("id")) {
          board.dragTo.map(function (_board) {
               if (allowedBoards.indexOf(_board) === -1) {
                    allowedBoards.push(_board);
               }
          });

          return allowedBoards[0];
     }

     return allowedBoards[0];
});

if (allowedBoards.length > 0 && allowedBoards.indexOf($(target.parentElement).data("id")) === -1) {
       kanban.drake.cancel(true);
       return;
}

but slightly modified and simplified it:

var allowedBoards = jkanban.options.boards.filter(b => b.id === source.parentElement.dataset.id)[0].dragTo;

if (allowedBoards.indexOf(target.parentElement.dataset.id) === -1) {
        jkanban.drake.cancel(true);
        return;
}

Nicely done!!! At that time I wasn't able to use filter (I can't remember why). Please close the issue if your problem was solved. I suggest you to create different issues for different questions.

bairog commented 2 years ago

Please close the issue if your problem was solved. I suggest you to create different issues for different questions.

Closed this one as my DropTo issue is solved now. Created separate issues: #148 for ItemHover and #149 for AddForm