swimlaneHeader.js 2.8 KB

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