cardActions.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. let cardColors;
  2. Meteor.startup(() => {
  3. cardColors = Cards.simpleSchema()._schema.color.allowedValues;
  4. });
  5. BlazeComponent.extendComponent({
  6. onCreated() {
  7. this.subscribe('allRules');
  8. },
  9. labels() {
  10. const labels = Boards.findOne(Session.get('currentBoard')).labels;
  11. for (let i = 0; i < labels.length; i++) {
  12. if (labels[i].name === '' || labels[i].name === undefined) {
  13. labels[i].name = labels[i].color.toUpperCase();
  14. }
  15. }
  16. return labels;
  17. },
  18. events() {
  19. return [{
  20. 'click .js-add-label-action' (event) {
  21. const ruleName = this.data().ruleName.get();
  22. const trigger = this.data().triggerVar.get();
  23. const actionSelected = this.find('#label-action').value;
  24. const labelId = this.find('#label-id').value;
  25. const boardId = Session.get('currentBoard');
  26. const desc = Utils.getTriggerActionDesc(event, this);
  27. if (actionSelected === 'add') {
  28. const triggerId = Triggers.insert(trigger);
  29. const actionId = Actions.insert({
  30. actionType: 'addLabel',
  31. labelId,
  32. boardId,
  33. desc,
  34. });
  35. Rules.insert({
  36. title: ruleName,
  37. triggerId,
  38. actionId,
  39. boardId,
  40. });
  41. }
  42. if (actionSelected === 'remove') {
  43. const triggerId = Triggers.insert(trigger);
  44. const actionId = Actions.insert({
  45. actionType: 'removeLabel',
  46. labelId,
  47. boardId,
  48. desc,
  49. });
  50. Rules.insert({
  51. title: ruleName,
  52. triggerId,
  53. actionId,
  54. boardId,
  55. });
  56. }
  57. },
  58. 'click .js-add-member-action' (event) {
  59. const ruleName = this.data().ruleName.get();
  60. const trigger = this.data().triggerVar.get();
  61. const actionSelected = this.find('#member-action').value;
  62. const username = this.find('#member-name').value;
  63. const boardId = Session.get('currentBoard');
  64. const desc = Utils.getTriggerActionDesc(event, this);
  65. if (actionSelected === 'add') {
  66. const triggerId = Triggers.insert(trigger);
  67. const actionId = Actions.insert({
  68. actionType: 'addMember',
  69. username,
  70. boardId,
  71. desc,
  72. });
  73. Rules.insert({
  74. title: ruleName,
  75. triggerId,
  76. actionId,
  77. boardId,
  78. desc,
  79. });
  80. }
  81. if (actionSelected === 'remove') {
  82. const triggerId = Triggers.insert(trigger);
  83. const actionId = Actions.insert({
  84. actionType: 'removeMember',
  85. username,
  86. boardId,
  87. desc,
  88. });
  89. Rules.insert({
  90. title: ruleName,
  91. triggerId,
  92. actionId,
  93. boardId,
  94. });
  95. }
  96. },
  97. 'click .js-add-removeall-action' (event) {
  98. const ruleName = this.data().ruleName.get();
  99. const trigger = this.data().triggerVar.get();
  100. const triggerId = Triggers.insert(trigger);
  101. const desc = Utils.getTriggerActionDesc(event, this);
  102. const boardId = Session.get('currentBoard');
  103. const actionId = Actions.insert({
  104. actionType: 'removeMember',
  105. 'username': '*',
  106. boardId,
  107. desc,
  108. });
  109. Rules.insert({
  110. title: ruleName,
  111. triggerId,
  112. actionId,
  113. boardId,
  114. });
  115. },
  116. 'click .js-show-color-palette'(event){
  117. const funct = Popup.open('setCardActionsColor');
  118. const colorButton = this.find('#color-action');
  119. if (colorButton.value === '') {
  120. colorButton.value = 'green';
  121. }
  122. funct.call(this, event);
  123. },
  124. 'click .js-set-color-action' (event) {
  125. const ruleName = this.data().ruleName.get();
  126. const trigger = this.data().triggerVar.get();
  127. const colorButton = this.find('#color-action');
  128. if (colorButton.value === '') {
  129. colorButton.value = 'green';
  130. }
  131. const selectedColor = colorButton.value;
  132. const boardId = Session.get('currentBoard');
  133. const desc = Utils.getTriggerActionDesc(event, this);
  134. const triggerId = Triggers.insert(trigger);
  135. const actionId = Actions.insert({
  136. actionType: 'setColor',
  137. selectedColor,
  138. boardId,
  139. desc,
  140. });
  141. Rules.insert({
  142. title: ruleName,
  143. triggerId,
  144. actionId,
  145. boardId,
  146. });
  147. },
  148. }];
  149. },
  150. }).register('cardActions');
  151. BlazeComponent.extendComponent({
  152. onCreated() {
  153. this.currentAction = this.currentData();
  154. this.colorButton = Popup.getOpenerComponent().find('#color-action');
  155. this.currentColor = new ReactiveVar(this.colorButton.value);
  156. },
  157. colors() {
  158. return cardColors.map((color) => ({ color, name: '' }));
  159. },
  160. isSelected(color) {
  161. return this.currentColor.get() === color;
  162. },
  163. events() {
  164. return [{
  165. 'click .js-palette-color'() {
  166. this.currentColor.set(this.currentData().color);
  167. },
  168. 'click .js-submit' () {
  169. this.colorButton.classList.remove(`card-details-${ this.colorButton.value }`);
  170. this.colorButton.value = this.currentColor.get();
  171. this.colorButton.innerText = `${TAPi18n.__(`color-${ this.currentColor.get() }`)}`;
  172. this.colorButton.classList.add(`card-details-${ this.colorButton.value }`);
  173. Popup.close();
  174. },
  175. }];
  176. },
  177. }).register('setCardActionsColorPopup');