2
0

swimlaneHeader.js 3.6 KB

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