From 468694a84cc164e4923f2d2e4631c37ceb1c4b55 Mon Sep 17 00:00:00 2001 From: Xavier Priour Date: Thu, 15 Oct 2015 14:01:13 +0200 Subject: Import board: added UI --- client/components/import/import.jade | 8 ++++ client/components/import/import.js | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 client/components/import/import.jade create mode 100644 client/components/import/import.js (limited to 'client/components/import') diff --git a/client/components/import/import.jade b/client/components/import/import.jade new file mode 100644 index 00000000..8059b65b --- /dev/null +++ b/client/components/import/import.jade @@ -0,0 +1,8 @@ +template(name="importPopup") + if error.get + .warning {{_ error.get}} + form + label + | {{_ getLabel}} + textarea.js-card-json(placeholder="{{_ 'import-json-placeholder'}}" autofocus) + input.primary.wide(type="submit" value="{{_ 'import'}}") diff --git a/client/components/import/import.js b/client/components/import/import.js new file mode 100644 index 00000000..f15185ed --- /dev/null +++ b/client/components/import/import.js @@ -0,0 +1,80 @@ +/** + * Abstract root for all import popup screens. + * Descendants must define: + * - getMethodName(): return the Meteor method to call for import, passing json data decoded as object + * and additional data (see below) + * - getAdditionalData(): return object containing additional data passed to Meteor method + * (like list ID and position for a card import) + * - getLabel(): i18n key for the text displayed in the popup, usually to explain how to get the data out of the + * source system. + */ +const ImportPopup = BlazeComponent.extendComponent({ + template() {return 'importPopup';}, + events() { + return [{ + 'submit': (evt) => { + evt.preventDefault(); + const dataJson = $(evt.currentTarget).find('textarea').val(); + let dataObject; + try { + dataObject = JSON.parse(dataJson); + } catch (e) { + this.setError('error-json-malformed'); + return; + } + Meteor.call(this.getMethodName(), dataObject, this.getAdditionalData(), + (error, response) => { + if (error) { + this.setError(error.error); + } else { + Filter.addException(response); + Popup.close(); + } + } + ); + }, + }]; + }, + + onCreated() { + this.error = new ReactiveVar(''); + }, + + setError(error) { + this.error.set(error); + }, +}); + +ImportPopup.extendComponent({ + getAdditionalData() { + const listId = this.data()._id; + const firstCardDom = $(`#js-list-${this.currentData()._id} .js-minicard:first`).get(0); + const sortIndex = Utils.calculateIndex(null, firstCardDom).base; + const result = {listId, sortIndex}; + return result; + }, + + getMethodName() { + return 'importTrelloCard'; + }, + + getLabel() { + return 'import-card-trello-instruction'; + }, +}).register('listImportCardPopup'); + +ImportPopup.extendComponent({ + getAdditionalData() { + const result = {}; + return result; + }, + + getMethodName() { + return 'importTrelloBoard'; + }, + + getLabel() { + return 'import-board-trello-instruction'; + }, +}).register('boardImportBoardPopup'); + -- cgit v1.2.3-1-g7c22