swimlaneHeader.js 3.4 KB

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