import.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /// Abstract root for all import popup screens.
  2. /// Descendants must define:
  3. /// - getMethodName(): return the Meteor method to call for import, passing json
  4. /// data decoded as object and additional data (see below);
  5. /// - getAdditionalData(): return object containing additional data passed to
  6. /// Meteor method (like list ID and position for a card import);
  7. /// - getLabel(): i18n key for the text displayed in the popup, usually to
  8. /// explain how to get the data out of the source system.
  9. const ImportPopup = BlazeComponent.extendComponent({
  10. template() {
  11. return 'importPopup';
  12. },
  13. events() {
  14. return [{
  15. 'submit': (evt) => {
  16. evt.preventDefault();
  17. const dataJson = $(evt.currentTarget).find('.js-import-json').val();
  18. let dataObject;
  19. try {
  20. dataObject = JSON.parse(dataJson);
  21. } catch (e) {
  22. this.setError('error-json-malformed');
  23. return;
  24. }
  25. Meteor.call(this.getMethodName(), dataObject, this.getAdditionalData(),
  26. (error, response) => {
  27. if (error) {
  28. this.setError(error.error);
  29. } else {
  30. Filter.addException(response);
  31. this.onFinish(response);
  32. }
  33. }
  34. );
  35. },
  36. }];
  37. },
  38. onCreated() {
  39. this.error = new ReactiveVar('');
  40. },
  41. setError(error) {
  42. this.error.set(error);
  43. },
  44. onFinish() {
  45. Popup.close();
  46. },
  47. });
  48. ImportPopup.extendComponent({
  49. getAdditionalData() {
  50. const listId = this.data()._id;
  51. const selector = `#js-list-${this.currentData()._id} .js-minicard:first`;
  52. const firstCardDom = $(selector).get(0);
  53. const sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  54. const result = {listId, sortIndex};
  55. return result;
  56. },
  57. getMethodName() {
  58. return 'importTrelloCard';
  59. },
  60. getLabel() {
  61. return 'import-card-trello-instruction';
  62. },
  63. }).register('listImportCardPopup');
  64. ImportPopup.extendComponent({
  65. getAdditionalData() {
  66. const result = {};
  67. return result;
  68. },
  69. getMethodName() {
  70. return 'importTrelloBoard';
  71. },
  72. getLabel() {
  73. return 'import-board-trello-instruction';
  74. },
  75. onFinish(response) {
  76. Utils.goBoardId(response);
  77. },
  78. }).register('boardImportBoardPopup');