sidebar.js 32 KB

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