utils.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Utils = {
  2. // XXX We should remove these two methods
  3. goBoardId: function(_id) {
  4. var board = Boards.findOne(_id);
  5. return board && Router.go('Board', {
  6. _id: board._id,
  7. slug: board.slug
  8. });
  9. },
  10. goCardId: function(_id) {
  11. var card = Cards.findOne(_id);
  12. var board = Boards.findOne(card.boardId);
  13. return board && Router.go('Card', {
  14. cardId: card._id,
  15. boardId: board._id,
  16. slug: board.slug
  17. });
  18. },
  19. capitalize: function(string) {
  20. return string.charAt(0).toUpperCase() + string.slice(1);
  21. },
  22. getLabelIndex: function(boardId, labelId) {
  23. var board = Boards.findOne(boardId);
  24. var labels = {};
  25. _.each(board.labels, function(a, b) {
  26. labels[a._id] = b;
  27. });
  28. return {
  29. index: labels[labelId],
  30. key: function(key) {
  31. return 'labels.' + labels[labelId] + '.' + key;
  32. }
  33. };
  34. },
  35. // Determine the new sort index
  36. getSortIndex: function(prevCardDomElement, nextCardDomElement) {
  37. // If we drop the card to an empty column
  38. if (! prevCardDomElement && ! nextCardDomElement) {
  39. return 0;
  40. // If we drop the card in the first position
  41. } else if (! prevCardDomElement) {
  42. return Blaze.getData(nextCardDomElement).sort - 1;
  43. // If we drop the card in the last position
  44. } else if (! nextCardDomElement) {
  45. return Blaze.getData(prevCardDomElement).sort + 1;
  46. }
  47. // In the general case take the average of the previous and next element
  48. // sort indexes.
  49. else {
  50. var prevSortIndex = Blaze.getData(prevCardDomElement).sort;
  51. var nextSortIndex = Blaze.getData(nextCardDomElement).sort;
  52. return (prevSortIndex + nextSortIndex) / 2;
  53. }
  54. }
  55. };