From 1b9df0049259438d001abd9c81f15ce8f7d25b14 Mon Sep 17 00:00:00 2001 From: Xavier Priour Date: Wed, 14 Oct 2015 00:32:44 +0200 Subject: Import single card: title and proper sort index --- client/components/lists/listHeader.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'client/components/lists') diff --git a/client/components/lists/listHeader.js b/client/components/lists/listHeader.js index 4f5fc3a0..28e7ab89 100644 --- a/client/components/lists/listHeader.js +++ b/client/components/lists/listHeader.js @@ -49,6 +49,32 @@ Template.listActionPopup.events({ }, }); +Template.listImportCardPopup.events({ + submit(evt, template) { + // 1. get the json data out of the form and parse it + evt.preventDefault(); + const jsonData = $(evt.currentTarget).find('textarea').val(); + const data = JSON.parse(jsonData); + // 2. map all fields for the card to create + const firstCardDom = $(`#js-list-${this._id} .js-minicard:first`).get(0); + sortIndex = Utils.calculateIndex(null, firstCardDom).base; + const cardToCreate = { + title: data.name, + listId: this._id, + boardId: this.boardId, + userId: Meteor.userId(), + sort: sortIndex, + } + // 3. finally, insert new card into list + const _id = Cards.insert(cardToCreate); + // In case the filter is active we need to add the newly inserted card in + // the list of exceptions -- cards that are not filtered. Otherwise the + // card will disappear instantly. + // See https://github.com/wekan/wekan/issues/80 + Filter.addException(_id); + } +}); + Template.listMoveCardsPopup.events({ 'click .js-select-list'() { const fromList = Template.parentData(2).data; -- cgit v1.2.3-1-g7c22