body.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 = _.once(function() {
  50. node.parentNode.removeChild(node);
  51. });
  52. if ($(node).hasClass('js-card-detail')) {
  53. $(node).css({
  54. flex: '0 0 0',
  55. padding: 0
  56. });
  57. $(lists).one(endTransitionEvents, removeNode);
  58. } else {
  59. removeNode();
  60. }
  61. }
  62. };
  63. if (! Meteor.user().isBoardMember())
  64. return;
  65. self.$(lists).sortable({
  66. tolerance: 'pointer',
  67. appendTo: '.js-lists',
  68. helper: 'clone',
  69. items: '.js-list:not(.js-list-composer)',
  70. placeholder: 'list placeholder',
  71. start: function(event, ui) {
  72. $('.list.placeholder').height(ui.item.height());
  73. Popup.close();
  74. },
  75. stop: function() {
  76. self.$('.js-lists').find('.js-list:not(.js-list-composer)').each(
  77. function(i, list) {
  78. var data = Blaze.getData(list);
  79. Lists.update(data._id, {
  80. $set: {
  81. sort: i
  82. }
  83. });
  84. }
  85. );
  86. }
  87. });
  88. // If there is no data in the board (ie, no lists) we autofocus the list
  89. // creation form by clicking on the corresponding element.
  90. if (self.data().lists().count() === 0) {
  91. this.openNewListForm();
  92. }
  93. },
  94. sidebarSize: function() {
  95. var sidebar = this.componentChildren('sidebar')[0];
  96. if (sidebar && sidebar.isOpen())
  97. return 'next-sidebar';
  98. }
  99. }).register('boardComponent');
  100. BlazeComponent.extendComponent({
  101. template: function() {
  102. return 'addListForm';
  103. },
  104. // Proxy
  105. open: function() {
  106. this.componentChildren('inlinedForm')[0].open();
  107. },
  108. events: function() {
  109. return [{
  110. submit: function(evt) {
  111. evt.preventDefault();
  112. var title = this.find('.list-name-input');
  113. if ($.trim(title.value)) {
  114. Lists.insert({
  115. title: title.value,
  116. boardId: Session.get('currentBoard'),
  117. sort: $('.list').length
  118. });
  119. title.value = '';
  120. }
  121. }
  122. }];
  123. }
  124. }).register('addListForm');