swimlaneHeader.js 3.7 KB

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