2
0

swimlaneHeader.js 3.0 KB

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