listHeader.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. BlazeComponent.extendComponent({
  2. template() {
  3. return 'listHeader';
  4. },
  5. editTitle(evt) {
  6. evt.preventDefault();
  7. const newTitle = this.componentChildren('inlinedForm')[0].getValue();
  8. const list = this.currentData();
  9. if ($.trim(newTitle)) {
  10. list.rename(newTitle);
  11. }
  12. },
  13. events() {
  14. return [{
  15. 'click .js-open-list-menu': Popup.open('listAction'),
  16. submit: this.editTitle,
  17. }];
  18. },
  19. }).register('listHeader');
  20. Template.listActionPopup.events({
  21. 'click .js-add-card'() {
  22. const listDom = document.getElementById(`js-list-${this._id}`);
  23. const listComponent = BlazeComponent.getComponentForElement(listDom);
  24. listComponent.openForm({ position: 'top' });
  25. Popup.close();
  26. },
  27. 'click .js-list-subscribe'() {},
  28. 'click .js-select-cards'() {
  29. const cardIds = this.allCards().map((card) => card._id);
  30. MultiSelection.add(cardIds);
  31. Popup.close();
  32. },
  33. 'click .js-import-card': Popup.open('listImportCard'),
  34. 'click .js-move-cards': Popup.open('listMoveCards'),
  35. 'click .js-archive-cards': Popup.afterConfirm('listArchiveCards', function() {
  36. this.allCards().forEach((card) => {
  37. card.archive();
  38. });
  39. Popup.close();
  40. }),
  41. 'click .js-close-list'(evt) {
  42. evt.preventDefault();
  43. this.archive();
  44. Popup.close();
  45. },
  46. });
  47. Template.listImportCardPopup.events({
  48. submit(evt) {
  49. // 1. get the json data out of the form and parse it
  50. evt.preventDefault();
  51. const jsonData = $(evt.currentTarget).find('textarea').val();
  52. const firstCardDom = $(`#js-list-${this._id} .js-minicard:first`).get(0);
  53. const sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  54. try {
  55. const trelloCard = JSON.parse(jsonData);
  56. const cardId = Meteor.call('importTrelloCard', trelloCard, this._id, sortIndex);
  57. // In case the filter is active we need to add the newly inserted card in
  58. // the list of exceptions -- cards that are not filtered. Otherwise the
  59. // card will disappear instantly.
  60. // See https://github.com/wekan/wekan/issues/80
  61. Filter.addException(cardId);
  62. Popup.close();
  63. } catch(e) {
  64. // XXX handle error
  65. // this.error.set('avatar-too-big');
  66. console.log('Invalid JSON');
  67. return;
  68. }
  69. },
  70. });
  71. Template.listMoveCardsPopup.events({
  72. 'click .js-select-list'() {
  73. const fromList = Template.parentData(2).data;
  74. const toList = this._id;
  75. fromList.allCards().forEach((card) => {
  76. card.move(toList);
  77. });
  78. Popup.close();
  79. },
  80. });