2
0

body.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'listBody';
  4. },
  5. mixins: function() {
  6. return [Mixins.PerfectScrollbar];
  7. },
  8. isSelected: function() {
  9. return Session.equals('currentCard', this.currentData()._id);
  10. },
  11. openForm: function(options) {
  12. options = options || {};
  13. options.position = options.position || 'top';
  14. var forms = this.componentChildren('inlinedForm');
  15. var form = _.find(forms, function(component) {
  16. return component.data().position === options.position;
  17. });
  18. if (! form && forms.length > 0) {
  19. form = forms[0];
  20. }
  21. form.open();
  22. },
  23. addCard: function(evt) {
  24. evt.preventDefault();
  25. var textarea = $(evt.currentTarget).find('textarea');
  26. var title = textarea.val();
  27. var position = Blaze.getData(evt.currentTarget).position;
  28. var sortIndex;
  29. if (position === 'top') {
  30. sortIndex = Utils.getSortIndex(null, this.find('.js-minicard:first'));
  31. } else if (position === 'bottom') {
  32. sortIndex = Utils.getSortIndex(this.find('.js-minicard:last'), null);
  33. }
  34. // Clear the form in-memory cache
  35. // var inputCacheKey = "addCard-" + this.listId;
  36. // InputsCache.set(inputCacheKey, '');
  37. // title trim if not empty then
  38. if ($.trim(title)) {
  39. Cards.insert({
  40. title: title,
  41. listId: this.data()._id,
  42. boardId: this.data().board()._id,
  43. sort: sortIndex
  44. }, function(err, _id) {
  45. // In case the filter is active we need to add the newly
  46. // inserted card in the list of exceptions -- cards that are
  47. // not filtered. Otherwise the card will disappear instantly.
  48. // See https://github.com/libreboard/libreboard/issues/80
  49. Filter.addException(_id);
  50. });
  51. // We keep the form opened, empty it, and scroll to it.
  52. textarea.val('').focus();
  53. Utils.Scroll(this.find('.js-minicards')).top(1000, true);
  54. }
  55. },
  56. showNewCardForm: function(value) {
  57. this.newCardFormIsVisible.set(value);
  58. },
  59. scrollToBottom: function() {
  60. var $container = $(this.firstNode());
  61. $container.animate({
  62. scrollTop: $container.height()
  63. });
  64. },
  65. onCreated: function() {
  66. this.newCardFormIsVisible = new ReactiveVar(true);
  67. },
  68. events: function() {
  69. return [{
  70. submit: this.addCard,
  71. 'click .open-card-composer': this.scrollToBottom
  72. }];
  73. }
  74. }).register('listBody');
  75. BlazeComponent.extendComponent({
  76. template: function() {
  77. return 'addCardForm';
  78. },
  79. pressKey: function(evt) {
  80. // Pressing Enter should submit the card
  81. if (evt.keyCode === 13) {
  82. evt.preventDefault();
  83. $(evt.currentTarget).parents('form:first').submit();
  84. // Pressing Tab should open the form of the next column, and Maj+Tab go
  85. // in the reverse order
  86. } else if (evt.keyCode === 9) {
  87. evt.preventDefault();
  88. var isReverse = evt.shiftKey;
  89. var list = $('#js-list-' + this.data().listId);
  90. var listSelector = '.js-list:not(.js-add-list)';
  91. var nextList = list[isReverse ? 'prev' : 'next'](listSelector).get(0);
  92. // If there isn't no next list, loop back to the beginning.
  93. if (! nextList) {
  94. nextList = $(listSelector + (isReverse ? ':last' : ':first')).get(0);
  95. }
  96. BlazeComponent.getComponentForElement(nextList).openForm({
  97. position:this.data().position
  98. });
  99. }
  100. },
  101. events: function() {
  102. return [{
  103. keydown: this.pressKey
  104. }];
  105. }
  106. }).register('addCardForm');