sidebarCustomFields.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. BlazeComponent.extendComponent({
  2. customFields() {
  3. return CustomFields.find({
  4. boardId: Session.get('currentBoard'),
  5. });
  6. },
  7. events() {
  8. return [{
  9. 'click .js-open-create-custom-field': Popup.open('createCustomField'),
  10. 'click .js-edit-custom-field': Popup.open('editCustomField'),
  11. }];
  12. },
  13. }).register('customFieldsSidebar');
  14. Template.createCustomFieldPopup.helpers({
  15. types() {
  16. var currentType = this.type;
  17. return ['text', 'number', 'checkbox', 'date', 'dropdown'].
  18. map(type => {return {
  19. type: type,
  20. name: TAPi18n.__('custom-field-' + type),
  21. selected: type == currentType,
  22. }});
  23. },
  24. });
  25. Template.createCustomFieldPopup.events({
  26. 'click .js-field-show-on-card'(event) {
  27. let $target = $(event.target);
  28. if(!$target.hasClass('js-field-show-on-card')){
  29. $target = $target.parent();
  30. }
  31. $target.find('.materialCheckBox').toggleClass('is-checked');
  32. $target.toggleClass('is-checked');
  33. },
  34. 'submit'(evt, tpl) {
  35. evt.preventDefault();
  36. const name = tpl.find('.js-field-name').value.trim();
  37. const type = tpl.find('.js-field-type').value.trim();
  38. const showOnCard = tpl.find('.js-field-show-on-card.is-checked') != null;
  39. //console.log('Create',name,type,showOnCard);
  40. CustomFields.insert({
  41. boardId: Session.get('currentBoard'),
  42. name: name,
  43. type: type,
  44. showOnCard: showOnCard
  45. });
  46. Popup.back();
  47. },
  48. 'click .js-delete-custom-field': Popup.afterConfirm('deleteCustomField', function() {
  49. const customFieldId = this._id;
  50. CustomFields.remove(customFieldId);
  51. Popup.close();
  52. }),
  53. });
  54. /*Template.deleteCustomFieldPopup.events({
  55. 'submit'(evt) {
  56. const customFieldId = this._id;
  57. CustomFields.remove(customFieldId);
  58. Popup.close();
  59. }
  60. });*/