swimlaneHeader.js 3.4 KB

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