cardCustomFields.js 4.3 KB

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