boardBody.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // XXX This event list must be abstracted somewhere else.
  2. var endTransitionEvents = [
  3. 'webkitTransitionEnd',
  4. 'otransitionend',
  5. 'oTransitionEnd',
  6. 'msTransitionEnd',
  7. 'transitionend'
  8. ].join(' ');
  9. BlazeComponent.extendComponent({
  10. template: function() {
  11. return 'boardComponent';
  12. },
  13. onCreated: function() {
  14. this.draggingActive = new ReactiveVar(false);
  15. },
  16. openNewListForm: function() {
  17. this.componentChildren('addListForm')[0].open();
  18. },
  19. setIsDragging: function(bool) {
  20. this.draggingActive.set(bool);
  21. },
  22. scrollLeft: function(position) {
  23. position = position || 0;
  24. var $container = $(this.find('.js-lists'));
  25. var containerWidth = $container.width();
  26. var currentScrollPosition = $container.scrollLeft();
  27. if (position < currentScrollPosition) {
  28. $container.animate({
  29. scrollLeft: position
  30. });
  31. } else if (position > currentScrollPosition + containerWidth) {
  32. $container.animate({
  33. scrollLeft: Math.max(0, position - containerWidth)
  34. });
  35. }
  36. },
  37. currentCardIsInThisList: function() {
  38. var currentCard = Cards.findOne(Session.get('currentCard'));
  39. var listId = this.currentData()._id;
  40. return currentCard && currentCard.listId === listId;
  41. },
  42. onRendered: function() {
  43. var self = this;
  44. self.scrollLeft();
  45. var lists = this.find('.js-lists');
  46. // We want to animate the card details window closing. We rely on CSS
  47. // transition for the actual animation.
  48. lists._uihooks = {
  49. removeElement: function(node) {
  50. var removeNode = _.once(function() {
  51. node.parentNode.removeChild(node);
  52. });
  53. if ($(node).hasClass('js-card-detail')) {
  54. $(node).css({
  55. flex: '0 0 0',
  56. padding: 0
  57. });
  58. $(lists).one(endTransitionEvents, removeNode);
  59. } else {
  60. removeNode();
  61. }
  62. }
  63. };
  64. if (! Meteor.userId() || ! Meteor.user().isBoardMember())
  65. return;
  66. self.$(lists).sortable({
  67. tolerance: 'pointer',
  68. appendTo: '.js-lists',
  69. helper: 'clone',
  70. items: '.js-list:not(.js-list-composer)',
  71. placeholder: 'list placeholder',
  72. start: function(evt, ui) {
  73. ui.placeholder.height(ui.helper.height());
  74. Popup.close();
  75. },
  76. stop: function() {
  77. self.$('.js-lists').find('.js-list:not(.js-list-composer)').each(
  78. function(i, list) {
  79. var data = Blaze.getData(list);
  80. Lists.update(data._id, {
  81. $set: {
  82. sort: i
  83. }
  84. });
  85. }
  86. );
  87. }
  88. });
  89. // Disable drag-dropping while in multi-selection mode
  90. self.autorun(function() {
  91. self.$(lists).sortable('option', 'disabled', MultiSelection.isActive());
  92. });
  93. // If there is no data in the board (ie, no lists) we autofocus the list
  94. // creation form by clicking on the corresponding element.
  95. if (self.data().lists().count() === 0) {
  96. this.openNewListForm();
  97. }
  98. },
  99. sidebarSize: function() {
  100. var sidebar = this.componentChildren('sidebar')[0];
  101. if (sidebar && sidebar.isOpen())
  102. return 'next-sidebar';
  103. }
  104. }).register('boardComponent');
  105. BlazeComponent.extendComponent({
  106. template: function() {
  107. return 'addListForm';
  108. },
  109. // Proxy
  110. open: function() {
  111. this.componentChildren('inlinedForm')[0].open();
  112. },
  113. events: function() {
  114. return [{
  115. submit: function(evt) {
  116. evt.preventDefault();
  117. var title = this.find('.list-name-input');
  118. if ($.trim(title.value)) {
  119. Lists.insert({
  120. title: title.value,
  121. boardId: Session.get('currentBoard'),
  122. sort: $('.list').length
  123. });
  124. title.value = '';
  125. }
  126. }
  127. }];
  128. }
  129. }).register('addListForm');