swimlaneHeader.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. 'click .js-move-swimlane': Popup.open('moveSwimlane'),
  52. });
  53. Template.swimlaneActionPopup.events({
  54. isCommentOnly() {
  55. return Meteor.user().isCommentOnly();
  56. },
  57. });
  58. BlazeComponent.extendComponent({
  59. onCreated() {
  60. this.currentSwimlane = this.currentData();
  61. },
  62. events() {
  63. return [
  64. {
  65. submit(event) {
  66. event.preventDefault();
  67. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  68. const nextSwimlane = currentBoard.nextSwimlane(this.currentSwimlane);
  69. const titleInput = this.find('.swimlane-name-input');
  70. const title = titleInput.value.trim();
  71. const sortValue = calculateIndexData(
  72. this.currentSwimlane,
  73. nextSwimlane,
  74. 1,
  75. );
  76. const swimlaneType = currentBoard.isTemplatesBoard()
  77. ? 'template-swimlane'
  78. : 'swimlane';
  79. if (title) {
  80. Swimlanes.insert({
  81. title,
  82. boardId: Session.get('currentBoard'),
  83. sort: sortValue.base,
  84. type: swimlaneType,
  85. });
  86. titleInput.value = '';
  87. titleInput.focus();
  88. }
  89. // XXX ideally, we should move the popup to the newly
  90. // created swimlane so a user can add more than one swimlane
  91. // with a minimum of interactions
  92. Popup.close();
  93. },
  94. 'click .js-swimlane-template': Popup.open('searchElement'),
  95. },
  96. ];
  97. },
  98. }).register('swimlaneAddPopup');
  99. BlazeComponent.extendComponent({
  100. onCreated() {
  101. this.currentSwimlane = this.currentData();
  102. this.currentColor = new ReactiveVar(this.currentSwimlane.color);
  103. },
  104. colors() {
  105. return swimlaneColors.map(color => ({ color, name: '' }));
  106. },
  107. isSelected(color) {
  108. return this.currentColor.get() === color;
  109. },
  110. events() {
  111. return [
  112. {
  113. 'click .js-palette-color'() {
  114. this.currentColor.set(this.currentData().color);
  115. },
  116. 'click .js-submit'() {
  117. this.currentSwimlane.setColor(this.currentColor.get());
  118. Popup.close();
  119. },
  120. 'click .js-remove-color'() {
  121. this.currentSwimlane.setColor(null);
  122. Popup.close();
  123. },
  124. },
  125. ];
  126. },
  127. }).register('setSwimlaneColorPopup');