swimlaneHeader.js 3.4 KB

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