body.js 3.6 KB

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