body.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'boardComponent';
  4. },
  5. openNewListForm: function() {
  6. this.componentChildren('addListForm')[0].open();
  7. },
  8. showNewCardForms: function(value) {
  9. _.each(this.componentChildren('list'), function(listComponent) {
  10. listComponent.showNewCardForm(value);
  11. });
  12. },
  13. scrollLeft: function() {
  14. // TODO
  15. },
  16. onRendered: function() {
  17. var self = this;
  18. self.scrollLeft();
  19. if (Meteor.user().isBoardMember()) {
  20. self.$('.js-lists').sortable({
  21. tolerance: 'pointer',
  22. appendTo: '.js-lists',
  23. helper: 'clone',
  24. items: '.js-list:not(.add-list)',
  25. placeholder: 'list placeholder',
  26. start: function(event, ui) {
  27. $('.list.placeholder').height(ui.item.height());
  28. Popup.close();
  29. },
  30. stop: function() {
  31. self.$('.js-lists').find('.js-list:not(.add-list)').each(
  32. function(i, list) {
  33. var data = Blaze.getData(list);
  34. Lists.update(data._id, {
  35. $set: {
  36. sort: i
  37. }
  38. });
  39. }
  40. );
  41. }
  42. });
  43. // If there is no data in the board (ie, no lists) we autofocus the list
  44. // creation form by clicking on the corresponding element.
  45. if (self.data().lists().count() === 0) {
  46. this.openNewListForm();
  47. }
  48. }
  49. },
  50. sidebarSize: function() {
  51. var sidebar = this.componentChildren('boardSidebar')[0];
  52. if (Session.get('currentCard') !== null)
  53. return 'next-large-sidebar';
  54. else if (sidebar && sidebar.isOpen())
  55. return 'next-small-sidebar';
  56. }
  57. }).register('boardComponent');
  58. BlazeComponent.extendComponent({
  59. template: function() {
  60. return 'addListForm';
  61. },
  62. // Proxy
  63. open: function() {
  64. this.componentChildren('inlinedForm')[0].open();
  65. },
  66. events: function() {
  67. return [{
  68. submit: function(evt) {
  69. evt.preventDefault();
  70. var title = this.find('.list-name-input');
  71. if ($.trim(title.value)) {
  72. Lists.insert({
  73. title: title.value,
  74. boardId: Session.get('currentBoard'),
  75. sort: $('.list').length
  76. });
  77. title.value = '';
  78. }
  79. }
  80. }];
  81. }
  82. }).register('addListForm');