mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
#3294 asked for a checklist item to become a card when dragged out onto a list, and to be marked done when dropped onto a "Done"-style list instead. A checklist item was already draggable via its own jQuery UI sortable (scoped to other checklists via connectWith '.js-checklist-items'), so dropping it anywhere else - a list's own card column - always reverted with no effect at all. The sortable's stop handler now checks, via document.elementFromPoint at the drop coordinates, whether the release landed over a list's '.js-minicards' card column rather than back inside a checklist. When it does, a new card is created titled from the item's text, in that list (and swimlane, resolved the same way list.js's own card-drop handler resolves it), through a pure buildCardFromChecklistItem() helper (models/lib/checklistItemToCard.js) so the "what does the new card look like" logic is pinned by a test without a Meteor database. The original checklist item is left completely untouched either way - the drag always reverts visually (sortable('cancel')), since nothing needs to move within the checklist. Scope decision: dropping ALWAYS creates a new card. The "mark done when dropped on a Done-style list" half of the request is intentionally NOT built - detecting that a list "means" Done would mean guessing from its name or position, which is unreliable and would surprise users. That capability is not actually missing: an item can already be marked done directly via its own checkbox (ChecklistItems' toggleItem()), and WeKan also already has a manual, explicit "Convert to card" action (convertChecklistItemToCardPopup) for the same underlying card-creation case - this drag gesture is a faster path to the same outcome, not a new concept. Thanks to BenjamindeJong82 and xet7 ! Closes #3294,
32 lines
1.5 KiB
JavaScript
32 lines
1.5 KiB
JavaScript
/**
|
|
* #3294: build the document for a new card created when a checklist item is
|
|
* dragged off its checklist and dropped onto a list (client/components/
|
|
* cards/checklists.js's checklist-item sortable `stop` handler).
|
|
*
|
|
* Kept as a pure function - no Cards.insert() here - so "what does the new
|
|
* card look like" can be pinned by tests/checklistItemToCard.test.cjs without
|
|
* a Meteor database, and so the drag handler has one place to get it from
|
|
* rather than building the document inline.
|
|
*
|
|
* Scope decision (see the #3294 commit message): dropping ALWAYS creates a
|
|
* new card. There is no attempt here to guess that a particular target list
|
|
* "means" Done and mark the ORIGINAL checklist item finished instead of
|
|
* creating a card - that would require guessing a list's meaning from its
|
|
* name or position, which is unreliable heuristic behaviour that would
|
|
* surprise users. Marking an item done already has its own explicit,
|
|
* unambiguous action - the item's own checkbox (ChecklistItems' toggleItem())
|
|
* - so that capability is not missing, just not wired to this drag gesture.
|
|
*/
|
|
export function buildCardFromChecklistItem(item, list, swimlaneId, sort) {
|
|
if (!item || !item.title || !String(item.title).trim()) return null;
|
|
if (!list || !list._id || !list.boardId) return null;
|
|
|
|
return {
|
|
title: item.title,
|
|
listId: list._id,
|
|
boardId: list.boardId,
|
|
swimlaneId: swimlaneId || list.swimlaneId,
|
|
sort: typeof sort === 'number' && !Number.isNaN(sort) ? sort : 0,
|
|
};
|
|
}
|