Fix drag&drop issues

pull/1/head
yflory 5 years ago
parent a901905ae5
commit 0fc5a456df

@ -536,7 +536,7 @@ define([
patchTransformer: options.patchTransformer || ChainPad.SmartJSONTransformer, patchTransformer: options.patchTransformer || ChainPad.SmartJSONTransformer,
// cryptpad debug logging (default is 1) // cryptpad debug logging (default is 1)
logLevel: 2, logLevel: 1,
validateContent: options.validateContent || function (content) { validateContent: options.validateContent || function (content) {
try { try {
JSON.parse(content); JSON.parse(content);

@ -94,6 +94,7 @@
}, },
accepts: function (el, target, source, sibling) { accepts: function (el, target, source, sibling) {
if (self.options.readOnly) { return false; } if (self.options.readOnly) { return false; }
if (sibling && sibling.getAttribute('id') === "kanban-addboard") { return false; }
return target.classList.contains('kanban-container') || return target.classList.contains('kanban-container') ||
target.classList.contains('kanban-trash'); target.classList.contains('kanban-trash');
}, },
@ -123,20 +124,24 @@
var id = Number($(el).attr('data-id')); var id = Number($(el).attr('data-id'));
var list = self.options.boards.list || []; var list = self.options.boards.list || [];
var index1 = list.indexOf(id);
if (index1 === -1) { return; }
// Move to trash? // Move to trash?
if (target.classList.contains('kanban-trash')) { if (target.classList.contains('kanban-trash')) {
var index1 = list.indexOf(id);
list.splice(index1, 1); list.splice(index1, 1);
delete self.options.boards.data[id]; delete self.options.boards.data[id];
self.onChange(); self.onChange();
return; return;
} }
var index1 = list.indexOf(id);
var index2; var index2;
if (sibling) { var id2 = Number($(sibling).attr("data-id"));
index2 = list.indexOf($(sibling).attr("data-id")); if (sibling && id2) {
} else { index2 = list.indexOf(id2);
}
// If we can't find the drop position, drop at the end
if (typeof(index2) === "undefined" || index2 === -1) {
index2 = list.length; index2 = list.length;
} }
@ -144,10 +149,11 @@
if (index1 < index2) { if (index1 < index2) {
index2 = index2 - 1; index2 = index2 - 1;
} }
list.splice(index2, 0, list.splice(index1, 1)[0]); list.splice(index1, 1);
list.splice(index2, 0, id);
// send event that board has changed // send event that board has changed
self.onChange(); self.onChange();
self.setBoards(self.options.boards);
}); });
//Init Drag Item //Init Drag Item
@ -227,11 +233,7 @@
// Remove the "move" effect // Remove the "move" effect
if (el !== null) { if (el !== null) {
self.options.dropEl(el, target, source, sibling);
el.classList.remove('is-moving'); el.classList.remove('is-moving');
if (typeof (el.dropfn) === 'function') {
el.dropfn(el, target, source, sibling);
}
} }
// Move the item // Move the item
@ -239,6 +241,7 @@
// send event that board has changed // send event that board has changed
self.onChange(); self.onChange();
self.setBoards(self.options.boards);
}) })
} }
}; };
@ -483,7 +486,9 @@
}; };
this.removeBoard = function (board) { this.removeBoard = function (board) {
var id;
if (typeof (board) === 'string' || typeof (board) === "number") { if (typeof (board) === 'string' || typeof (board) === "number") {
id = board;
board = self.element.querySelector('[data-id="' + board + '"]'); board = self.element.querySelector('[data-id="' + board + '"]');
} }
if (board) { if (board) {
@ -493,6 +498,9 @@
self.onChange(); self.onChange();
} }
// Remove duplicates
if (id) { $('.kanban-board[data-id="' + board + '"]').remove(); }
return self; return self;
} }

Loading…
Cancel
Save