sidebar.js 32 KB

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