helpers.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Template.cardMembersPopup.helpers({
  2. isCardMember: function() {
  3. var cardId = Template.parentData()._id;
  4. var cardMembers = Cards.findOne(cardId).members || [];
  5. return _.contains(cardMembers, this.userId);
  6. },
  7. user: function() {
  8. return Users.findOne(this.userId);
  9. }
  10. });
  11. Template.cardLabelsPopup.helpers({
  12. isLabelSelected: function(cardId) {
  13. return _.contains(Cards.findOne(cardId).labelIds, this._id);
  14. }
  15. });
  16. var labelColors;
  17. Meteor.startup(function() {
  18. labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
  19. });
  20. Template.createLabelPopup.helpers({
  21. // This is the default color for a new label. We search the first color that
  22. // is not already used in the board (although it's not a problem if two
  23. // labels have the same color).
  24. defaultColor: function() {
  25. var labels = this.labels || this.card.board().labels;
  26. var usedColors = _.pluck(labels, 'color');
  27. var availableColors = _.difference(labelColors, usedColors);
  28. return availableColors.length > 1 ? availableColors[0] : 'green';
  29. }
  30. });
  31. Template.formLabel.helpers({
  32. labels: function() {
  33. return _.map(labelColors, function(color) {
  34. return { color: color, name: '' };
  35. });
  36. }
  37. });
  38. Blaze.registerHelper('currentCard', function() {
  39. var cardId = Session.get('currentCard');
  40. if (cardId) {
  41. return Cards.findOne(cardId);
  42. }
  43. });