sidebar.js 30 KB

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