swimlaneHeader.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if (title) {
  45. Swimlanes.insert({
  46. title,
  47. boardId: Session.get('currentBoard'),
  48. sort: sortValue.base,
  49. });
  50. titleInput.value = '';
  51. titleInput.focus();
  52. }
  53. // XXX ideally, we should move the popup to the newly
  54. // created swimlane so a user can add more than one swimlane
  55. // with a minimum of interactions
  56. Popup.close();
  57. },
  58. }];
  59. },
  60. }).register('swimlaneAddPopup');
  61. BlazeComponent.extendComponent({
  62. onCreated() {
  63. this.currentSwimlane = this.currentData();
  64. this.currentColor = new ReactiveVar(this.currentSwimlane.color);
  65. },
  66. colors() {
  67. return swimlaneColors.map((color) => ({ color, name: '' }));
  68. },
  69. isSelected(color) {
  70. return this.currentColor.get() === color;
  71. },
  72. events() {
  73. return [{
  74. 'click .js-palette-color'() {
  75. this.currentColor.set(this.currentData().color);
  76. },
  77. 'click .js-submit' () {
  78. this.currentSwimlane.setColor(this.currentColor.get());
  79. Popup.close();
  80. },
  81. 'click .js-remove-color'() {
  82. this.currentSwimlane.setColor(null);
  83. Popup.close();
  84. },
  85. }];
  86. },
  87. }).register('setSwimlaneColorPopup');