swimlaneHeader.js 3.3 KB

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