sidebar.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. Sidebar = null;
  2. const defaultView = 'home';
  3. const MCB = '.materialCheckBox';
  4. const CKCLS = 'is-checked';
  5. const viewTitles = {
  6. filter: 'filter-cards',
  7. search: 'search-cards',
  8. multiselection: 'multi-selection',
  9. customFields: 'custom-fields',
  10. archives: 'archives',
  11. };
  12. BlazeComponent.extendComponent({
  13. mixins() {
  14. return [Mixins.InfiniteScrolling];
  15. },
  16. onCreated() {
  17. this._isOpen = new ReactiveVar(false);
  18. this._view = new ReactiveVar(defaultView);
  19. Sidebar = this;
  20. },
  21. onDestroyed() {
  22. Sidebar = null;
  23. },
  24. isOpen() {
  25. return this._isOpen.get();
  26. },
  27. open() {
  28. if (!this._isOpen.get()) {
  29. this._isOpen.set(true);
  30. EscapeActions.executeUpTo('detailsPane');
  31. }
  32. },
  33. hide() {
  34. if (this._isOpen.get()) {
  35. this._isOpen.set(false);
  36. }
  37. },
  38. toggle() {
  39. this._isOpen.set(!this._isOpen.get());
  40. },
  41. calculateNextPeak() {
  42. const sidebarElement = this.find('.js-board-sidebar-content');
  43. if (sidebarElement) {
  44. const altitude = sidebarElement.scrollHeight;
  45. this.callFirstWith(this, 'setNextPeak', altitude);
  46. }
  47. },
  48. reachNextPeak() {
  49. const activitiesComponent = this.childComponents('activities')[0];
  50. activitiesComponent.loadNextPage();
  51. },
  52. isTongueHidden() {
  53. return this.isOpen() && this.getView() !== defaultView;
  54. },
  55. scrollTop() {
  56. this.$('.js-board-sidebar-content').scrollTop(0);
  57. },
  58. getView() {
  59. return this._view.get();
  60. },
  61. setView(view) {
  62. view = _.isString(view) ? view : defaultView;
  63. if (this._view.get() !== view) {
  64. this._view.set(view);
  65. this.scrollTop();
  66. EscapeActions.executeUpTo('detailsPane');
  67. }
  68. this.open();
  69. },
  70. isDefaultView() {
  71. return this.getView() === defaultView;
  72. },
  73. getViewTemplate() {
  74. return `${this.getView()}Sidebar`;
  75. },
  76. getViewTitle() {
  77. return TAPi18n.__(viewTitles[this.getView()]);
  78. },
  79. showTongueTitle() {
  80. if (this.isOpen()) return `${TAPi18n.__('sidebar-close')}`;
  81. else return `${TAPi18n.__('sidebar-open')}`;
  82. },
  83. events() {
  84. return [
  85. {
  86. 'click .js-hide-sidebar': this.hide,
  87. 'click .js-toggle-sidebar': this.toggle,
  88. 'click .js-back-home': this.setView,
  89. 'click .js-toggle-minicard-label-text'() {
  90. currentUser = Meteor.user();
  91. if (currentUser) {
  92. Meteor.call('toggleMinicardLabelText');
  93. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  94. window.localStorage.removeItem('hiddenMinicardLabelText');
  95. location.reload();
  96. } else {
  97. window.localStorage.setItem('hiddenMinicardLabelText', 'true');
  98. location.reload();
  99. }
  100. },
  101. 'click .js-shortcuts'() {
  102. FlowRouter.go('shortcuts');
  103. },
  104. },
  105. ];
  106. },
  107. }).register('sidebar');
  108. Blaze.registerHelper('Sidebar', () => Sidebar);
  109. Template.homeSidebar.helpers({
  110. hiddenMinicardLabelText() {
  111. currentUser = Meteor.user();
  112. if (currentUser) {
  113. return (currentUser.profile || {}).hiddenMinicardLabelText;
  114. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. },
  120. });
  121. EscapeActions.register(
  122. 'sidebarView',
  123. () => {
  124. Sidebar.setView(defaultView);
  125. },
  126. () => {
  127. return Sidebar && Sidebar.getView() !== defaultView;
  128. },
  129. );
  130. Template.memberPopup.helpers({
  131. user() {
  132. return Users.findOne(this.userId);
  133. },
  134. isBoardAdmin() {
  135. return Meteor.user().isBoardAdmin();
  136. },
  137. memberType() {
  138. const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
  139. if (type === 'normal') {
  140. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  141. const commentOnly = currentBoard.hasCommentOnly(this.userId);
  142. const noComments = currentBoard.hasNoComments(this.userId);
  143. const worker = currentBoard.hasWorker(this.userId);
  144. if (commentOnly) {
  145. return TAPi18n.__('comment-only').toLowerCase();
  146. } else if (noComments) {
  147. return TAPi18n.__('no-comments').toLowerCase();
  148. } else if (worker) {
  149. return TAPi18n.__('worker').toLowerCase();
  150. } else {
  151. return TAPi18n.__(type).toLowerCase();
  152. }
  153. } else {
  154. return TAPi18n.__(type).toLowerCase();
  155. }
  156. },
  157. isInvited() {
  158. return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
  159. },
  160. });
  161. Template.boardMenuPopup.events({
  162. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  163. 'click .js-open-rules-view'() {
  164. Modal.openWide('rulesMain');
  165. Popup.close();
  166. },
  167. 'click .js-custom-fields'() {
  168. Sidebar.setView('customFields');
  169. Popup.close();
  170. },
  171. 'click .js-open-archives'() {
  172. Sidebar.setView('archives');
  173. Popup.close();
  174. },
  175. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  176. 'click .js-change-language': Popup.open('changeLanguage'),
  177. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  178. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  179. currentBoard.archive();
  180. // XXX We should have some kind of notification on top of the page to
  181. // confirm that the board was successfully archived.
  182. FlowRouter.go('home');
  183. }),
  184. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  185. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  186. Popup.close();
  187. Boards.remove(currentBoard._id);
  188. FlowRouter.go('home');
  189. }),
  190. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  191. 'click .js-import-board': Popup.open('chooseBoardSource'),
  192. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  193. 'click .js-card-settings': Popup.open('boardCardSettings'),
  194. 'click .js-export-board': Popup.open('exportBoard'),
  195. });
  196. Template.boardMenuPopup.onCreated(function() {
  197. this.apiEnabled = new ReactiveVar(false);
  198. Meteor.call('_isApiEnabled', (e, result) => {
  199. this.apiEnabled.set(result);
  200. });
  201. });
  202. Template.boardMenuPopup.helpers({
  203. isBoardAdmin() {
  204. return Meteor.user().isBoardAdmin();
  205. },
  206. withApi() {
  207. return Template.instance().apiEnabled.get();
  208. },
  209. exportUrl() {
  210. const params = {
  211. boardId: Session.get('currentBoard'),
  212. };
  213. const queryParams = {
  214. authToken: Accounts._storedLoginToken(),
  215. };
  216. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  217. },
  218. exportFilename() {
  219. const boardId = Session.get('currentBoard');
  220. return `export-board-${boardId}.json`;
  221. },
  222. });
  223. Template.memberPopup.events({
  224. 'click .js-filter-member'() {
  225. Filter.members.toggle(this.userId);
  226. Popup.close();
  227. },
  228. 'click .js-change-role': Popup.open('changePermissions'),
  229. 'click .js-remove-member': Popup.afterConfirm('removeMember', function() {
  230. // This works from removing member from board, card members and assignees.
  231. const boardId = Session.get('currentBoard');
  232. const memberId = this.userId;
  233. Cards.find({ boardId, members: memberId }).forEach(card => {
  234. card.unassignMember(memberId);
  235. });
  236. Cards.find({ boardId, assignees: memberId }).forEach(card => {
  237. card.unassignAssignee(memberId);
  238. });
  239. Boards.findOne(boardId).removeMember(memberId);
  240. Popup.close();
  241. }),
  242. 'click .js-leave-member': Popup.afterConfirm('leaveBoard', () => {
  243. const boardId = Session.get('currentBoard');
  244. Meteor.call('quitBoard', boardId, () => {
  245. Popup.close();
  246. FlowRouter.go('home');
  247. });
  248. }),
  249. });
  250. Template.removeMemberPopup.helpers({
  251. user() {
  252. return Users.findOne(this.userId);
  253. },
  254. board() {
  255. return Boards.findOne(Session.get('currentBoard'));
  256. },
  257. });
  258. Template.leaveBoardPopup.helpers({
  259. board() {
  260. return Boards.findOne(Session.get('currentBoard'));
  261. },
  262. });
  263. Template.membersWidget.helpers({
  264. isInvited() {
  265. const user = Meteor.user();
  266. return user && user.isInvitedTo(Session.get('currentBoard'));
  267. },
  268. isWorker() {
  269. const user = Meteor.user();
  270. if (user) {
  271. return Meteor.call(Boards.hasWorker(user.memberId));
  272. } else {
  273. return false;
  274. }
  275. },
  276. isBoardAdmin() {
  277. return Meteor.user().isBoardAdmin();
  278. },
  279. });
  280. Template.membersWidget.events({
  281. 'click .js-member': Popup.open('member'),
  282. 'click .js-open-board-menu': Popup.open('boardMenu'),
  283. 'click .js-manage-board-members': Popup.open('addMember'),
  284. 'click .js-import': Popup.open('boardImportBoard'),
  285. submit: this.onSubmit,
  286. 'click .js-import-board': Popup.open('chooseBoardSource'),
  287. 'click .js-open-archived-board'() {
  288. Modal.open('archivedBoards');
  289. },
  290. 'click .sandstorm-powerbox-request-identity'() {
  291. window.sandstormRequestIdentity();
  292. },
  293. 'click .js-member-invite-accept'() {
  294. const boardId = Session.get('currentBoard');
  295. Meteor.user().removeInvite(boardId);
  296. },
  297. 'click .js-member-invite-decline'() {
  298. const boardId = Session.get('currentBoard');
  299. Meteor.call('quitBoard', boardId, (err, ret) => {
  300. if (!err && ret) {
  301. Meteor.user().removeInvite(boardId);
  302. FlowRouter.go('home');
  303. }
  304. });
  305. },
  306. });
  307. BlazeComponent.extendComponent({
  308. boardId() {
  309. return Session.get('currentBoard') || Integrations.Const.GLOBAL_WEBHOOK_ID;
  310. },
  311. integrations() {
  312. const boardId = this.boardId();
  313. return Integrations.find({ boardId: `${boardId}` }).fetch();
  314. },
  315. types() {
  316. return Integrations.Const.WEBHOOK_TYPES;
  317. },
  318. integration(cond) {
  319. const boardId = this.boardId();
  320. const condition = { boardId, ...cond };
  321. for (const k in condition) {
  322. if (!condition[k]) delete condition[k];
  323. }
  324. return Integrations.findOne(condition);
  325. },
  326. onCreated() {
  327. this.disabled = new ReactiveVar(false);
  328. },
  329. events() {
  330. return [
  331. {
  332. 'click a.flex'(evt) {
  333. this.disabled.set(!this.disabled.get());
  334. $(evt.target).toggleClass(CKCLS, this.disabled.get());
  335. },
  336. submit(evt) {
  337. evt.preventDefault();
  338. const url = evt.target.url.value;
  339. const boardId = this.boardId();
  340. let id = null;
  341. let integration = null;
  342. const title = evt.target.title.value;
  343. const token = evt.target.token.value;
  344. const type = evt.target.type.value;
  345. const enabled = !this.disabled.get();
  346. let remove = false;
  347. const values = {
  348. url,
  349. type,
  350. token,
  351. title,
  352. enabled,
  353. };
  354. if (evt.target.id) {
  355. id = evt.target.id.value;
  356. integration = this.integration({ _id: id });
  357. remove = !url;
  358. } else if (url) {
  359. integration = this.integration({ url, token });
  360. }
  361. if (remove) {
  362. Integrations.remove(integration._id);
  363. } else if (integration && integration._id) {
  364. Integrations.update(integration._id, {
  365. $set: values,
  366. });
  367. } else if (url) {
  368. Integrations.insert({
  369. ...values,
  370. userId: Meteor.userId(),
  371. enabled: true,
  372. boardId,
  373. activities: ['all'],
  374. });
  375. }
  376. Popup.close();
  377. },
  378. },
  379. ];
  380. },
  381. }).register('outgoingWebhooksPopup');
  382. BlazeComponent.extendComponent({
  383. template() {
  384. return 'chooseBoardSource';
  385. },
  386. }).register('chooseBoardSourcePopup');
  387. BlazeComponent.extendComponent({
  388. template() {
  389. return 'exportBoard';
  390. },
  391. withApi() {
  392. return Template.instance().apiEnabled.get();
  393. },
  394. exportUrl() {
  395. const params = {
  396. boardId: Session.get('currentBoard'),
  397. };
  398. const queryParams = {
  399. authToken: Accounts._storedLoginToken(),
  400. };
  401. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  402. },
  403. exportCsvUrl() {
  404. const params = {
  405. boardId: Session.get('currentBoard'),
  406. };
  407. const queryParams = {
  408. authToken: Accounts._storedLoginToken(),
  409. };
  410. return FlowRouter.path(
  411. '/api/boards/:boardId/export/csv',
  412. params,
  413. queryParams,
  414. );
  415. },
  416. exportTsvUrl() {
  417. const params = {
  418. boardId: Session.get('currentBoard'),
  419. };
  420. const queryParams = {
  421. authToken: Accounts._storedLoginToken(),
  422. delimiter: '\t',
  423. };
  424. return FlowRouter.path(
  425. '/api/boards/:boardId/export/csv',
  426. params,
  427. queryParams,
  428. );
  429. },
  430. exportJsonFilename() {
  431. const boardId = Session.get('currentBoard');
  432. return `export-board-${boardId}.json`;
  433. },
  434. exportCsvFilename() {
  435. const boardId = Session.get('currentBoard');
  436. return `export-board-${boardId}.csv`;
  437. },
  438. exportTsvFilename() {
  439. const boardId = Session.get('currentBoard');
  440. return `export-board-${boardId}.tsv`;
  441. },
  442. }).register('exportBoardPopup');
  443. Template.exportBoard.events({
  444. 'click .html-export-board': async event => {
  445. event.preventDefault();
  446. await ExportHtml(Popup)();
  447. },
  448. });
  449. Template.labelsWidget.events({
  450. 'click .js-label': Popup.open('editLabel'),
  451. 'click .js-add-label': Popup.open('createLabel'),
  452. });
  453. Template.labelsWidget.helpers({
  454. isBoardAdmin() {
  455. return Meteor.user().isBoardAdmin();
  456. },
  457. });
  458. // Board members can assign people or labels by drag-dropping elements from the
  459. // sidebar to the cards on the board. In order to re-initialize the jquery-ui
  460. // plugin any time a draggable member or label is modified or removed we use a
  461. // autorun function and register a dependency on the both members and labels
  462. // fields of the current board document.
  463. function draggableMembersLabelsWidgets() {
  464. this.autorun(() => {
  465. const currentBoardId = Tracker.nonreactive(() => {
  466. return Session.get('currentBoard');
  467. });
  468. Boards.findOne(currentBoardId, {
  469. fields: {
  470. members: 1,
  471. labels: 1,
  472. },
  473. });
  474. Tracker.afterFlush(() => {
  475. const $draggables = this.$('.js-member,.js-label');
  476. $draggables.draggable({
  477. appendTo: 'body',
  478. helper: 'clone',
  479. revert: 'invalid',
  480. revertDuration: 150,
  481. snap: false,
  482. snapMode: 'both',
  483. start() {
  484. EscapeActions.executeUpTo('popup-back');
  485. },
  486. });
  487. function userIsMember() {
  488. return Meteor.user() && Meteor.user().isBoardMember();
  489. }
  490. this.autorun(() => {
  491. $draggables.draggable('option', 'disabled', !userIsMember());
  492. });
  493. });
  494. });
  495. }
  496. Template.membersWidget.onRendered(draggableMembersLabelsWidgets);
  497. Template.labelsWidget.onRendered(draggableMembersLabelsWidgets);
  498. BlazeComponent.extendComponent({
  499. backgroundColors() {
  500. return Boards.simpleSchema()._schema.color.allowedValues;
  501. },
  502. isSelected() {
  503. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  504. return currentBoard.color === this.currentData().toString();
  505. },
  506. events() {
  507. return [
  508. {
  509. 'click .js-select-background'(evt) {
  510. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  511. const newColor = this.currentData().toString();
  512. currentBoard.setColor(newColor);
  513. evt.preventDefault();
  514. },
  515. },
  516. ];
  517. },
  518. }).register('boardChangeColorPopup');
  519. BlazeComponent.extendComponent({
  520. onCreated() {
  521. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  522. },
  523. allowsSubtasks() {
  524. return this.currentBoard.allowsSubtasks;
  525. },
  526. allowsReceivedDate() {
  527. return this.currentBoard.allowsReceivedDate;
  528. },
  529. isBoardSelected() {
  530. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  531. },
  532. isNullBoardSelected() {
  533. return (
  534. this.currentBoard.subtasksDefaultBoardId === null ||
  535. this.currentBoard.subtasksDefaultBoardId === undefined
  536. );
  537. },
  538. boards() {
  539. return Boards.find(
  540. {
  541. archived: false,
  542. 'members.userId': Meteor.userId(),
  543. },
  544. {
  545. sort: { sort: 1 /* boards default sorting */ },
  546. },
  547. );
  548. },
  549. lists() {
  550. return Lists.find(
  551. {
  552. boardId: this.currentBoard._id,
  553. archived: false,
  554. },
  555. {
  556. sort: ['title'],
  557. },
  558. );
  559. },
  560. hasLists() {
  561. return this.lists().count() > 0;
  562. },
  563. isListSelected() {
  564. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  565. },
  566. presentParentTask() {
  567. let result = this.currentBoard.presentParentTask;
  568. if (result === null || result === undefined) {
  569. result = 'no-parent';
  570. }
  571. return result;
  572. },
  573. events() {
  574. return [
  575. {
  576. 'click .js-field-has-subtasks'(evt) {
  577. evt.preventDefault();
  578. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  579. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  580. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  581. CKCLS,
  582. this.currentBoard.allowsSubtasks,
  583. );
  584. $('.js-field-has-subtasks').toggleClass(
  585. CKCLS,
  586. this.currentBoard.allowsSubtasks,
  587. );
  588. $('.js-field-deposit-board').prop(
  589. 'disabled',
  590. !this.currentBoard.allowsSubtasks,
  591. );
  592. },
  593. 'change .js-field-deposit-board'(evt) {
  594. let value = evt.target.value;
  595. if (value === 'null') {
  596. value = null;
  597. }
  598. this.currentBoard.setSubtasksDefaultBoardId(value);
  599. evt.preventDefault();
  600. },
  601. 'change .js-field-deposit-list'(evt) {
  602. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  603. evt.preventDefault();
  604. },
  605. 'click .js-field-show-parent-in-minicard'(evt) {
  606. const value =
  607. evt.target.id ||
  608. $(evt.target).parent()[0].id ||
  609. $(evt.target)
  610. .parent()[0]
  611. .parent()[0].id;
  612. const options = [
  613. 'prefix-with-full-path',
  614. 'prefix-with-parent',
  615. 'subtext-with-full-path',
  616. 'subtext-with-parent',
  617. 'no-parent',
  618. ];
  619. options.forEach(function(element) {
  620. if (element !== value) {
  621. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  622. $(`#${element}`).toggleClass(CKCLS, false);
  623. }
  624. });
  625. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  626. $(`#${value}`).toggleClass(CKCLS, true);
  627. this.currentBoard.setPresentParentTask(value);
  628. evt.preventDefault();
  629. },
  630. },
  631. ];
  632. },
  633. }).register('boardSubtaskSettingsPopup');
  634. BlazeComponent.extendComponent({
  635. onCreated() {
  636. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  637. },
  638. allowsReceivedDate() {
  639. return this.currentBoard.allowsReceivedDate;
  640. },
  641. allowsStartDate() {
  642. return this.currentBoard.allowsStartDate;
  643. },
  644. allowsDueDate() {
  645. return this.currentBoard.allowsDueDate;
  646. },
  647. allowsEndDate() {
  648. return this.currentBoard.allowsEndDate;
  649. },
  650. allowsSubtasks() {
  651. return this.currentBoard.allowsSubtasks;
  652. },
  653. allowsMembers() {
  654. return this.currentBoard.allowsMembers;
  655. },
  656. allowsAssignee() {
  657. return this.currentBoard.allowsAssignee;
  658. },
  659. allowsAssignedBy() {
  660. return this.currentBoard.allowsAssignedBy;
  661. },
  662. allowsRequestedBy() {
  663. return this.currentBoard.allowsRequestedBy;
  664. },
  665. allowsLabels() {
  666. return this.currentBoard.allowsLabels;
  667. },
  668. allowsChecklists() {
  669. return this.currentBoard.allowsChecklists;
  670. },
  671. allowsAttachments() {
  672. return this.currentBoard.allowsAttachments;
  673. },
  674. allowsComments() {
  675. return this.currentBoard.allowsComments;
  676. },
  677. allowsDescriptionTitle() {
  678. return this.currentBoard.allowsDescriptionTitle;
  679. },
  680. allowsDescriptionText() {
  681. return this.currentBoard.allowsDescriptionText;
  682. },
  683. isBoardSelected() {
  684. return this.currentBoard.dateSettingsDefaultBoardID;
  685. },
  686. isNullBoardSelected() {
  687. return (
  688. this.currentBoard.dateSettingsDefaultBoardId === null ||
  689. this.currentBoard.dateSettingsDefaultBoardId === undefined
  690. );
  691. },
  692. boards() {
  693. return Boards.find(
  694. {
  695. archived: false,
  696. 'members.userId': Meteor.userId(),
  697. },
  698. {
  699. sort: { sort: 1 /* boards default sorting */ },
  700. },
  701. );
  702. },
  703. lists() {
  704. return Lists.find(
  705. {
  706. boardId: this.currentBoard._id,
  707. archived: false,
  708. },
  709. {
  710. sort: ['title'],
  711. },
  712. );
  713. },
  714. hasLists() {
  715. return this.lists().count() > 0;
  716. },
  717. isListSelected() {
  718. return (
  719. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  720. );
  721. },
  722. events() {
  723. return [
  724. {
  725. 'click .js-field-has-receiveddate'(evt) {
  726. evt.preventDefault();
  727. this.currentBoard.allowsReceivedDate = !this.currentBoard
  728. .allowsReceivedDate;
  729. this.currentBoard.setAllowsReceivedDate(
  730. this.currentBoard.allowsReceivedDate,
  731. );
  732. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  733. CKCLS,
  734. this.currentBoard.allowsReceivedDate,
  735. );
  736. $('.js-field-has-receiveddate').toggleClass(
  737. CKCLS,
  738. this.currentBoard.allowsReceivedDate,
  739. );
  740. },
  741. 'click .js-field-has-startdate'(evt) {
  742. evt.preventDefault();
  743. this.currentBoard.allowsStartDate = !this.currentBoard
  744. .allowsStartDate;
  745. this.currentBoard.setAllowsStartDate(
  746. this.currentBoard.allowsStartDate,
  747. );
  748. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  749. CKCLS,
  750. this.currentBoard.allowsStartDate,
  751. );
  752. $('.js-field-has-startdate').toggleClass(
  753. CKCLS,
  754. this.currentBoard.allowsStartDate,
  755. );
  756. },
  757. 'click .js-field-has-enddate'(evt) {
  758. evt.preventDefault();
  759. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  760. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  761. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  762. CKCLS,
  763. this.currentBoard.allowsEndDate,
  764. );
  765. $('.js-field-has-enddate').toggleClass(
  766. CKCLS,
  767. this.currentBoard.allowsEndDate,
  768. );
  769. },
  770. 'click .js-field-has-duedate'(evt) {
  771. evt.preventDefault();
  772. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  773. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  774. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  775. CKCLS,
  776. this.currentBoard.allowsDueDate,
  777. );
  778. $('.js-field-has-duedate').toggleClass(
  779. CKCLS,
  780. this.currentBoard.allowsDueDate,
  781. );
  782. },
  783. 'click .js-field-has-subtasks'(evt) {
  784. evt.preventDefault();
  785. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  786. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  787. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  788. CKCLS,
  789. this.currentBoard.allowsSubtasks,
  790. );
  791. $('.js-field-has-subtasks').toggleClass(
  792. CKCLS,
  793. this.currentBoard.allowsSubtasks,
  794. );
  795. },
  796. 'click .js-field-has-members'(evt) {
  797. evt.preventDefault();
  798. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  799. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  800. $(`.js-field-has-members ${MCB}`).toggleClass(
  801. CKCLS,
  802. this.currentBoard.allowsMembers,
  803. );
  804. $('.js-field-has-members').toggleClass(
  805. CKCLS,
  806. this.currentBoard.allowsMembers,
  807. );
  808. },
  809. 'click .js-field-has-assignee'(evt) {
  810. evt.preventDefault();
  811. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  812. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  813. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  814. CKCLS,
  815. this.currentBoard.allowsAssignee,
  816. );
  817. $('.js-field-has-assignee').toggleClass(
  818. CKCLS,
  819. this.currentBoard.allowsAssignee,
  820. );
  821. },
  822. 'click .js-field-has-assigned-by'(evt) {
  823. evt.preventDefault();
  824. this.currentBoard.allowsAssignedBy = !this.currentBoard
  825. .allowsAssignedBy;
  826. this.currentBoard.setAllowsAssignedBy(
  827. this.currentBoard.allowsAssignedBy,
  828. );
  829. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  830. CKCLS,
  831. this.currentBoard.allowsAssignedBy,
  832. );
  833. $('.js-field-has-assigned-by').toggleClass(
  834. CKCLS,
  835. this.currentBoard.allowsAssignedBy,
  836. );
  837. },
  838. 'click .js-field-has-requested-by'(evt) {
  839. evt.preventDefault();
  840. this.currentBoard.allowsRequestedBy = !this.currentBoard
  841. .allowsRequestedBy;
  842. this.currentBoard.setAllowsRequestedBy(
  843. this.currentBoard.allowsRequestedBy,
  844. );
  845. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  846. CKCLS,
  847. this.currentBoard.allowsRequestedBy,
  848. );
  849. $('.js-field-has-requested-by').toggleClass(
  850. CKCLS,
  851. this.currentBoard.allowsRequestedBy,
  852. );
  853. },
  854. 'click .js-field-has-labels'(evt) {
  855. evt.preventDefault();
  856. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  857. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  858. $(`.js-field-has-labels ${MCB}`).toggleClass(
  859. CKCLS,
  860. this.currentBoard.allowsAssignee,
  861. );
  862. $('.js-field-has-labels').toggleClass(
  863. CKCLS,
  864. this.currentBoard.allowsLabels,
  865. );
  866. },
  867. 'click .js-field-has-description-title'(evt) {
  868. evt.preventDefault();
  869. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  870. .allowsDescriptionTitle;
  871. this.currentBoard.setAllowsDescriptionTitle(
  872. this.currentBoard.allowsDescriptionTitle,
  873. );
  874. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  875. CKCLS,
  876. this.currentBoard.allowsDescriptionTitle,
  877. );
  878. $('.js-field-has-description-title').toggleClass(
  879. CKCLS,
  880. this.currentBoard.allowsDescriptionTitle,
  881. );
  882. },
  883. 'click .js-field-has-description-text'(evt) {
  884. evt.preventDefault();
  885. this.currentBoard.allowsDescriptionText = !this.currentBoard
  886. .allowsDescriptionText;
  887. this.currentBoard.setAllowsDescriptionText(
  888. this.currentBoard.allowsDescriptionText,
  889. );
  890. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  891. CKCLS,
  892. this.currentBoard.allowsDescriptionText,
  893. );
  894. $('.js-field-has-description-text').toggleClass(
  895. CKCLS,
  896. this.currentBoard.allowsDescriptionText,
  897. );
  898. },
  899. 'click .js-field-has-checklists'(evt) {
  900. evt.preventDefault();
  901. this.currentBoard.allowsChecklists = !this.currentBoard
  902. .allowsChecklists;
  903. this.currentBoard.setAllowsChecklists(
  904. this.currentBoard.allowsChecklists,
  905. );
  906. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  907. CKCLS,
  908. this.currentBoard.allowsChecklists,
  909. );
  910. $('.js-field-has-checklists').toggleClass(
  911. CKCLS,
  912. this.currentBoard.allowsChecklists,
  913. );
  914. },
  915. 'click .js-field-has-attachments'(evt) {
  916. evt.preventDefault();
  917. this.currentBoard.allowsAttachments = !this.currentBoard
  918. .allowsAttachments;
  919. this.currentBoard.setAllowsAttachments(
  920. this.currentBoard.allowsAttachments,
  921. );
  922. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  923. CKCLS,
  924. this.currentBoard.allowsAttachments,
  925. );
  926. $('.js-field-has-attachments').toggleClass(
  927. CKCLS,
  928. this.currentBoard.allowsAttachments,
  929. );
  930. },
  931. 'click .js-field-has-comments'(evt) {
  932. evt.preventDefault();
  933. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  934. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  935. $(`.js-field-has-comments ${MCB}`).toggleClass(
  936. CKCLS,
  937. this.currentBoard.allowsComments,
  938. );
  939. $('.js-field-has-comments').toggleClass(
  940. CKCLS,
  941. this.currentBoard.allowsComments,
  942. );
  943. },
  944. 'click .js-field-has-activities'(evt) {
  945. evt.preventDefault();
  946. this.currentBoard.allowsActivities = !this.currentBoard
  947. .allowsActivities;
  948. this.currentBoard.setAllowsActivities(
  949. this.currentBoard.allowsActivities,
  950. );
  951. $(`.js-field-has-activities ${MCB}`).toggleClass(
  952. CKCLS,
  953. this.currentBoard.allowsActivities,
  954. );
  955. $('.js-field-has-activities').toggleClass(
  956. CKCLS,
  957. this.currentBoard.allowsActivities,
  958. );
  959. },
  960. },
  961. ];
  962. },
  963. }).register('boardCardSettingsPopup');
  964. BlazeComponent.extendComponent({
  965. onCreated() {
  966. this.error = new ReactiveVar('');
  967. this.loading = new ReactiveVar(false);
  968. },
  969. onRendered() {
  970. this.find('.js-search-member input').focus();
  971. this.setLoading(false);
  972. },
  973. isBoardMember() {
  974. const userId = this.currentData()._id;
  975. const user = Users.findOne(userId);
  976. return user && user.isBoardMember();
  977. },
  978. isValidEmail(email) {
  979. return SimpleSchema.RegEx.Email.test(email);
  980. },
  981. setError(error) {
  982. this.error.set(error);
  983. },
  984. setLoading(w) {
  985. this.loading.set(w);
  986. },
  987. isLoading() {
  988. return this.loading.get();
  989. },
  990. inviteUser(idNameEmail) {
  991. const boardId = Session.get('currentBoard');
  992. this.setLoading(true);
  993. const self = this;
  994. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  995. self.setLoading(false);
  996. if (err) self.setError(err.error);
  997. else if (ret.email) self.setError('email-sent');
  998. else Popup.close();
  999. });
  1000. },
  1001. events() {
  1002. return [
  1003. {
  1004. 'keyup input'() {
  1005. this.setError('');
  1006. },
  1007. 'click .js-select-member'() {
  1008. const userId = this.currentData()._id;
  1009. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1010. if (!currentBoard.hasMember(userId)) {
  1011. this.inviteUser(userId);
  1012. }
  1013. },
  1014. 'click .js-email-invite'() {
  1015. const idNameEmail = $('.js-search-member input').val();
  1016. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  1017. this.inviteUser(idNameEmail);
  1018. } else this.setError('email-invalid');
  1019. },
  1020. },
  1021. ];
  1022. },
  1023. }).register('addMemberPopup');
  1024. Template.changePermissionsPopup.events({
  1025. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  1026. event,
  1027. ) {
  1028. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1029. const memberId = this.userId;
  1030. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  1031. const isCommentOnly = $(event.currentTarget).hasClass(
  1032. 'js-set-comment-only',
  1033. );
  1034. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  1035. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  1036. currentBoard.setMemberPermission(
  1037. memberId,
  1038. isAdmin,
  1039. isNoComments,
  1040. isCommentOnly,
  1041. isWorker,
  1042. );
  1043. Popup.back(1);
  1044. },
  1045. });
  1046. Template.changePermissionsPopup.helpers({
  1047. isAdmin() {
  1048. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1049. return currentBoard.hasAdmin(this.userId);
  1050. },
  1051. isNormal() {
  1052. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1053. return (
  1054. !currentBoard.hasAdmin(this.userId) &&
  1055. !currentBoard.hasNoComments(this.userId) &&
  1056. !currentBoard.hasCommentOnly(this.userId) &&
  1057. !currentBoard.hasWorker(this.userId)
  1058. );
  1059. },
  1060. isNoComments() {
  1061. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1062. return (
  1063. !currentBoard.hasAdmin(this.userId) &&
  1064. currentBoard.hasNoComments(this.userId)
  1065. );
  1066. },
  1067. isCommentOnly() {
  1068. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1069. return (
  1070. !currentBoard.hasAdmin(this.userId) &&
  1071. currentBoard.hasCommentOnly(this.userId)
  1072. );
  1073. },
  1074. isWorker() {
  1075. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1076. return (
  1077. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  1078. );
  1079. },
  1080. isLastAdmin() {
  1081. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1082. return (
  1083. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1084. );
  1085. },
  1086. });