sidebar.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  1. Sidebar = null;
  2. const defaultView = 'home';
  3. const MCB = '.materialCheckBox';
  4. const CKCLS = 'is-checked';
  5. const viewTitles = {
  6. filter: 'filter-cards',
  7. search: 'search-cards',
  8. multiselection: 'multi-selection',
  9. customFields: 'custom-fields',
  10. archives: 'archives',
  11. };
  12. BlazeComponent.extendComponent({
  13. mixins() {
  14. return [Mixins.InfiniteScrolling];
  15. },
  16. onCreated() {
  17. this._isOpen = new ReactiveVar(false);
  18. this._view = new ReactiveVar(defaultView);
  19. Sidebar = this;
  20. },
  21. onDestroyed() {
  22. Sidebar = null;
  23. },
  24. isOpen() {
  25. return this._isOpen.get();
  26. },
  27. open() {
  28. if (!this._isOpen.get()) {
  29. this._isOpen.set(true);
  30. EscapeActions.executeUpTo('detailsPane');
  31. }
  32. },
  33. hide() {
  34. if (this._isOpen.get()) {
  35. this._isOpen.set(false);
  36. }
  37. },
  38. toggle() {
  39. this._isOpen.set(!this._isOpen.get());
  40. },
  41. calculateNextPeak() {
  42. const sidebarElement = this.find('.js-board-sidebar-content');
  43. if (sidebarElement) {
  44. const altitude = sidebarElement.scrollHeight;
  45. this.callFirstWith(this, 'setNextPeak', altitude);
  46. }
  47. },
  48. reachNextPeak() {
  49. const activitiesComponent = this.childComponents('activities')[0];
  50. activitiesComponent.loadNextPage();
  51. },
  52. isTongueHidden() {
  53. return this.isOpen() && this.getView() !== defaultView;
  54. },
  55. scrollTop() {
  56. this.$('.js-board-sidebar-content').scrollTop(0);
  57. },
  58. getView() {
  59. return this._view.get();
  60. },
  61. setView(view) {
  62. view = _.isString(view) ? view : defaultView;
  63. if (this._view.get() !== view) {
  64. this._view.set(view);
  65. this.scrollTop();
  66. EscapeActions.executeUpTo('detailsPane');
  67. }
  68. this.open();
  69. },
  70. isDefaultView() {
  71. return this.getView() === defaultView;
  72. },
  73. getViewTemplate() {
  74. return `${this.getView()}Sidebar`;
  75. },
  76. getViewTitle() {
  77. return TAPi18n.__(viewTitles[this.getView()]);
  78. },
  79. showTongueTitle() {
  80. if (this.isOpen()) return `${TAPi18n.__('sidebar-close')}`;
  81. else return `${TAPi18n.__('sidebar-open')}`;
  82. },
  83. events() {
  84. return [
  85. {
  86. 'click .js-hide-sidebar': this.hide,
  87. 'click .js-toggle-sidebar': this.toggle,
  88. 'click .js-back-home': this.setView,
  89. 'click .js-toggle-minicard-label-text'() {
  90. currentUser = Meteor.user();
  91. if (currentUser) {
  92. Meteor.call('toggleMinicardLabelText');
  93. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  94. window.localStorage.removeItem('hiddenMinicardLabelText');
  95. location.reload();
  96. } else {
  97. window.localStorage.setItem('hiddenMinicardLabelText', 'true');
  98. location.reload();
  99. }
  100. },
  101. 'click .js-shortcuts'() {
  102. FlowRouter.go('shortcuts');
  103. },
  104. },
  105. ];
  106. },
  107. }).register('sidebar');
  108. Blaze.registerHelper('Sidebar', () => Sidebar);
  109. Template.homeSidebar.helpers({
  110. hiddenMinicardLabelText() {
  111. currentUser = Meteor.user();
  112. if (currentUser) {
  113. return (currentUser.profile || {}).hiddenMinicardLabelText;
  114. } else if (window.localStorage.getItem('hiddenMinicardLabelText')) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. },
  120. });
  121. EscapeActions.register(
  122. 'sidebarView',
  123. () => {
  124. Sidebar.setView(defaultView);
  125. },
  126. () => {
  127. return Sidebar && Sidebar.getView() !== defaultView;
  128. },
  129. );
  130. Template.memberPopup.helpers({
  131. user() {
  132. return Users.findOne(this.userId);
  133. },
  134. isBoardAdmin() {
  135. return Meteor.user().isBoardAdmin();
  136. },
  137. memberType() {
  138. const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
  139. if (type === 'normal') {
  140. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  141. const commentOnly = currentBoard.hasCommentOnly(this.userId);
  142. const noComments = currentBoard.hasNoComments(this.userId);
  143. const worker = currentBoard.hasWorker(this.userId);
  144. if (commentOnly) {
  145. return TAPi18n.__('comment-only');
  146. } else if (noComments) {
  147. return TAPi18n.__('no-comments');
  148. } else if (worker) {
  149. return TAPi18n.__('worker');
  150. } else {
  151. return TAPi18n.__(type);
  152. }
  153. } else {
  154. return TAPi18n.__(type);
  155. }
  156. },
  157. isInvited() {
  158. return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
  159. },
  160. });
  161. Template.boardMenuPopup.events({
  162. 'click .js-rename-board': Popup.open('boardChangeTitle'),
  163. 'click .js-open-rules-view'() {
  164. Modal.openWide('rulesMain');
  165. Popup.close();
  166. },
  167. 'click .js-custom-fields'() {
  168. Sidebar.setView('customFields');
  169. Popup.close();
  170. },
  171. 'click .js-open-archives'() {
  172. Sidebar.setView('archives');
  173. Popup.close();
  174. },
  175. 'click .js-change-board-color': Popup.open('boardChangeColor'),
  176. 'click .js-change-language': Popup.open('changeLanguage'),
  177. 'click .js-archive-board ': Popup.afterConfirm('archiveBoard', function() {
  178. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  179. currentBoard.archive();
  180. // XXX We should have some kind of notification on top of the page to
  181. // confirm that the board was successfully archived.
  182. FlowRouter.go('home');
  183. }),
  184. 'click .js-delete-board': Popup.afterConfirm('deleteBoard', function() {
  185. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  186. Popup.close();
  187. Boards.remove(currentBoard._id);
  188. FlowRouter.go('home');
  189. }),
  190. 'click .js-outgoing-webhooks': Popup.open('outgoingWebhooks'),
  191. 'click .js-import-board': Popup.open('chooseBoardSource'),
  192. 'click .js-subtask-settings': Popup.open('boardSubtaskSettings'),
  193. 'click .js-card-settings': Popup.open('boardCardSettings'),
  194. 'click .js-export-board': Popup.open('exportBoard'),
  195. });
  196. Template.boardMenuPopup.onCreated(function() {
  197. this.apiEnabled = new ReactiveVar(false);
  198. Meteor.call('_isApiEnabled', (e, result) => {
  199. this.apiEnabled.set(result);
  200. });
  201. });
  202. Template.boardMenuPopup.helpers({
  203. isBoardAdmin() {
  204. return Meteor.user().isBoardAdmin();
  205. },
  206. withApi() {
  207. return Template.instance().apiEnabled.get();
  208. },
  209. exportUrl() {
  210. const params = {
  211. boardId: Session.get('currentBoard'),
  212. };
  213. const queryParams = {
  214. authToken: Accounts._storedLoginToken(),
  215. };
  216. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  217. },
  218. exportFilename() {
  219. const boardId = Session.get('currentBoard');
  220. return `export-board-${boardId}.json`;
  221. },
  222. });
  223. Template.memberPopup.events({
  224. 'click .js-filter-member'() {
  225. Filter.members.toggle(this.userId);
  226. Popup.close();
  227. },
  228. 'click .js-change-role': Popup.open('changePermissions'),
  229. 'click .js-remove-member': Popup.afterConfirm('removeMember', function() {
  230. // This works from removing member from board, card members and assignees.
  231. const boardId = Session.get('currentBoard');
  232. const memberId = this.userId;
  233. Cards.find({ boardId, members: memberId }).forEach(card => {
  234. card.unassignMember(memberId);
  235. });
  236. Cards.find({ boardId, assignees: memberId }).forEach(card => {
  237. card.unassignAssignee(memberId);
  238. });
  239. Boards.findOne(boardId).removeMember(memberId);
  240. Popup.close();
  241. }),
  242. 'click .js-leave-member': Popup.afterConfirm('leaveBoard', () => {
  243. const boardId = Session.get('currentBoard');
  244. Meteor.call('quitBoard', boardId, () => {
  245. Popup.close();
  246. FlowRouter.go('home');
  247. });
  248. }),
  249. });
  250. Template.removeMemberPopup.helpers({
  251. user() {
  252. return Users.findOne(this.userId);
  253. },
  254. board() {
  255. return Boards.findOne(Session.get('currentBoard'));
  256. },
  257. });
  258. Template.leaveBoardPopup.helpers({
  259. board() {
  260. return Boards.findOne(Session.get('currentBoard'));
  261. },
  262. });
  263. Template.membersWidget.helpers({
  264. isInvited() {
  265. const user = Meteor.user();
  266. return user && user.isInvitedTo(Session.get('currentBoard'));
  267. },
  268. isWorker() {
  269. const user = Meteor.user();
  270. if (user) {
  271. return Meteor.call(Boards.hasWorker(user.memberId));
  272. } else {
  273. return false;
  274. }
  275. },
  276. isBoardAdmin() {
  277. return Meteor.user().isBoardAdmin();
  278. },
  279. });
  280. Template.membersWidget.events({
  281. 'click .js-member': Popup.open('member'),
  282. 'click .js-open-board-menu': Popup.open('boardMenu'),
  283. 'click .js-manage-board-members': Popup.open('addMember'),
  284. 'click .js-manage-board-addOrg': Popup.open('addBoardOrg'),
  285. 'click .js-manage-board-addTeam': Popup.open('addBoardTeam'),
  286. 'click .js-import': Popup.open('boardImportBoard'),
  287. submit: this.onSubmit,
  288. 'click .js-import-board': Popup.open('chooseBoardSource'),
  289. 'click .js-open-archived-board'() {
  290. Modal.open('archivedBoards');
  291. },
  292. 'click .sandstorm-powerbox-request-identity'() {
  293. window.sandstormRequestIdentity();
  294. },
  295. 'click .js-member-invite-accept'() {
  296. const boardId = Session.get('currentBoard');
  297. Meteor.user().removeInvite(boardId);
  298. },
  299. 'click .js-member-invite-decline'() {
  300. const boardId = Session.get('currentBoard');
  301. Meteor.call('quitBoard', boardId, (err, ret) => {
  302. if (!err && ret) {
  303. Meteor.user().removeInvite(boardId);
  304. FlowRouter.go('home');
  305. }
  306. });
  307. },
  308. });
  309. BlazeComponent.extendComponent({
  310. boardId() {
  311. return Session.get('currentBoard') || Integrations.Const.GLOBAL_WEBHOOK_ID;
  312. },
  313. integrations() {
  314. const boardId = this.boardId();
  315. return Integrations.find({ boardId: `${boardId}` }).fetch();
  316. },
  317. types() {
  318. return Integrations.Const.WEBHOOK_TYPES;
  319. },
  320. integration(cond) {
  321. const boardId = this.boardId();
  322. const condition = { boardId, ...cond };
  323. for (const k in condition) {
  324. if (!condition[k]) delete condition[k];
  325. }
  326. return Integrations.findOne(condition);
  327. },
  328. onCreated() {
  329. this.disabled = new ReactiveVar(false);
  330. },
  331. events() {
  332. return [
  333. {
  334. 'click a.flex'(evt) {
  335. this.disabled.set(!this.disabled.get());
  336. $(evt.target).toggleClass(CKCLS, this.disabled.get());
  337. },
  338. submit(evt) {
  339. evt.preventDefault();
  340. const url = evt.target.url.value;
  341. const boardId = this.boardId();
  342. let id = null;
  343. let integration = null;
  344. const title = evt.target.title.value;
  345. const token = evt.target.token.value;
  346. const type = evt.target.type.value;
  347. const enabled = !this.disabled.get();
  348. let remove = false;
  349. const values = {
  350. url,
  351. type,
  352. token,
  353. title,
  354. enabled,
  355. };
  356. if (evt.target.id) {
  357. id = evt.target.id.value;
  358. integration = this.integration({ _id: id });
  359. remove = !url;
  360. } else if (url) {
  361. integration = this.integration({ url, token });
  362. }
  363. if (remove) {
  364. Integrations.remove(integration._id);
  365. } else if (integration && integration._id) {
  366. Integrations.update(integration._id, {
  367. $set: values,
  368. });
  369. } else if (url) {
  370. Integrations.insert({
  371. ...values,
  372. userId: Meteor.userId(),
  373. enabled: true,
  374. boardId,
  375. activities: ['all'],
  376. });
  377. }
  378. Popup.close();
  379. },
  380. },
  381. ];
  382. },
  383. }).register('outgoingWebhooksPopup');
  384. BlazeComponent.extendComponent({
  385. template() {
  386. return 'chooseBoardSource';
  387. },
  388. }).register('chooseBoardSourcePopup');
  389. BlazeComponent.extendComponent({
  390. template() {
  391. return 'exportBoard';
  392. },
  393. withApi() {
  394. return Template.instance().apiEnabled.get();
  395. },
  396. exportUrl() {
  397. const params = {
  398. boardId: Session.get('currentBoard'),
  399. };
  400. const queryParams = {
  401. authToken: Accounts._storedLoginToken(),
  402. };
  403. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  404. },
  405. exportUrlExcel() {
  406. const params = {
  407. boardId: Session.get('currentBoard'),
  408. };
  409. const queryParams = {
  410. authToken: Accounts._storedLoginToken(),
  411. };
  412. return FlowRouter.path(
  413. '/api/boards/:boardId/exportExcel',
  414. params,
  415. queryParams,
  416. );
  417. },
  418. exportFilenameExcel() {
  419. const boardId = Session.get('currentBoard');
  420. return `export-board-excel-${boardId}.xlsx`;
  421. },
  422. exportCsvUrl() {
  423. const params = {
  424. boardId: Session.get('currentBoard'),
  425. };
  426. const queryParams = {
  427. authToken: Accounts._storedLoginToken(),
  428. };
  429. return FlowRouter.path(
  430. '/api/boards/:boardId/export/csv',
  431. params,
  432. queryParams,
  433. );
  434. },
  435. exportTsvUrl() {
  436. const params = {
  437. boardId: Session.get('currentBoard'),
  438. };
  439. const queryParams = {
  440. authToken: Accounts._storedLoginToken(),
  441. delimiter: '\t',
  442. };
  443. return FlowRouter.path(
  444. '/api/boards/:boardId/export/csv',
  445. params,
  446. queryParams,
  447. );
  448. },
  449. exportJsonFilename() {
  450. const boardId = Session.get('currentBoard');
  451. return `export-board-${boardId}.json`;
  452. },
  453. exportCsvFilename() {
  454. const boardId = Session.get('currentBoard');
  455. return `export-board-${boardId}.csv`;
  456. },
  457. exportTsvFilename() {
  458. const boardId = Session.get('currentBoard');
  459. return `export-board-${boardId}.tsv`;
  460. },
  461. }).register('exportBoardPopup');
  462. Template.exportBoard.events({
  463. 'click .html-export-board': async event => {
  464. event.preventDefault();
  465. await ExportHtml(Popup)();
  466. },
  467. });
  468. Template.labelsWidget.events({
  469. 'click .js-label': Popup.open('editLabel'),
  470. 'click .js-add-label': Popup.open('createLabel'),
  471. });
  472. Template.labelsWidget.helpers({
  473. isBoardAdmin() {
  474. return Meteor.user().isBoardAdmin();
  475. },
  476. });
  477. // Board members can assign people or labels by drag-dropping elements from the
  478. // sidebar to the cards on the board. In order to re-initialize the jquery-ui
  479. // plugin any time a draggable member or label is modified or removed we use a
  480. // autorun function and register a dependency on the both members and labels
  481. // fields of the current board document.
  482. function draggableMembersLabelsWidgets() {
  483. this.autorun(() => {
  484. const currentBoardId = Tracker.nonreactive(() => {
  485. return Session.get('currentBoard');
  486. });
  487. Boards.findOne(currentBoardId, {
  488. fields: {
  489. members: 1,
  490. labels: 1,
  491. },
  492. });
  493. Tracker.afterFlush(() => {
  494. const $draggables = this.$('.js-member,.js-label');
  495. $draggables.draggable({
  496. appendTo: 'body',
  497. helper: 'clone',
  498. revert: 'invalid',
  499. revertDuration: 150,
  500. snap: false,
  501. snapMode: 'both',
  502. start() {
  503. EscapeActions.executeUpTo('popup-back');
  504. },
  505. });
  506. function userIsMember() {
  507. return Meteor.user() && Meteor.user().isBoardMember();
  508. }
  509. this.autorun(() => {
  510. $draggables.draggable('option', 'disabled', !userIsMember());
  511. });
  512. });
  513. });
  514. }
  515. Template.membersWidget.onRendered(draggableMembersLabelsWidgets);
  516. Template.labelsWidget.onRendered(draggableMembersLabelsWidgets);
  517. BlazeComponent.extendComponent({
  518. backgroundColors() {
  519. return Boards.simpleSchema()._schema.color.allowedValues;
  520. },
  521. isSelected() {
  522. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  523. return currentBoard.color === this.currentData().toString();
  524. },
  525. events() {
  526. return [
  527. {
  528. 'click .js-select-background'(evt) {
  529. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  530. const newColor = this.currentData().toString();
  531. currentBoard.setColor(newColor);
  532. evt.preventDefault();
  533. },
  534. },
  535. ];
  536. },
  537. }).register('boardChangeColorPopup');
  538. BlazeComponent.extendComponent({
  539. onCreated() {
  540. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  541. },
  542. allowsSubtasks() {
  543. return this.currentBoard.allowsSubtasks;
  544. },
  545. allowsReceivedDate() {
  546. return this.currentBoard.allowsReceivedDate;
  547. },
  548. isBoardSelected() {
  549. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  550. },
  551. isNullBoardSelected() {
  552. return (
  553. this.currentBoard.subtasksDefaultBoardId === null ||
  554. this.currentBoard.subtasksDefaultBoardId === undefined
  555. );
  556. },
  557. boards() {
  558. return Boards.find(
  559. {
  560. archived: false,
  561. 'members.userId': Meteor.userId(),
  562. },
  563. {
  564. sort: { sort: 1 /* boards default sorting */ },
  565. },
  566. );
  567. },
  568. lists() {
  569. return Lists.find(
  570. {
  571. boardId: this.currentBoard._id,
  572. archived: false,
  573. },
  574. {
  575. sort: ['title'],
  576. },
  577. );
  578. },
  579. hasLists() {
  580. return this.lists().count() > 0;
  581. },
  582. isListSelected() {
  583. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  584. },
  585. presentParentTask() {
  586. let result = this.currentBoard.presentParentTask;
  587. if (result === null || result === undefined) {
  588. result = 'no-parent';
  589. }
  590. return result;
  591. },
  592. events() {
  593. return [
  594. {
  595. 'click .js-field-has-subtasks'(evt) {
  596. evt.preventDefault();
  597. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  598. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  599. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  600. CKCLS,
  601. this.currentBoard.allowsSubtasks,
  602. );
  603. $('.js-field-has-subtasks').toggleClass(
  604. CKCLS,
  605. this.currentBoard.allowsSubtasks,
  606. );
  607. $('.js-field-deposit-board').prop(
  608. 'disabled',
  609. !this.currentBoard.allowsSubtasks,
  610. );
  611. },
  612. 'change .js-field-deposit-board'(evt) {
  613. let value = evt.target.value;
  614. if (value === 'null') {
  615. value = null;
  616. }
  617. this.currentBoard.setSubtasksDefaultBoardId(value);
  618. evt.preventDefault();
  619. },
  620. 'change .js-field-deposit-list'(evt) {
  621. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  622. evt.preventDefault();
  623. },
  624. 'click .js-field-show-parent-in-minicard'(evt) {
  625. const value =
  626. evt.target.id ||
  627. $(evt.target).parent()[0].id ||
  628. $(evt.target)
  629. .parent()[0]
  630. .parent()[0].id;
  631. const options = [
  632. 'prefix-with-full-path',
  633. 'prefix-with-parent',
  634. 'subtext-with-full-path',
  635. 'subtext-with-parent',
  636. 'no-parent',
  637. ];
  638. options.forEach(function(element) {
  639. if (element !== value) {
  640. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  641. $(`#${element}`).toggleClass(CKCLS, false);
  642. }
  643. });
  644. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  645. $(`#${value}`).toggleClass(CKCLS, true);
  646. this.currentBoard.setPresentParentTask(value);
  647. evt.preventDefault();
  648. },
  649. },
  650. ];
  651. },
  652. }).register('boardSubtaskSettingsPopup');
  653. BlazeComponent.extendComponent({
  654. onCreated() {
  655. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  656. },
  657. allowsReceivedDate() {
  658. return this.currentBoard.allowsReceivedDate;
  659. },
  660. allowsStartDate() {
  661. return this.currentBoard.allowsStartDate;
  662. },
  663. allowsDueDate() {
  664. return this.currentBoard.allowsDueDate;
  665. },
  666. allowsEndDate() {
  667. return this.currentBoard.allowsEndDate;
  668. },
  669. allowsSubtasks() {
  670. return this.currentBoard.allowsSubtasks;
  671. },
  672. allowsCreator() {
  673. return (
  674. this.currentBoard.allowsCreator === null ||
  675. this.currentBoard.allowsCreator === undefined ||
  676. this.currentBoard.allowsCreator
  677. );
  678. },
  679. allowsMembers() {
  680. return this.currentBoard.allowsMembers;
  681. },
  682. allowsAssignee() {
  683. return this.currentBoard.allowsAssignee;
  684. },
  685. allowsAssignedBy() {
  686. return this.currentBoard.allowsAssignedBy;
  687. },
  688. allowsRequestedBy() {
  689. return this.currentBoard.allowsRequestedBy;
  690. },
  691. allowsCardSortingByNumber() {
  692. return this.currentBoard.allowsCardSortingByNumber;
  693. },
  694. allowsLabels() {
  695. return this.currentBoard.allowsLabels;
  696. },
  697. allowsChecklists() {
  698. return this.currentBoard.allowsChecklists;
  699. },
  700. allowsAttachments() {
  701. return this.currentBoard.allowsAttachments;
  702. },
  703. allowsComments() {
  704. return this.currentBoard.allowsComments;
  705. },
  706. allowsDescriptionTitle() {
  707. return this.currentBoard.allowsDescriptionTitle;
  708. },
  709. allowsDescriptionText() {
  710. return this.currentBoard.allowsDescriptionText;
  711. },
  712. isBoardSelected() {
  713. return this.currentBoard.dateSettingsDefaultBoardID;
  714. },
  715. isNullBoardSelected() {
  716. return (
  717. this.currentBoard.dateSettingsDefaultBoardId === null ||
  718. this.currentBoard.dateSettingsDefaultBoardId === undefined
  719. );
  720. },
  721. boards() {
  722. return Boards.find(
  723. {
  724. archived: false,
  725. 'members.userId': Meteor.userId(),
  726. },
  727. {
  728. sort: { sort: 1 /* boards default sorting */ },
  729. },
  730. );
  731. },
  732. lists() {
  733. return Lists.find(
  734. {
  735. boardId: this.currentBoard._id,
  736. archived: false,
  737. },
  738. {
  739. sort: ['title'],
  740. },
  741. );
  742. },
  743. hasLists() {
  744. return this.lists().count() > 0;
  745. },
  746. isListSelected() {
  747. return (
  748. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  749. );
  750. },
  751. events() {
  752. return [
  753. {
  754. 'click .js-field-has-receiveddate'(evt) {
  755. evt.preventDefault();
  756. this.currentBoard.allowsReceivedDate = !this.currentBoard
  757. .allowsReceivedDate;
  758. this.currentBoard.setAllowsReceivedDate(
  759. this.currentBoard.allowsReceivedDate,
  760. );
  761. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  762. CKCLS,
  763. this.currentBoard.allowsReceivedDate,
  764. );
  765. $('.js-field-has-receiveddate').toggleClass(
  766. CKCLS,
  767. this.currentBoard.allowsReceivedDate,
  768. );
  769. },
  770. 'click .js-field-has-startdate'(evt) {
  771. evt.preventDefault();
  772. this.currentBoard.allowsStartDate = !this.currentBoard
  773. .allowsStartDate;
  774. this.currentBoard.setAllowsStartDate(
  775. this.currentBoard.allowsStartDate,
  776. );
  777. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  778. CKCLS,
  779. this.currentBoard.allowsStartDate,
  780. );
  781. $('.js-field-has-startdate').toggleClass(
  782. CKCLS,
  783. this.currentBoard.allowsStartDate,
  784. );
  785. },
  786. 'click .js-field-has-enddate'(evt) {
  787. evt.preventDefault();
  788. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  789. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  790. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  791. CKCLS,
  792. this.currentBoard.allowsEndDate,
  793. );
  794. $('.js-field-has-enddate').toggleClass(
  795. CKCLS,
  796. this.currentBoard.allowsEndDate,
  797. );
  798. },
  799. 'click .js-field-has-duedate'(evt) {
  800. evt.preventDefault();
  801. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  802. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  803. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  804. CKCLS,
  805. this.currentBoard.allowsDueDate,
  806. );
  807. $('.js-field-has-duedate').toggleClass(
  808. CKCLS,
  809. this.currentBoard.allowsDueDate,
  810. );
  811. },
  812. 'click .js-field-has-subtasks'(evt) {
  813. evt.preventDefault();
  814. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  815. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  816. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  817. CKCLS,
  818. this.currentBoard.allowsSubtasks,
  819. );
  820. $('.js-field-has-subtasks').toggleClass(
  821. CKCLS,
  822. this.currentBoard.allowsSubtasks,
  823. );
  824. },
  825. 'click .js-field-has-creator'(evt) {
  826. evt.preventDefault();
  827. this.currentBoard.allowsCreator = !this.currentBoard.allowsCreator;
  828. this.currentBoard.setAllowsCreator(this.currentBoard.allowsCreator);
  829. $(`.js-field-has-creator ${MCB}`).toggleClass(
  830. CKCLS,
  831. this.currentBoard.allowsCreator,
  832. );
  833. $('.js-field-has-creator').toggleClass(
  834. CKCLS,
  835. this.currentBoard.allowsCreator,
  836. );
  837. },
  838. 'click .js-field-has-members'(evt) {
  839. evt.preventDefault();
  840. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  841. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  842. $(`.js-field-has-members ${MCB}`).toggleClass(
  843. CKCLS,
  844. this.currentBoard.allowsMembers,
  845. );
  846. $('.js-field-has-members').toggleClass(
  847. CKCLS,
  848. this.currentBoard.allowsMembers,
  849. );
  850. },
  851. 'click .js-field-has-assignee'(evt) {
  852. evt.preventDefault();
  853. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  854. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  855. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  856. CKCLS,
  857. this.currentBoard.allowsAssignee,
  858. );
  859. $('.js-field-has-assignee').toggleClass(
  860. CKCLS,
  861. this.currentBoard.allowsAssignee,
  862. );
  863. },
  864. 'click .js-field-has-assigned-by'(evt) {
  865. evt.preventDefault();
  866. this.currentBoard.allowsAssignedBy = !this.currentBoard
  867. .allowsAssignedBy;
  868. this.currentBoard.setAllowsAssignedBy(
  869. this.currentBoard.allowsAssignedBy,
  870. );
  871. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  872. CKCLS,
  873. this.currentBoard.allowsAssignedBy,
  874. );
  875. $('.js-field-has-assigned-by').toggleClass(
  876. CKCLS,
  877. this.currentBoard.allowsAssignedBy,
  878. );
  879. },
  880. 'click .js-field-has-requested-by'(evt) {
  881. evt.preventDefault();
  882. this.currentBoard.allowsRequestedBy = !this.currentBoard
  883. .allowsRequestedBy;
  884. this.currentBoard.setAllowsRequestedBy(
  885. this.currentBoard.allowsRequestedBy,
  886. );
  887. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  888. CKCLS,
  889. this.currentBoard.allowsRequestedBy,
  890. );
  891. $('.js-field-has-requested-by').toggleClass(
  892. CKCLS,
  893. this.currentBoard.allowsRequestedBy,
  894. );
  895. },
  896. 'click .js-field-has-card-sorting-by-number'(evt) {
  897. evt.preventDefault();
  898. this.currentBoard.allowsCardSortingByNumber = !this.currentBoard
  899. .allowsCardSortingByNumber;
  900. this.currentBoard.setAllowsCardSortingByNumber(
  901. this.currentBoard.allowsCardSortingByNumber,
  902. );
  903. $(`.js-field-has-card-sorting-by-number ${MCB}`).toggleClass(
  904. CKCLS,
  905. this.currentBoard.allowsCardSortingByNumber,
  906. );
  907. $('.js-field-has-card-sorting-by-number').toggleClass(
  908. CKCLS,
  909. this.currentBoard.allowsCardSortingByNumber,
  910. );
  911. },
  912. 'click .js-field-has-labels'(evt) {
  913. evt.preventDefault();
  914. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  915. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  916. $(`.js-field-has-labels ${MCB}`).toggleClass(
  917. CKCLS,
  918. this.currentBoard.allowsAssignee,
  919. );
  920. $('.js-field-has-labels').toggleClass(
  921. CKCLS,
  922. this.currentBoard.allowsLabels,
  923. );
  924. },
  925. 'click .js-field-has-description-title'(evt) {
  926. evt.preventDefault();
  927. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  928. .allowsDescriptionTitle;
  929. this.currentBoard.setAllowsDescriptionTitle(
  930. this.currentBoard.allowsDescriptionTitle,
  931. );
  932. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  933. CKCLS,
  934. this.currentBoard.allowsDescriptionTitle,
  935. );
  936. $('.js-field-has-description-title').toggleClass(
  937. CKCLS,
  938. this.currentBoard.allowsDescriptionTitle,
  939. );
  940. },
  941. 'click .js-field-has-description-text'(evt) {
  942. evt.preventDefault();
  943. this.currentBoard.allowsDescriptionText = !this.currentBoard
  944. .allowsDescriptionText;
  945. this.currentBoard.setAllowsDescriptionText(
  946. this.currentBoard.allowsDescriptionText,
  947. );
  948. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  949. CKCLS,
  950. this.currentBoard.allowsDescriptionText,
  951. );
  952. $('.js-field-has-description-text').toggleClass(
  953. CKCLS,
  954. this.currentBoard.allowsDescriptionText,
  955. );
  956. },
  957. 'click .js-field-has-checklists'(evt) {
  958. evt.preventDefault();
  959. this.currentBoard.allowsChecklists = !this.currentBoard
  960. .allowsChecklists;
  961. this.currentBoard.setAllowsChecklists(
  962. this.currentBoard.allowsChecklists,
  963. );
  964. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  965. CKCLS,
  966. this.currentBoard.allowsChecklists,
  967. );
  968. $('.js-field-has-checklists').toggleClass(
  969. CKCLS,
  970. this.currentBoard.allowsChecklists,
  971. );
  972. },
  973. 'click .js-field-has-attachments'(evt) {
  974. evt.preventDefault();
  975. this.currentBoard.allowsAttachments = !this.currentBoard
  976. .allowsAttachments;
  977. this.currentBoard.setAllowsAttachments(
  978. this.currentBoard.allowsAttachments,
  979. );
  980. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  981. CKCLS,
  982. this.currentBoard.allowsAttachments,
  983. );
  984. $('.js-field-has-attachments').toggleClass(
  985. CKCLS,
  986. this.currentBoard.allowsAttachments,
  987. );
  988. },
  989. 'click .js-field-has-comments'(evt) {
  990. evt.preventDefault();
  991. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  992. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  993. $(`.js-field-has-comments ${MCB}`).toggleClass(
  994. CKCLS,
  995. this.currentBoard.allowsComments,
  996. );
  997. $('.js-field-has-comments').toggleClass(
  998. CKCLS,
  999. this.currentBoard.allowsComments,
  1000. );
  1001. },
  1002. 'click .js-field-has-activities'(evt) {
  1003. evt.preventDefault();
  1004. this.currentBoard.allowsActivities = !this.currentBoard
  1005. .allowsActivities;
  1006. this.currentBoard.setAllowsActivities(
  1007. this.currentBoard.allowsActivities,
  1008. );
  1009. $(`.js-field-has-activities ${MCB}`).toggleClass(
  1010. CKCLS,
  1011. this.currentBoard.allowsActivities,
  1012. );
  1013. $('.js-field-has-activities').toggleClass(
  1014. CKCLS,
  1015. this.currentBoard.allowsActivities,
  1016. );
  1017. },
  1018. },
  1019. ];
  1020. },
  1021. }).register('boardCardSettingsPopup');
  1022. BlazeComponent.extendComponent({
  1023. onCreated() {
  1024. this.error = new ReactiveVar('');
  1025. this.loading = new ReactiveVar(false);
  1026. },
  1027. onRendered() {
  1028. this.find('.js-search-member input').focus();
  1029. this.setLoading(false);
  1030. },
  1031. isBoardMember() {
  1032. const userId = this.currentData()._id;
  1033. const user = Users.findOne(userId);
  1034. return user && user.isBoardMember();
  1035. },
  1036. isValidEmail(email) {
  1037. return SimpleSchema.RegEx.Email.test(email);
  1038. },
  1039. setError(error) {
  1040. this.error.set(error);
  1041. },
  1042. setLoading(w) {
  1043. this.loading.set(w);
  1044. },
  1045. isLoading() {
  1046. return this.loading.get();
  1047. },
  1048. inviteUser(idNameEmail) {
  1049. const boardId = Session.get('currentBoard');
  1050. this.setLoading(true);
  1051. const self = this;
  1052. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  1053. self.setLoading(false);
  1054. if (err) self.setError(err.error);
  1055. else if (ret.email) self.setError('email-sent');
  1056. else Popup.close();
  1057. });
  1058. },
  1059. events() {
  1060. return [
  1061. {
  1062. 'keyup input'() {
  1063. this.setError('');
  1064. },
  1065. 'click .js-select-member'() {
  1066. const userId = this.currentData()._id;
  1067. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1068. if (!currentBoard.hasMember(userId)) {
  1069. this.inviteUser(userId);
  1070. }
  1071. },
  1072. 'click .js-email-invite'() {
  1073. const idNameEmail = $('.js-search-member input').val();
  1074. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  1075. this.inviteUser(idNameEmail);
  1076. } else this.setError('email-invalid');
  1077. },
  1078. },
  1079. ];
  1080. },
  1081. }).register('addMemberPopup');
  1082. BlazeComponent.extendComponent({
  1083. onCreated() {
  1084. this.error = new ReactiveVar('');
  1085. this.loading = new ReactiveVar(false);
  1086. this.findOrgsOptions = new ReactiveVar({});
  1087. this.page = new ReactiveVar(1);
  1088. this.autorun(() => {
  1089. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1090. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1091. });
  1092. },
  1093. onRendered() {
  1094. this.setLoading(false);
  1095. },
  1096. setError(error) {
  1097. this.error.set(error);
  1098. },
  1099. setLoading(w) {
  1100. this.loading.set(w);
  1101. },
  1102. isLoading() {
  1103. return this.loading.get();
  1104. },
  1105. events() {
  1106. return [
  1107. {
  1108. 'keyup input'() {
  1109. this.setError('');
  1110. },
  1111. 'change #jsBoardOrgs'() {
  1112. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1113. let selectElt = document.getElementById("jsBoardOrgs");
  1114. let selectedOrgId = selectElt.options[selectElt.selectedIndex].value;
  1115. let selectedOrgDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1116. let boardOrganizations = [];
  1117. if(currentBoard.orgs !== undefined){
  1118. for(let i = 0; i < currentBoard.orgs.length; i++){
  1119. boardOrganizations.push(currentBoard.orgs[i]);
  1120. }
  1121. }
  1122. if(!boardOrganizations.some((org) => org.orgDisplayName == selectedOrgDisplayName)){
  1123. boardOrganizations.push({
  1124. "orgId": selectedOrgId,
  1125. "orgDisplayName": selectedOrgDisplayName,
  1126. "isActive" : true,
  1127. })
  1128. if (selectedOrgId != "-1") {
  1129. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1130. }
  1131. }
  1132. Popup.close();
  1133. },
  1134. },
  1135. ];
  1136. },
  1137. }).register('addBoardOrgPopup');
  1138. Template.addBoardOrgPopup.helpers({
  1139. orgsDatas() {
  1140. // return Org.find({}, {sort: { createdAt: -1 }});
  1141. let orgs = Org.find({}, {sort: { createdAt: -1 }});
  1142. return orgs;
  1143. },
  1144. });
  1145. BlazeComponent.extendComponent({
  1146. onCreated() {
  1147. this.error = new ReactiveVar('');
  1148. this.loading = new ReactiveVar(false);
  1149. this.findOrgsOptions = new ReactiveVar({});
  1150. this.page = new ReactiveVar(1);
  1151. this.autorun(() => {
  1152. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1153. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1154. });
  1155. },
  1156. onRendered() {
  1157. this.setLoading(false);
  1158. },
  1159. setError(error) {
  1160. this.error.set(error);
  1161. },
  1162. setLoading(w) {
  1163. this.loading.set(w);
  1164. },
  1165. isLoading() {
  1166. return this.loading.get();
  1167. },
  1168. events() {
  1169. return [
  1170. {
  1171. 'keyup input'() {
  1172. this.setError('');
  1173. },
  1174. 'click #leaveBoardBtn'(){
  1175. let stringOrgId = document.getElementById('hideOrgId').value;
  1176. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1177. let boardOrganizations = [];
  1178. if(currentBoard.orgs !== undefined){
  1179. for(let i = 0; i < currentBoard.orgs.length; i++){
  1180. if(currentBoard.orgs[i].orgId != stringOrgId){
  1181. boardOrganizations.push(currentBoard.orgs[i]);
  1182. }
  1183. }
  1184. }
  1185. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1186. Popup.close();
  1187. },
  1188. 'click #cancelLeaveBoardBtn'(){
  1189. Popup.close();
  1190. },
  1191. },
  1192. ];
  1193. },
  1194. }).register('removeBoardOrgPopup');
  1195. Template.removeBoardOrgPopup.helpers({
  1196. org() {
  1197. return Org.findOne(this.orgId);
  1198. },
  1199. });
  1200. BlazeComponent.extendComponent({
  1201. onCreated() {
  1202. this.error = new ReactiveVar('');
  1203. this.loading = new ReactiveVar(false);
  1204. this.findOrgsOptions = new ReactiveVar({});
  1205. this.page = new ReactiveVar(1);
  1206. this.autorun(() => {
  1207. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1208. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1209. });
  1210. },
  1211. onRendered() {
  1212. this.setLoading(false);
  1213. },
  1214. setError(error) {
  1215. this.error.set(error);
  1216. },
  1217. setLoading(w) {
  1218. this.loading.set(w);
  1219. },
  1220. isLoading() {
  1221. return this.loading.get();
  1222. },
  1223. events() {
  1224. return [
  1225. {
  1226. 'keyup input'() {
  1227. this.setError('');
  1228. },
  1229. 'change #jsBoardTeams'() {
  1230. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1231. let selectElt = document.getElementById("jsBoardTeams");
  1232. let selectedTeamId = selectElt.options[selectElt.selectedIndex].value;
  1233. let selectedTeamDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1234. let boardTeams = [];
  1235. if(currentBoard.teams !== undefined){
  1236. for(let i = 0; i < currentBoard.teams.length; i++){
  1237. boardTeams.push(currentBoard.teams[i]);
  1238. }
  1239. }
  1240. if(!boardTeams.some((team) => team.teamDisplayName == selectedTeamDisplayName)){
  1241. boardTeams.push({
  1242. "teamId": selectedTeamId,
  1243. "teamDisplayName": selectedTeamDisplayName,
  1244. "isActive" : true,
  1245. })
  1246. if (selectedTeamId != "-1") {
  1247. Meteor.call('setBoardTeams', boardTeams, currentBoard._id);
  1248. }
  1249. }
  1250. Popup.close();
  1251. },
  1252. },
  1253. ];
  1254. },
  1255. }).register('addBoardTeamPopup');
  1256. Template.addBoardTeamPopup.helpers({
  1257. teamsDatas() {
  1258. let teams = Team.find({}, {sort: { createdAt: -1 }});
  1259. return teams;
  1260. },
  1261. });
  1262. BlazeComponent.extendComponent({
  1263. onCreated() {
  1264. this.error = new ReactiveVar('');
  1265. this.loading = new ReactiveVar(false);
  1266. this.findOrgsOptions = new ReactiveVar({});
  1267. this.page = new ReactiveVar(1);
  1268. this.autorun(() => {
  1269. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1270. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1271. });
  1272. },
  1273. onRendered() {
  1274. this.setLoading(false);
  1275. },
  1276. setError(error) {
  1277. this.error.set(error);
  1278. },
  1279. setLoading(w) {
  1280. this.loading.set(w);
  1281. },
  1282. isLoading() {
  1283. return this.loading.get();
  1284. },
  1285. events() {
  1286. return [
  1287. {
  1288. 'keyup input'() {
  1289. this.setError('');
  1290. },
  1291. 'click #leaveBoardTeamBtn'(){
  1292. let stringTeamId = document.getElementById('hideTeamId').value;
  1293. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1294. let boardTeams = [];
  1295. if(currentBoard.teams !== undefined){
  1296. for(let i = 0; i < currentBoard.teams.length; i++){
  1297. if(currentBoard.teams[i].teamId != stringTeamId){
  1298. boardTeams.push(currentBoard.teams[i]);
  1299. }
  1300. }
  1301. }
  1302. Meteor.call('setBoardTeams', boardTeams, currentBoard._id);
  1303. Popup.close();
  1304. },
  1305. 'click #cancelLeaveBoardTeamBtn'(){
  1306. Popup.close();
  1307. },
  1308. },
  1309. ];
  1310. },
  1311. }).register('removeBoardTeamPopup');
  1312. Template.removeBoardTeamPopup.helpers({
  1313. team() {
  1314. return Team.findOne(this.teamId);
  1315. },
  1316. });
  1317. Template.changePermissionsPopup.events({
  1318. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  1319. event,
  1320. ) {
  1321. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1322. const memberId = this.userId;
  1323. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  1324. const isCommentOnly = $(event.currentTarget).hasClass(
  1325. 'js-set-comment-only',
  1326. );
  1327. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  1328. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  1329. currentBoard.setMemberPermission(
  1330. memberId,
  1331. isAdmin,
  1332. isNoComments,
  1333. isCommentOnly,
  1334. isWorker,
  1335. );
  1336. Popup.back(1);
  1337. },
  1338. });
  1339. Template.changePermissionsPopup.helpers({
  1340. isAdmin() {
  1341. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1342. return currentBoard.hasAdmin(this.userId);
  1343. },
  1344. isNormal() {
  1345. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1346. return (
  1347. !currentBoard.hasAdmin(this.userId) &&
  1348. !currentBoard.hasNoComments(this.userId) &&
  1349. !currentBoard.hasCommentOnly(this.userId) &&
  1350. !currentBoard.hasWorker(this.userId)
  1351. );
  1352. },
  1353. isNoComments() {
  1354. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1355. return (
  1356. !currentBoard.hasAdmin(this.userId) &&
  1357. currentBoard.hasNoComments(this.userId)
  1358. );
  1359. },
  1360. isCommentOnly() {
  1361. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1362. return (
  1363. !currentBoard.hasAdmin(this.userId) &&
  1364. currentBoard.hasCommentOnly(this.userId)
  1365. );
  1366. },
  1367. isWorker() {
  1368. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1369. return (
  1370. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  1371. );
  1372. },
  1373. isLastAdmin() {
  1374. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1375. return (
  1376. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1377. );
  1378. },
  1379. });