swimlaneHeader.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. const { calculateIndexData } = Utils;
  2. let swimlaneColors;
  3. Meteor.startup(() => {
  4. swimlaneColors = Swimlanes.simpleSchema()._schema.color.allowedValues;
  5. });
  6. BlazeComponent.extendComponent({
  7. editTitle(event) {
  8. event.preventDefault();
  9. const newTitle = this.childComponents('inlinedForm')[0]
  10. .getValue()
  11. .trim();
  12. const swimlane = this.currentData();
  13. if (newTitle) {
  14. swimlane.rename(newTitle.trim());
  15. }
  16. },
  17. events() {
  18. return [
  19. {
  20. 'click .js-open-swimlane-menu': Popup.open('swimlaneAction'),
  21. 'click .js-open-add-swimlane-menu': Popup.open('swimlaneAdd'),
  22. submit: this.editTitle,
  23. },
  24. ];
  25. },
  26. }).register('swimlaneHeader');
  27. Template.swimlaneHeader.helpers({
  28. showDesktopDragHandles() {
  29. currentUser = Meteor.user();
  30. if (currentUser) {
  31. return (currentUser.profile || {}).showDesktopDragHandles;
  32. } else if (window.localStorage.getItem('showDesktopDragHandles')) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. },
  38. });
  39. Template.swimlaneFixedHeader.helpers({
  40. isBoardAdmin() {
  41. return Meteor.user().isBoardAdmin();
  42. },
  43. });
  44. Template.swimlaneActionPopup.events({
  45. 'click .js-set-swimlane-color': Popup.open('setSwimlaneColor'),
  46. 'click .js-close-swimlane'(event) {
  47. event.preventDefault();
  48. this.archive();
  49. Popup.close();
  50. },
  51. });
  52. Template.swimlaneActionPopup.helpers({
  53. isCommentOnly() {
  54. return Meteor.user().isCommentOnly();
  55. },
  56. });
  57. BlazeComponent.extendComponent({
  58. onCreated() {
  59. this.currentSwimlane = this.currentData();
  60. },
  61. events() {
  62. return [
  63. {
  64. submit(event) {
  65. event.preventDefault();
  66. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  67. const nextSwimlane = currentBoard.nextSwimlane(this.currentSwimlane);
  68. const titleInput = this.find('.swimlane-name-input');
  69. const title = titleInput.value.trim();
  70. const sortValue = calculateIndexData(
  71. this.currentSwimlane,
  72. nextSwimlane,
  73. 1,
  74. );
  75. const swimlaneType = currentBoard.isTemplatesBoard()
  76. ? 'template-swimlane'
  77. : 'swimlane';
  78. if (title) {
  79. Swimlanes.insert({
  80. title,
  81. boardId: Session.get('currentBoard'),
  82. sort: sortValue.base,
  83. type: swimlaneType,
  84. });
  85. titleInput.value = '';
  86. titleInput.focus();
  87. }
  88. // XXX ideally, we should move the popup to the newly
  89. // created swimlane so a user can add more than one swimlane
  90. // with a minimum of interactions
  91. Popup.close();
  92. },
  93. 'click .js-swimlane-template': Popup.open('searchElement'),
  94. },
  95. ];
  96. },
  97. }).register('swimlaneAddPopup');
  98. BlazeComponent.extendComponent({
  99. onCreated() {
  100. this.currentSwimlane = this.currentData();
  101. this.currentColor = new ReactiveVar(this.currentSwimlane.color);
  102. },
  103. colors() {
  104. return swimlaneColors.map(color => ({ color, name: '' }));
  105. },
  106. isSelected(color) {
  107. return this.currentColor.get() === color;
  108. },
  109. events() {
  110. return [
  111. {
  112. 'click .js-palette-color'() {
  113. this.currentColor.set(this.currentData().color);
  114. },
  115. 'click .js-submit'() {
  116. this.currentSwimlane.setColor(this.currentColor.get());
  117. Popup.close();
  118. },
  119. 'click .js-remove-color'() {
  120. this.currentSwimlane.setColor(null);
  121. Popup.close();
  122. },
  123. },
  124. ];
  125. },
  126. }).register('setSwimlaneColorPopup');