sidebar.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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');
  146. } else if (noComments) {
  147. return TAPi18n.__('no-comments');
  148. } else if (worker) {
  149. return TAPi18n.__('worker');
  150. } else {
  151. return TAPi18n.__(type);
  152. }
  153. } else {
  154. return TAPi18n.__(type);
  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. exportUrlExcel() {
  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/exportExcel',
  412. params,
  413. queryParams,
  414. );
  415. },
  416. exportFilenameExcel() {
  417. const boardId = Session.get('currentBoard');
  418. return `export-board-excel-${boardId}.xlsx`;
  419. },
  420. exportCsvUrl() {
  421. const params = {
  422. boardId: Session.get('currentBoard'),
  423. };
  424. const queryParams = {
  425. authToken: Accounts._storedLoginToken(),
  426. };
  427. return FlowRouter.path(
  428. '/api/boards/:boardId/export/csv',
  429. params,
  430. queryParams,
  431. );
  432. },
  433. exportTsvUrl() {
  434. const params = {
  435. boardId: Session.get('currentBoard'),
  436. };
  437. const queryParams = {
  438. authToken: Accounts._storedLoginToken(),
  439. delimiter: '\t',
  440. };
  441. return FlowRouter.path(
  442. '/api/boards/:boardId/export/csv',
  443. params,
  444. queryParams,
  445. );
  446. },
  447. exportJsonFilename() {
  448. const boardId = Session.get('currentBoard');
  449. return `export-board-${boardId}.json`;
  450. },
  451. exportCsvFilename() {
  452. const boardId = Session.get('currentBoard');
  453. return `export-board-${boardId}.csv`;
  454. },
  455. exportTsvFilename() {
  456. const boardId = Session.get('currentBoard');
  457. return `export-board-${boardId}.tsv`;
  458. },
  459. }).register('exportBoardPopup');
  460. Template.exportBoard.events({
  461. 'click .html-export-board': async event => {
  462. event.preventDefault();
  463. await ExportHtml(Popup)();
  464. },
  465. });
  466. Template.labelsWidget.events({
  467. 'click .js-label': Popup.open('editLabel'),
  468. 'click .js-add-label': Popup.open('createLabel'),
  469. });
  470. Template.labelsWidget.helpers({
  471. isBoardAdmin() {
  472. return Meteor.user().isBoardAdmin();
  473. },
  474. });
  475. // Board members can assign people or labels by drag-dropping elements from the
  476. // sidebar to the cards on the board. In order to re-initialize the jquery-ui
  477. // plugin any time a draggable member or label is modified or removed we use a
  478. // autorun function and register a dependency on the both members and labels
  479. // fields of the current board document.
  480. function draggableMembersLabelsWidgets() {
  481. this.autorun(() => {
  482. const currentBoardId = Tracker.nonreactive(() => {
  483. return Session.get('currentBoard');
  484. });
  485. Boards.findOne(currentBoardId, {
  486. fields: {
  487. members: 1,
  488. labels: 1,
  489. },
  490. });
  491. Tracker.afterFlush(() => {
  492. const $draggables = this.$('.js-member,.js-label');
  493. $draggables.draggable({
  494. appendTo: 'body',
  495. helper: 'clone',
  496. revert: 'invalid',
  497. revertDuration: 150,
  498. snap: false,
  499. snapMode: 'both',
  500. start() {
  501. EscapeActions.executeUpTo('popup-back');
  502. },
  503. });
  504. function userIsMember() {
  505. return Meteor.user() && Meteor.user().isBoardMember();
  506. }
  507. this.autorun(() => {
  508. $draggables.draggable('option', 'disabled', !userIsMember());
  509. });
  510. });
  511. });
  512. }
  513. Template.membersWidget.onRendered(draggableMembersLabelsWidgets);
  514. Template.labelsWidget.onRendered(draggableMembersLabelsWidgets);
  515. BlazeComponent.extendComponent({
  516. backgroundColors() {
  517. return Boards.simpleSchema()._schema.color.allowedValues;
  518. },
  519. isSelected() {
  520. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  521. return currentBoard.color === this.currentData().toString();
  522. },
  523. events() {
  524. return [
  525. {
  526. 'click .js-select-background'(evt) {
  527. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  528. const newColor = this.currentData().toString();
  529. currentBoard.setColor(newColor);
  530. evt.preventDefault();
  531. },
  532. },
  533. ];
  534. },
  535. }).register('boardChangeColorPopup');
  536. BlazeComponent.extendComponent({
  537. onCreated() {
  538. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  539. },
  540. allowsSubtasks() {
  541. return this.currentBoard.allowsSubtasks;
  542. },
  543. allowsReceivedDate() {
  544. return this.currentBoard.allowsReceivedDate;
  545. },
  546. isBoardSelected() {
  547. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  548. },
  549. isNullBoardSelected() {
  550. return (
  551. this.currentBoard.subtasksDefaultBoardId === null ||
  552. this.currentBoard.subtasksDefaultBoardId === undefined
  553. );
  554. },
  555. boards() {
  556. return Boards.find(
  557. {
  558. archived: false,
  559. 'members.userId': Meteor.userId(),
  560. },
  561. {
  562. sort: { sort: 1 /* boards default sorting */ },
  563. },
  564. );
  565. },
  566. lists() {
  567. return Lists.find(
  568. {
  569. boardId: this.currentBoard._id,
  570. archived: false,
  571. },
  572. {
  573. sort: ['title'],
  574. },
  575. );
  576. },
  577. hasLists() {
  578. return this.lists().count() > 0;
  579. },
  580. isListSelected() {
  581. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  582. },
  583. presentParentTask() {
  584. let result = this.currentBoard.presentParentTask;
  585. if (result === null || result === undefined) {
  586. result = 'no-parent';
  587. }
  588. return result;
  589. },
  590. events() {
  591. return [
  592. {
  593. 'click .js-field-has-subtasks'(evt) {
  594. evt.preventDefault();
  595. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  596. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  597. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  598. CKCLS,
  599. this.currentBoard.allowsSubtasks,
  600. );
  601. $('.js-field-has-subtasks').toggleClass(
  602. CKCLS,
  603. this.currentBoard.allowsSubtasks,
  604. );
  605. $('.js-field-deposit-board').prop(
  606. 'disabled',
  607. !this.currentBoard.allowsSubtasks,
  608. );
  609. },
  610. 'change .js-field-deposit-board'(evt) {
  611. let value = evt.target.value;
  612. if (value === 'null') {
  613. value = null;
  614. }
  615. this.currentBoard.setSubtasksDefaultBoardId(value);
  616. evt.preventDefault();
  617. },
  618. 'change .js-field-deposit-list'(evt) {
  619. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  620. evt.preventDefault();
  621. },
  622. 'click .js-field-show-parent-in-minicard'(evt) {
  623. const value =
  624. evt.target.id ||
  625. $(evt.target).parent()[0].id ||
  626. $(evt.target)
  627. .parent()[0]
  628. .parent()[0].id;
  629. const options = [
  630. 'prefix-with-full-path',
  631. 'prefix-with-parent',
  632. 'subtext-with-full-path',
  633. 'subtext-with-parent',
  634. 'no-parent',
  635. ];
  636. options.forEach(function(element) {
  637. if (element !== value) {
  638. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  639. $(`#${element}`).toggleClass(CKCLS, false);
  640. }
  641. });
  642. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  643. $(`#${value}`).toggleClass(CKCLS, true);
  644. this.currentBoard.setPresentParentTask(value);
  645. evt.preventDefault();
  646. },
  647. },
  648. ];
  649. },
  650. }).register('boardSubtaskSettingsPopup');
  651. BlazeComponent.extendComponent({
  652. onCreated() {
  653. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  654. },
  655. allowsReceivedDate() {
  656. return this.currentBoard.allowsReceivedDate;
  657. },
  658. allowsStartDate() {
  659. return this.currentBoard.allowsStartDate;
  660. },
  661. allowsDueDate() {
  662. return this.currentBoard.allowsDueDate;
  663. },
  664. allowsEndDate() {
  665. return this.currentBoard.allowsEndDate;
  666. },
  667. allowsSubtasks() {
  668. return this.currentBoard.allowsSubtasks;
  669. },
  670. allowsCreator() {
  671. return (
  672. this.currentBoard.allowsCreator === null ||
  673. this.currentBoard.allowsCreator === undefined ||
  674. this.currentBoard.allowsCreator
  675. );
  676. },
  677. allowsMembers() {
  678. return this.currentBoard.allowsMembers;
  679. },
  680. allowsAssignee() {
  681. return this.currentBoard.allowsAssignee;
  682. },
  683. allowsAssignedBy() {
  684. return this.currentBoard.allowsAssignedBy;
  685. },
  686. allowsRequestedBy() {
  687. return this.currentBoard.allowsRequestedBy;
  688. },
  689. allowsCardSortingByNumber() {
  690. return this.currentBoard.allowsCardSortingByNumber;
  691. },
  692. allowsLabels() {
  693. return this.currentBoard.allowsLabels;
  694. },
  695. allowsChecklists() {
  696. return this.currentBoard.allowsChecklists;
  697. },
  698. allowsAttachments() {
  699. return this.currentBoard.allowsAttachments;
  700. },
  701. allowsComments() {
  702. return this.currentBoard.allowsComments;
  703. },
  704. allowsDescriptionTitle() {
  705. return this.currentBoard.allowsDescriptionTitle;
  706. },
  707. allowsDescriptionText() {
  708. return this.currentBoard.allowsDescriptionText;
  709. },
  710. isBoardSelected() {
  711. return this.currentBoard.dateSettingsDefaultBoardID;
  712. },
  713. isNullBoardSelected() {
  714. return (
  715. this.currentBoard.dateSettingsDefaultBoardId === null ||
  716. this.currentBoard.dateSettingsDefaultBoardId === undefined
  717. );
  718. },
  719. boards() {
  720. return Boards.find(
  721. {
  722. archived: false,
  723. 'members.userId': Meteor.userId(),
  724. },
  725. {
  726. sort: { sort: 1 /* boards default sorting */ },
  727. },
  728. );
  729. },
  730. lists() {
  731. return Lists.find(
  732. {
  733. boardId: this.currentBoard._id,
  734. archived: false,
  735. },
  736. {
  737. sort: ['title'],
  738. },
  739. );
  740. },
  741. hasLists() {
  742. return this.lists().count() > 0;
  743. },
  744. isListSelected() {
  745. return (
  746. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  747. );
  748. },
  749. events() {
  750. return [
  751. {
  752. 'click .js-field-has-receiveddate'(evt) {
  753. evt.preventDefault();
  754. this.currentBoard.allowsReceivedDate = !this.currentBoard
  755. .allowsReceivedDate;
  756. this.currentBoard.setAllowsReceivedDate(
  757. this.currentBoard.allowsReceivedDate,
  758. );
  759. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  760. CKCLS,
  761. this.currentBoard.allowsReceivedDate,
  762. );
  763. $('.js-field-has-receiveddate').toggleClass(
  764. CKCLS,
  765. this.currentBoard.allowsReceivedDate,
  766. );
  767. },
  768. 'click .js-field-has-startdate'(evt) {
  769. evt.preventDefault();
  770. this.currentBoard.allowsStartDate = !this.currentBoard
  771. .allowsStartDate;
  772. this.currentBoard.setAllowsStartDate(
  773. this.currentBoard.allowsStartDate,
  774. );
  775. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  776. CKCLS,
  777. this.currentBoard.allowsStartDate,
  778. );
  779. $('.js-field-has-startdate').toggleClass(
  780. CKCLS,
  781. this.currentBoard.allowsStartDate,
  782. );
  783. },
  784. 'click .js-field-has-enddate'(evt) {
  785. evt.preventDefault();
  786. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  787. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  788. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  789. CKCLS,
  790. this.currentBoard.allowsEndDate,
  791. );
  792. $('.js-field-has-enddate').toggleClass(
  793. CKCLS,
  794. this.currentBoard.allowsEndDate,
  795. );
  796. },
  797. 'click .js-field-has-duedate'(evt) {
  798. evt.preventDefault();
  799. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  800. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  801. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  802. CKCLS,
  803. this.currentBoard.allowsDueDate,
  804. );
  805. $('.js-field-has-duedate').toggleClass(
  806. CKCLS,
  807. this.currentBoard.allowsDueDate,
  808. );
  809. },
  810. 'click .js-field-has-subtasks'(evt) {
  811. evt.preventDefault();
  812. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  813. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  814. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  815. CKCLS,
  816. this.currentBoard.allowsSubtasks,
  817. );
  818. $('.js-field-has-subtasks').toggleClass(
  819. CKCLS,
  820. this.currentBoard.allowsSubtasks,
  821. );
  822. },
  823. 'click .js-field-has-creator'(evt) {
  824. evt.preventDefault();
  825. this.currentBoard.allowsCreator = !this.currentBoard.allowsCreator;
  826. this.currentBoard.setAllowsCreator(this.currentBoard.allowsCreator);
  827. $(`.js-field-has-creator ${MCB}`).toggleClass(
  828. CKCLS,
  829. this.currentBoard.allowsCreator,
  830. );
  831. $('.js-field-has-creator').toggleClass(
  832. CKCLS,
  833. this.currentBoard.allowsCreator,
  834. );
  835. },
  836. 'click .js-field-has-members'(evt) {
  837. evt.preventDefault();
  838. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  839. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  840. $(`.js-field-has-members ${MCB}`).toggleClass(
  841. CKCLS,
  842. this.currentBoard.allowsMembers,
  843. );
  844. $('.js-field-has-members').toggleClass(
  845. CKCLS,
  846. this.currentBoard.allowsMembers,
  847. );
  848. },
  849. 'click .js-field-has-assignee'(evt) {
  850. evt.preventDefault();
  851. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  852. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  853. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  854. CKCLS,
  855. this.currentBoard.allowsAssignee,
  856. );
  857. $('.js-field-has-assignee').toggleClass(
  858. CKCLS,
  859. this.currentBoard.allowsAssignee,
  860. );
  861. },
  862. 'click .js-field-has-assigned-by'(evt) {
  863. evt.preventDefault();
  864. this.currentBoard.allowsAssignedBy = !this.currentBoard
  865. .allowsAssignedBy;
  866. this.currentBoard.setAllowsAssignedBy(
  867. this.currentBoard.allowsAssignedBy,
  868. );
  869. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  870. CKCLS,
  871. this.currentBoard.allowsAssignedBy,
  872. );
  873. $('.js-field-has-assigned-by').toggleClass(
  874. CKCLS,
  875. this.currentBoard.allowsAssignedBy,
  876. );
  877. },
  878. 'click .js-field-has-requested-by'(evt) {
  879. evt.preventDefault();
  880. this.currentBoard.allowsRequestedBy = !this.currentBoard
  881. .allowsRequestedBy;
  882. this.currentBoard.setAllowsRequestedBy(
  883. this.currentBoard.allowsRequestedBy,
  884. );
  885. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  886. CKCLS,
  887. this.currentBoard.allowsRequestedBy,
  888. );
  889. $('.js-field-has-requested-by').toggleClass(
  890. CKCLS,
  891. this.currentBoard.allowsRequestedBy,
  892. );
  893. },
  894. 'click .js-field-has-card-sorting-by-number'(evt) {
  895. evt.preventDefault();
  896. this.currentBoard.allowsCardSortingByNumber = !this.currentBoard
  897. .allowsCardSortingByNumber;
  898. this.currentBoard.setAllowsCardSortingByNumber(
  899. this.currentBoard.allowsCardSortingByNumber,
  900. );
  901. $(`.js-field-has-card-sorting-by-number ${MCB}`).toggleClass(
  902. CKCLS,
  903. this.currentBoard.allowsCardSortingByNumber,
  904. );
  905. $('.js-field-has-card-sorting-by-number').toggleClass(
  906. CKCLS,
  907. this.currentBoard.allowsCardSortingByNumber,
  908. );
  909. },
  910. 'click .js-field-has-labels'(evt) {
  911. evt.preventDefault();
  912. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  913. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  914. $(`.js-field-has-labels ${MCB}`).toggleClass(
  915. CKCLS,
  916. this.currentBoard.allowsAssignee,
  917. );
  918. $('.js-field-has-labels').toggleClass(
  919. CKCLS,
  920. this.currentBoard.allowsLabels,
  921. );
  922. },
  923. 'click .js-field-has-description-title'(evt) {
  924. evt.preventDefault();
  925. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  926. .allowsDescriptionTitle;
  927. this.currentBoard.setAllowsDescriptionTitle(
  928. this.currentBoard.allowsDescriptionTitle,
  929. );
  930. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  931. CKCLS,
  932. this.currentBoard.allowsDescriptionTitle,
  933. );
  934. $('.js-field-has-description-title').toggleClass(
  935. CKCLS,
  936. this.currentBoard.allowsDescriptionTitle,
  937. );
  938. },
  939. 'click .js-field-has-description-text'(evt) {
  940. evt.preventDefault();
  941. this.currentBoard.allowsDescriptionText = !this.currentBoard
  942. .allowsDescriptionText;
  943. this.currentBoard.setAllowsDescriptionText(
  944. this.currentBoard.allowsDescriptionText,
  945. );
  946. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  947. CKCLS,
  948. this.currentBoard.allowsDescriptionText,
  949. );
  950. $('.js-field-has-description-text').toggleClass(
  951. CKCLS,
  952. this.currentBoard.allowsDescriptionText,
  953. );
  954. },
  955. 'click .js-field-has-checklists'(evt) {
  956. evt.preventDefault();
  957. this.currentBoard.allowsChecklists = !this.currentBoard
  958. .allowsChecklists;
  959. this.currentBoard.setAllowsChecklists(
  960. this.currentBoard.allowsChecklists,
  961. );
  962. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  963. CKCLS,
  964. this.currentBoard.allowsChecklists,
  965. );
  966. $('.js-field-has-checklists').toggleClass(
  967. CKCLS,
  968. this.currentBoard.allowsChecklists,
  969. );
  970. },
  971. 'click .js-field-has-attachments'(evt) {
  972. evt.preventDefault();
  973. this.currentBoard.allowsAttachments = !this.currentBoard
  974. .allowsAttachments;
  975. this.currentBoard.setAllowsAttachments(
  976. this.currentBoard.allowsAttachments,
  977. );
  978. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  979. CKCLS,
  980. this.currentBoard.allowsAttachments,
  981. );
  982. $('.js-field-has-attachments').toggleClass(
  983. CKCLS,
  984. this.currentBoard.allowsAttachments,
  985. );
  986. },
  987. 'click .js-field-has-comments'(evt) {
  988. evt.preventDefault();
  989. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  990. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  991. $(`.js-field-has-comments ${MCB}`).toggleClass(
  992. CKCLS,
  993. this.currentBoard.allowsComments,
  994. );
  995. $('.js-field-has-comments').toggleClass(
  996. CKCLS,
  997. this.currentBoard.allowsComments,
  998. );
  999. },
  1000. 'click .js-field-has-activities'(evt) {
  1001. evt.preventDefault();
  1002. this.currentBoard.allowsActivities = !this.currentBoard
  1003. .allowsActivities;
  1004. this.currentBoard.setAllowsActivities(
  1005. this.currentBoard.allowsActivities,
  1006. );
  1007. $(`.js-field-has-activities ${MCB}`).toggleClass(
  1008. CKCLS,
  1009. this.currentBoard.allowsActivities,
  1010. );
  1011. $('.js-field-has-activities').toggleClass(
  1012. CKCLS,
  1013. this.currentBoard.allowsActivities,
  1014. );
  1015. },
  1016. },
  1017. ];
  1018. },
  1019. }).register('boardCardSettingsPopup');
  1020. BlazeComponent.extendComponent({
  1021. onCreated() {
  1022. this.error = new ReactiveVar('');
  1023. this.loading = new ReactiveVar(false);
  1024. },
  1025. onRendered() {
  1026. this.find('.js-search-member input').focus();
  1027. this.setLoading(false);
  1028. },
  1029. isBoardMember() {
  1030. const userId = this.currentData()._id;
  1031. const user = Users.findOne(userId);
  1032. return user && user.isBoardMember();
  1033. },
  1034. isValidEmail(email) {
  1035. return SimpleSchema.RegEx.Email.test(email);
  1036. },
  1037. setError(error) {
  1038. this.error.set(error);
  1039. },
  1040. setLoading(w) {
  1041. this.loading.set(w);
  1042. },
  1043. isLoading() {
  1044. return this.loading.get();
  1045. },
  1046. inviteUser(idNameEmail) {
  1047. const boardId = Session.get('currentBoard');
  1048. this.setLoading(true);
  1049. const self = this;
  1050. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  1051. self.setLoading(false);
  1052. if (err) self.setError(err.error);
  1053. else if (ret.email) self.setError('email-sent');
  1054. else Popup.close();
  1055. });
  1056. },
  1057. events() {
  1058. return [
  1059. {
  1060. 'keyup input'() {
  1061. this.setError('');
  1062. },
  1063. 'click .js-select-member'() {
  1064. const userId = this.currentData()._id;
  1065. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1066. if (!currentBoard.hasMember(userId)) {
  1067. this.inviteUser(userId);
  1068. }
  1069. },
  1070. 'click .js-email-invite'() {
  1071. const idNameEmail = $('.js-search-member input').val();
  1072. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  1073. this.inviteUser(idNameEmail);
  1074. } else this.setError('email-invalid');
  1075. },
  1076. },
  1077. ];
  1078. },
  1079. }).register('addMemberPopup');
  1080. Template.changePermissionsPopup.events({
  1081. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  1082. event,
  1083. ) {
  1084. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1085. const memberId = this.userId;
  1086. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  1087. const isCommentOnly = $(event.currentTarget).hasClass(
  1088. 'js-set-comment-only',
  1089. );
  1090. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  1091. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  1092. currentBoard.setMemberPermission(
  1093. memberId,
  1094. isAdmin,
  1095. isNoComments,
  1096. isCommentOnly,
  1097. isWorker,
  1098. );
  1099. Popup.back(1);
  1100. },
  1101. });
  1102. Template.changePermissionsPopup.helpers({
  1103. isAdmin() {
  1104. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1105. return currentBoard.hasAdmin(this.userId);
  1106. },
  1107. isNormal() {
  1108. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1109. return (
  1110. !currentBoard.hasAdmin(this.userId) &&
  1111. !currentBoard.hasNoComments(this.userId) &&
  1112. !currentBoard.hasCommentOnly(this.userId) &&
  1113. !currentBoard.hasWorker(this.userId)
  1114. );
  1115. },
  1116. isNoComments() {
  1117. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1118. return (
  1119. !currentBoard.hasAdmin(this.userId) &&
  1120. currentBoard.hasNoComments(this.userId)
  1121. );
  1122. },
  1123. isCommentOnly() {
  1124. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1125. return (
  1126. !currentBoard.hasAdmin(this.userId) &&
  1127. currentBoard.hasCommentOnly(this.userId)
  1128. );
  1129. },
  1130. isWorker() {
  1131. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1132. return (
  1133. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  1134. );
  1135. },
  1136. isLastAdmin() {
  1137. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1138. return (
  1139. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1140. );
  1141. },
  1142. });