cardCustomFields.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. Template.cardCustomFieldsPopup.helpers({
  2. hasCustomField() {
  3. const card = Cards.findOne(Session.get('currentCard'));
  4. const customFieldId = this._id;
  5. return card.customFieldIndex(customFieldId) > -1;
  6. },
  7. });
  8. Template.cardCustomFieldsPopup.events({
  9. 'click .js-select-field'(evt) {
  10. const card = Cards.findOne(Session.get('currentCard'));
  11. const customFieldId = this._id;
  12. card.toggleCustomField(customFieldId);
  13. evt.preventDefault();
  14. },
  15. 'click .js-settings'(evt) {
  16. EscapeActions.executeUpTo('detailsPane');
  17. Sidebar.setView('customFields');
  18. evt.preventDefault();
  19. },
  20. });
  21. // cardCustomField
  22. const CardCustomField = BlazeComponent.extendComponent({
  23. getTemplate() {
  24. return `cardCustomField-${this.data().definition.type}`;
  25. },
  26. onCreated() {
  27. const self = this;
  28. self.card = Cards.findOne(Session.get('currentCard'));
  29. self.customFieldId = this.data()._id;
  30. },
  31. canModifyCard() {
  32. return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly();
  33. },
  34. });
  35. CardCustomField.register('cardCustomField');
  36. // cardCustomField-text
  37. (class extends CardCustomField {
  38. onCreated() {
  39. super.onCreated();
  40. }
  41. events() {
  42. return [{
  43. 'submit .js-card-customfield-text'(evt) {
  44. evt.preventDefault();
  45. const value = this.currentComponent().getValue();
  46. this.card.setCustomField(this.customFieldId, value);
  47. },
  48. }];
  49. }
  50. }).register('cardCustomField-text');
  51. // cardCustomField-number
  52. (class extends CardCustomField {
  53. onCreated() {
  54. super.onCreated();
  55. }
  56. events() {
  57. return [{
  58. 'submit .js-card-customfield-number'(evt) {
  59. evt.preventDefault();
  60. const value = parseInt(this.find('input').value, 10);
  61. this.card.setCustomField(this.customFieldId, value);
  62. },
  63. }];
  64. }
  65. }).register('cardCustomField-number');
  66. // cardCustomField-date
  67. (class extends CardCustomField {
  68. onCreated() {
  69. super.onCreated();
  70. const self = this;
  71. self.date = ReactiveVar();
  72. self.now = ReactiveVar(moment());
  73. window.setInterval(() => {
  74. self.now.set(moment());
  75. }, 60000);
  76. self.autorun(() => {
  77. self.date.set(moment(self.data().value));
  78. });
  79. }
  80. showDate() {
  81. // this will start working once mquandalle:moment
  82. // is updated to at least moment.js 2.10.5
  83. // until then, the date is displayed in the "L" format
  84. return this.date.get().calendar(null, {
  85. sameElse: 'llll',
  86. });
  87. }
  88. showISODate() {
  89. return this.date.get().toISOString();
  90. }
  91. classes() {
  92. if (this.date.get().isBefore(this.now.get(), 'minute') &&
  93. this.now.get().isBefore(this.data().value)) {
  94. return 'current';
  95. }
  96. return '';
  97. }
  98. showTitle() {
  99. return `${TAPi18n.__('card-start-on')} ${this.date.get().format('LLLL')}`;
  100. }
  101. events() {
  102. return [{
  103. 'click .js-edit-date': Popup.open('cardCustomField-date'),
  104. }];
  105. }
  106. }).register('cardCustomField-date');
  107. // cardCustomField-datePopup
  108. (class extends DatePicker {
  109. onCreated() {
  110. super.onCreated();
  111. const self = this;
  112. self.card = Cards.findOne(Session.get('currentCard'));
  113. self.customFieldId = this.data()._id;
  114. this.data().value && this.date.set(moment(this.data().value));
  115. }
  116. _storeDate(date) {
  117. this.card.setCustomField(this.customFieldId, date);
  118. }
  119. _deleteDate() {
  120. this.card.setCustomField(this.customFieldId, '');
  121. }
  122. }).register('cardCustomField-datePopup');
  123. // cardCustomField-dropdown
  124. (class extends CardCustomField {
  125. onCreated() {
  126. super.onCreated();
  127. this._items = this.data().definition.settings.dropdownItems;
  128. this.items = this._items.slice(0);
  129. this.items.unshift({
  130. _id: '',
  131. name: TAPi18n.__('custom-field-dropdown-none'),
  132. });
  133. }
  134. selectedItem() {
  135. const selected = this._items.find((item) => {
  136. return item._id === this.data().value;
  137. });
  138. return (selected) ? selected.name : TAPi18n.__('custom-field-dropdown-unknown');
  139. }
  140. events() {
  141. return [{
  142. 'submit .js-card-customfield-dropdown'(evt) {
  143. evt.preventDefault();
  144. const value = this.find('select').value;
  145. this.card.setCustomField(this.customFieldId, value);
  146. },
  147. }];
  148. }
  149. }).register('cardCustomField-dropdown');