events.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. Template.cardMemberPopup.events({
  2. 'click .js-remove-member': function() {
  3. Cards.update(this.cardId, {$pull: {members: this.userId}});
  4. Popup.close();
  5. }
  6. });
  7. Template.WindowActivityModule.events({
  8. 'click .js-new-comment:not(.focus)': function(evt) {
  9. var $this = $(evt.currentTarget);
  10. $this.addClass('focus');
  11. },
  12. 'submit #CommentForm': function(evt, t) {
  13. var text = t.$('.js-new-comment-input');
  14. if ($.trim(text.val())) {
  15. CardComments.insert({
  16. boardId: this.card.boardId,
  17. cardId: this.card._id,
  18. text: text.val()
  19. });
  20. text.val('');
  21. $('.focus').removeClass('focus');
  22. }
  23. evt.preventDefault();
  24. }
  25. });
  26. Template.WindowSidebarModule.events({
  27. 'click .js-change-card-members': Popup.open('cardMembers'),
  28. 'click .js-edit-labels': Popup.open('cardLabels'),
  29. 'click .js-archive-card': function(evt) {
  30. // Update
  31. Cards.update(this.card._id, {
  32. $set: {
  33. archived: true
  34. }
  35. });
  36. evt.preventDefault();
  37. },
  38. 'click .js-unarchive-card': function(evt) {
  39. Cards.update(this.card._id, {
  40. $set: {
  41. archived: false
  42. }
  43. });
  44. evt.preventDefault();
  45. },
  46. 'click .js-delete-card': Popup.afterConfirm('cardDelete', function() {
  47. Cards.remove(this.card._id);
  48. // redirect board
  49. Utils.goBoardId(this.card.board()._id);
  50. Popup.close();
  51. }),
  52. 'click .js-more-menu': Popup.open('cardMore'),
  53. 'click .js-attach': Popup.open('cardAttachments')
  54. });
  55. Template.WindowAttachmentsModule.events({
  56. 'click .js-attach': Popup.open('cardAttachments'),
  57. 'click .js-confirm-delete': Popup.afterConfirm('attachmentDelete',
  58. function() {
  59. Attachments.remove(this._id);
  60. Popup.close();
  61. }
  62. ),
  63. // If we let this event bubble, Iron-Router will handle it and empty the
  64. // page content, see #101.
  65. 'click .js-open-viewer, click .js-download': function(event) {
  66. event.stopPropagation();
  67. },
  68. 'click .js-add-cover': function() {
  69. Cards.update(this.cardId, { $set: { coverId: this._id } });
  70. },
  71. 'click .js-remove-cover': function() {
  72. Cards.update(this.cardId, { $unset: { coverId: '' } });
  73. }
  74. });
  75. Template.cardMembersPopup.events({
  76. 'click .js-select-member': function(evt) {
  77. var cardId = Template.parentData(2).data._id;
  78. var memberId = this.userId;
  79. var operation;
  80. if (Cards.find({ _id: cardId, members: memberId}).count() === 0)
  81. operation = '$addToSet';
  82. else
  83. operation = '$pull';
  84. var query = {};
  85. query[operation] = {
  86. members: memberId
  87. };
  88. Cards.update(cardId, query);
  89. evt.preventDefault();
  90. }
  91. });
  92. Template.cardLabelsPopup.events({
  93. 'click .js-select-label': function(evt) {
  94. var cardId = Template.parentData(2).data._id;
  95. var labelId = this._id;
  96. var operation;
  97. if (Cards.find({ _id: cardId, labelIds: labelId}).count() === 0)
  98. operation = '$addToSet';
  99. else
  100. operation = '$pull';
  101. var query = {};
  102. query[operation] = {
  103. labelIds: labelId
  104. };
  105. Cards.update(cardId, query);
  106. evt.preventDefault();
  107. },
  108. 'click .js-edit-label': Popup.open('editLabel'),
  109. 'click .js-add-label': Popup.open('createLabel')
  110. });
  111. Template.formLabel.events({
  112. 'click .js-palette-color': function(evt) {
  113. var $this = $(evt.currentTarget);
  114. // hide selected ll colors
  115. $('.js-palette-select').addClass('hide');
  116. // show select color
  117. $this.find('.js-palette-select').removeClass('hide');
  118. }
  119. });
  120. Template.createLabelPopup.events({
  121. // Create the new label
  122. 'submit .create-label': function(evt, tpl) {
  123. var name = tpl.$('#labelName').val().trim();
  124. var boardId = Session.get('currentBoard');
  125. var selectLabelDom = tpl.$('.js-palette-select:not(.hide)').get(0);
  126. var selectLabel = Blaze.getData(selectLabelDom);
  127. Boards.update(boardId, {
  128. $push: {
  129. labels: {
  130. _id: Random.id(6),
  131. name: name,
  132. color: selectLabel.color
  133. }
  134. }
  135. });
  136. Popup.back();
  137. evt.preventDefault();
  138. }
  139. });
  140. Template.editLabelPopup.events({
  141. 'click .js-delete-label': Popup.afterConfirm('deleteLabel', function() {
  142. var boardId = Session.get('currentBoard');
  143. Boards.update(boardId, {
  144. $pull: {
  145. labels: {
  146. _id: this._id
  147. }
  148. }
  149. });
  150. Popup.back(2);
  151. }),
  152. 'submit .edit-label': function(evt, tpl) {
  153. var name = tpl.$('#labelName').val().trim();
  154. var boardId = Session.get('currentBoard');
  155. var getLabel = Utils.getLabelIndex(boardId, this._id);
  156. var selectLabelDom = tpl.$('.js-palette-select:not(.hide)').get(0);
  157. var selectLabel = Blaze.getData(selectLabelDom);
  158. var $set = {};
  159. // set label index
  160. $set[getLabel.key('name')] = name;
  161. // set color
  162. $set[getLabel.key('color')] = selectLabel.color;
  163. // update
  164. Boards.update(boardId, { $set: $set });
  165. // return to the previous popup view trigger
  166. Popup.back();
  167. evt.preventDefault();
  168. },
  169. 'click .js-select-label': function() {
  170. Cards.remove(this.cardId);
  171. // redirect board
  172. Utils.goBoardId(this.boardId);
  173. }
  174. });
  175. Template.cardMorePopup.events({
  176. 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
  177. Cards.remove(this.card._id);
  178. // redirect board
  179. Utils.goBoardId(this.card.board()._id);
  180. })
  181. });
  182. Template.cardAttachmentsPopup.events({
  183. 'change .js-attach-file': function(evt) {
  184. var card = this.card;
  185. FS.Utility.eachFile(evt, function(f) {
  186. var file = new FS.File(f);
  187. // set Ids
  188. file.boardId = card.boardId;
  189. file.cardId = card._id;
  190. // upload file
  191. Attachments.insert(file);
  192. Popup.close();
  193. });
  194. },
  195. 'click .js-computer-upload': function(evt, t) {
  196. t.find('.js-attach-file').click();
  197. evt.preventDefault();
  198. }
  199. });