sidebar.js 30 KB

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