Fix new kanban card deleted on content update

pull/1/head
yflory 5 years ago
parent 04af753a81
commit daa4675a44

@ -761,6 +761,9 @@ define([
var isTop = $el.attr('data-top'); var isTop = $el.attr('data-top');
var boardId = $el.closest('.kanban-board').attr("data-id"); var boardId = $el.closest('.kanban-board').attr("data-id");
var $item = $('<div>', {'class': 'kanban-item new-item'}); var $item = $('<div>', {'class': 'kanban-item new-item'});
if (isTop) {
$item.addClass('item-top');
}
var $input = getInput().val(name).appendTo($item); var $input = getInput().val(name).appendTo($item);
kanban.addForm(boardId, $item[0], isTop); kanban.addForm(boardId, $item[0], isTop);
$input.focus(); $input.focus();
@ -1059,6 +1062,7 @@ define([
} else if (!$el.length) { } else if (!$el.length) {
$el = $container.find('[data-eid="'+id+'"]'); $el = $container.find('[data-eid="'+id+'"]');
} }
var isTop = $el && $el.hasClass('item-top');
if (!$el.length) { return; } if (!$el.length) { return; }
var $input = $el.find('input'); var $input = $el.find('input');
if (!$input.length) { return; } if (!$input.length) { return; }
@ -1077,6 +1081,7 @@ define([
value: val, value: val,
start: start, start: start,
end: end, end: end,
isTop: isTop,
oldValue: oldVal oldValue: oldVal
}; };
} catch (e) { } catch (e) {
@ -1092,8 +1097,10 @@ define([
// An item was being added: add a new item // An item was being added: add a new item
if (id === "new" && !data.oldValue) { if (id === "new" && !data.oldValue) {
var $newBoard = $('.kanban-board[data-id="'+data.newBoard+'"]'); var $newBoard = $('.kanban-board[data-id="'+data.newBoard+'"]');
$newBoard.find('.kanban-title-button').click(); var topSelector = ':not([data-top])';
var $newInput = $newBoard.find('.kanban-item:last-child input'); if (data.isTop) { topSelector = '[data-top]'; }
$newBoard.find('.kanban-title-button' + topSelector).click();
var $newInput = $newBoard.find('.kanban-item.new-item input');
$newInput.val(data.value); $newInput.val(data.value);
$newInput[0].selectionStart = data.start; $newInput[0].selectionStart = data.start;
$newInput[0].selectionEnd = data.end; $newInput[0].selectionEnd = data.end;

Loading…
Cancel
Save