swimlaneHeader.js 3.1 KB

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