sidebar.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  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. BlazeComponent.extendComponent({
  264. onCreated() {
  265. this.error = new ReactiveVar('');
  266. this.loading = new ReactiveVar(false);
  267. this.findOrgsOptions = new ReactiveVar({});
  268. this.findTeamsOptions = new ReactiveVar({});
  269. this.page = new ReactiveVar(1);
  270. this.teamPage = new ReactiveVar(1);
  271. this.autorun(() => {
  272. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  273. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  274. });
  275. this.autorun(() => {
  276. const limitTeams = this.teamPage.get() * Number.MAX_SAFE_INTEGER;
  277. this.subscribe('team', this.findTeamsOptions.get(), limitTeams, () => {});
  278. });
  279. },
  280. onRendered() {
  281. this.setLoading(false);
  282. },
  283. setError(error) {
  284. this.error.set(error);
  285. },
  286. setLoading(w) {
  287. this.loading.set(w);
  288. },
  289. isLoading() {
  290. return this.loading.get();
  291. },
  292. }).register('membersWidget');
  293. Template.membersWidget.helpers({
  294. isInvited() {
  295. const user = Meteor.user();
  296. return user && user.isInvitedTo(Session.get('currentBoard'));
  297. },
  298. isWorker() {
  299. const user = Meteor.user();
  300. if (user) {
  301. return Meteor.call(Boards.hasWorker(user.memberId));
  302. } else {
  303. return false;
  304. }
  305. },
  306. isBoardAdmin() {
  307. return Meteor.user().isBoardAdmin();
  308. },
  309. AtLeastOneOrgWasCreated(){
  310. let orgs = Org.find({}, {sort: { createdAt: -1 }});
  311. if(orgs === undefined)
  312. return false;
  313. return orgs.count() > 0;
  314. },
  315. AtLeastOneTeamWasCreated(){
  316. let teams = Team.find({}, {sort: { createdAt: -1 }});
  317. if(teams === undefined)
  318. return false;
  319. return teams.count() > 0;
  320. },
  321. });
  322. Template.membersWidget.events({
  323. 'click .js-member': Popup.open('member'),
  324. 'click .js-open-board-menu': Popup.open('boardMenu'),
  325. 'click .js-manage-board-members': Popup.open('addMember'),
  326. 'click .js-manage-board-addOrg': Popup.open('addBoardOrg'),
  327. 'click .js-manage-board-addTeam': Popup.open('addBoardTeam'),
  328. 'click .js-import': Popup.open('boardImportBoard'),
  329. submit: this.onSubmit,
  330. 'click .js-import-board': Popup.open('chooseBoardSource'),
  331. 'click .js-open-archived-board'() {
  332. Modal.open('archivedBoards');
  333. },
  334. 'click .sandstorm-powerbox-request-identity'() {
  335. window.sandstormRequestIdentity();
  336. },
  337. 'click .js-member-invite-accept'() {
  338. const boardId = Session.get('currentBoard');
  339. Meteor.user().removeInvite(boardId);
  340. },
  341. 'click .js-member-invite-decline'() {
  342. const boardId = Session.get('currentBoard');
  343. Meteor.call('quitBoard', boardId, (err, ret) => {
  344. if (!err && ret) {
  345. Meteor.user().removeInvite(boardId);
  346. FlowRouter.go('home');
  347. }
  348. });
  349. },
  350. });
  351. BlazeComponent.extendComponent({
  352. boardId() {
  353. return Session.get('currentBoard') || Integrations.Const.GLOBAL_WEBHOOK_ID;
  354. },
  355. integrations() {
  356. const boardId = this.boardId();
  357. return Integrations.find({ boardId: `${boardId}` }).fetch();
  358. },
  359. types() {
  360. return Integrations.Const.WEBHOOK_TYPES;
  361. },
  362. integration(cond) {
  363. const boardId = this.boardId();
  364. const condition = { boardId, ...cond };
  365. for (const k in condition) {
  366. if (!condition[k]) delete condition[k];
  367. }
  368. return Integrations.findOne(condition);
  369. },
  370. onCreated() {
  371. this.disabled = new ReactiveVar(false);
  372. },
  373. events() {
  374. return [
  375. {
  376. 'click a.flex'(evt) {
  377. this.disabled.set(!this.disabled.get());
  378. $(evt.target).toggleClass(CKCLS, this.disabled.get());
  379. },
  380. submit(evt) {
  381. evt.preventDefault();
  382. const url = evt.target.url.value;
  383. const boardId = this.boardId();
  384. let id = null;
  385. let integration = null;
  386. const title = evt.target.title.value;
  387. const token = evt.target.token.value;
  388. const type = evt.target.type.value;
  389. const enabled = !this.disabled.get();
  390. let remove = false;
  391. const values = {
  392. url,
  393. type,
  394. token,
  395. title,
  396. enabled,
  397. };
  398. if (evt.target.id) {
  399. id = evt.target.id.value;
  400. integration = this.integration({ _id: id });
  401. remove = !url;
  402. } else if (url) {
  403. integration = this.integration({ url, token });
  404. }
  405. if (remove) {
  406. Integrations.remove(integration._id);
  407. } else if (integration && integration._id) {
  408. Integrations.update(integration._id, {
  409. $set: values,
  410. });
  411. } else if (url) {
  412. Integrations.insert({
  413. ...values,
  414. userId: Meteor.userId(),
  415. enabled: true,
  416. boardId,
  417. activities: ['all'],
  418. });
  419. }
  420. Popup.close();
  421. },
  422. },
  423. ];
  424. },
  425. }).register('outgoingWebhooksPopup');
  426. BlazeComponent.extendComponent({
  427. template() {
  428. return 'chooseBoardSource';
  429. },
  430. }).register('chooseBoardSourcePopup');
  431. BlazeComponent.extendComponent({
  432. template() {
  433. return 'exportBoard';
  434. },
  435. withApi() {
  436. return Template.instance().apiEnabled.get();
  437. },
  438. exportUrl() {
  439. const params = {
  440. boardId: Session.get('currentBoard'),
  441. };
  442. const queryParams = {
  443. authToken: Accounts._storedLoginToken(),
  444. };
  445. return FlowRouter.path('/api/boards/:boardId/export', params, queryParams);
  446. },
  447. exportUrlExcel() {
  448. const params = {
  449. boardId: Session.get('currentBoard'),
  450. };
  451. const queryParams = {
  452. authToken: Accounts._storedLoginToken(),
  453. };
  454. return FlowRouter.path(
  455. '/api/boards/:boardId/exportExcel',
  456. params,
  457. queryParams,
  458. );
  459. },
  460. exportFilenameExcel() {
  461. const boardId = Session.get('currentBoard');
  462. return `export-board-excel-${boardId}.xlsx`;
  463. },
  464. exportCsvUrl() {
  465. const params = {
  466. boardId: Session.get('currentBoard'),
  467. };
  468. const queryParams = {
  469. authToken: Accounts._storedLoginToken(),
  470. };
  471. return FlowRouter.path(
  472. '/api/boards/:boardId/export/csv',
  473. params,
  474. queryParams,
  475. );
  476. },
  477. exportTsvUrl() {
  478. const params = {
  479. boardId: Session.get('currentBoard'),
  480. };
  481. const queryParams = {
  482. authToken: Accounts._storedLoginToken(),
  483. delimiter: '\t',
  484. };
  485. return FlowRouter.path(
  486. '/api/boards/:boardId/export/csv',
  487. params,
  488. queryParams,
  489. );
  490. },
  491. exportJsonFilename() {
  492. const boardId = Session.get('currentBoard');
  493. return `export-board-${boardId}.json`;
  494. },
  495. exportCsvFilename() {
  496. const boardId = Session.get('currentBoard');
  497. return `export-board-${boardId}.csv`;
  498. },
  499. exportTsvFilename() {
  500. const boardId = Session.get('currentBoard');
  501. return `export-board-${boardId}.tsv`;
  502. },
  503. }).register('exportBoardPopup');
  504. Template.exportBoard.events({
  505. 'click .html-export-board': async event => {
  506. event.preventDefault();
  507. await ExportHtml(Popup)();
  508. },
  509. });
  510. Template.labelsWidget.events({
  511. 'click .js-label': Popup.open('editLabel'),
  512. 'click .js-add-label': Popup.open('createLabel'),
  513. });
  514. Template.labelsWidget.helpers({
  515. isBoardAdmin() {
  516. return Meteor.user().isBoardAdmin();
  517. },
  518. });
  519. // Board members can assign people or labels by drag-dropping elements from the
  520. // sidebar to the cards on the board. In order to re-initialize the jquery-ui
  521. // plugin any time a draggable member or label is modified or removed we use a
  522. // autorun function and register a dependency on the both members and labels
  523. // fields of the current board document.
  524. function draggableMembersLabelsWidgets() {
  525. this.autorun(() => {
  526. const currentBoardId = Tracker.nonreactive(() => {
  527. return Session.get('currentBoard');
  528. });
  529. Boards.findOne(currentBoardId, {
  530. fields: {
  531. members: 1,
  532. labels: 1,
  533. },
  534. });
  535. Tracker.afterFlush(() => {
  536. const $draggables = this.$('.js-member,.js-label');
  537. $draggables.draggable({
  538. appendTo: 'body',
  539. helper: 'clone',
  540. revert: 'invalid',
  541. revertDuration: 150,
  542. snap: false,
  543. snapMode: 'both',
  544. start() {
  545. EscapeActions.executeUpTo('popup-back');
  546. },
  547. });
  548. function userIsMember() {
  549. return Meteor.user() && Meteor.user().isBoardMember();
  550. }
  551. this.autorun(() => {
  552. $draggables.draggable('option', 'disabled', !userIsMember());
  553. });
  554. });
  555. });
  556. }
  557. Template.membersWidget.onRendered(draggableMembersLabelsWidgets);
  558. Template.labelsWidget.onRendered(draggableMembersLabelsWidgets);
  559. BlazeComponent.extendComponent({
  560. backgroundColors() {
  561. return Boards.simpleSchema()._schema.color.allowedValues;
  562. },
  563. isSelected() {
  564. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  565. return currentBoard.color === this.currentData().toString();
  566. },
  567. events() {
  568. return [
  569. {
  570. 'click .js-select-background'(evt) {
  571. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  572. const newColor = this.currentData().toString();
  573. currentBoard.setColor(newColor);
  574. evt.preventDefault();
  575. },
  576. },
  577. ];
  578. },
  579. }).register('boardChangeColorPopup');
  580. BlazeComponent.extendComponent({
  581. onCreated() {
  582. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  583. },
  584. allowsSubtasks() {
  585. return this.currentBoard.allowsSubtasks;
  586. },
  587. allowsReceivedDate() {
  588. return this.currentBoard.allowsReceivedDate;
  589. },
  590. isBoardSelected() {
  591. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  592. },
  593. isNullBoardSelected() {
  594. return (
  595. this.currentBoard.subtasksDefaultBoardId === null ||
  596. this.currentBoard.subtasksDefaultBoardId === undefined
  597. );
  598. },
  599. boards() {
  600. return Boards.find(
  601. {
  602. archived: false,
  603. 'members.userId': Meteor.userId(),
  604. },
  605. {
  606. sort: { sort: 1 /* boards default sorting */ },
  607. },
  608. );
  609. },
  610. lists() {
  611. return Lists.find(
  612. {
  613. boardId: this.currentBoard._id,
  614. archived: false,
  615. },
  616. {
  617. sort: ['title'],
  618. },
  619. );
  620. },
  621. hasLists() {
  622. return this.lists().count() > 0;
  623. },
  624. isListSelected() {
  625. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  626. },
  627. presentParentTask() {
  628. let result = this.currentBoard.presentParentTask;
  629. if (result === null || result === undefined) {
  630. result = 'no-parent';
  631. }
  632. return result;
  633. },
  634. events() {
  635. return [
  636. {
  637. 'click .js-field-has-subtasks'(evt) {
  638. evt.preventDefault();
  639. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  640. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  641. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  642. CKCLS,
  643. this.currentBoard.allowsSubtasks,
  644. );
  645. $('.js-field-has-subtasks').toggleClass(
  646. CKCLS,
  647. this.currentBoard.allowsSubtasks,
  648. );
  649. $('.js-field-deposit-board').prop(
  650. 'disabled',
  651. !this.currentBoard.allowsSubtasks,
  652. );
  653. },
  654. 'change .js-field-deposit-board'(evt) {
  655. let value = evt.target.value;
  656. if (value === 'null') {
  657. value = null;
  658. }
  659. this.currentBoard.setSubtasksDefaultBoardId(value);
  660. evt.preventDefault();
  661. },
  662. 'change .js-field-deposit-list'(evt) {
  663. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  664. evt.preventDefault();
  665. },
  666. 'click .js-field-show-parent-in-minicard'(evt) {
  667. const value =
  668. evt.target.id ||
  669. $(evt.target).parent()[0].id ||
  670. $(evt.target)
  671. .parent()[0]
  672. .parent()[0].id;
  673. const options = [
  674. 'prefix-with-full-path',
  675. 'prefix-with-parent',
  676. 'subtext-with-full-path',
  677. 'subtext-with-parent',
  678. 'no-parent',
  679. ];
  680. options.forEach(function(element) {
  681. if (element !== value) {
  682. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  683. $(`#${element}`).toggleClass(CKCLS, false);
  684. }
  685. });
  686. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  687. $(`#${value}`).toggleClass(CKCLS, true);
  688. this.currentBoard.setPresentParentTask(value);
  689. evt.preventDefault();
  690. },
  691. },
  692. ];
  693. },
  694. }).register('boardSubtaskSettingsPopup');
  695. BlazeComponent.extendComponent({
  696. onCreated() {
  697. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  698. },
  699. allowsReceivedDate() {
  700. return this.currentBoard.allowsReceivedDate;
  701. },
  702. allowsStartDate() {
  703. return this.currentBoard.allowsStartDate;
  704. },
  705. allowsDueDate() {
  706. return this.currentBoard.allowsDueDate;
  707. },
  708. allowsEndDate() {
  709. return this.currentBoard.allowsEndDate;
  710. },
  711. allowsSubtasks() {
  712. return this.currentBoard.allowsSubtasks;
  713. },
  714. allowsCreator() {
  715. return (
  716. this.currentBoard.allowsCreator === null ||
  717. this.currentBoard.allowsCreator === undefined ||
  718. this.currentBoard.allowsCreator
  719. );
  720. },
  721. allowsMembers() {
  722. return this.currentBoard.allowsMembers;
  723. },
  724. allowsAssignee() {
  725. return this.currentBoard.allowsAssignee;
  726. },
  727. allowsAssignedBy() {
  728. return this.currentBoard.allowsAssignedBy;
  729. },
  730. allowsRequestedBy() {
  731. return this.currentBoard.allowsRequestedBy;
  732. },
  733. allowsCardSortingByNumber() {
  734. return this.currentBoard.allowsCardSortingByNumber;
  735. },
  736. allowsLabels() {
  737. return this.currentBoard.allowsLabels;
  738. },
  739. allowsChecklists() {
  740. return this.currentBoard.allowsChecklists;
  741. },
  742. allowsAttachments() {
  743. return this.currentBoard.allowsAttachments;
  744. },
  745. allowsComments() {
  746. return this.currentBoard.allowsComments;
  747. },
  748. allowsCardNumber() {
  749. return this.currentBoard.allowsCardNumber;
  750. },
  751. allowsDescriptionTitle() {
  752. return this.currentBoard.allowsDescriptionTitle;
  753. },
  754. allowsDescriptionText() {
  755. return this.currentBoard.allowsDescriptionText;
  756. },
  757. isBoardSelected() {
  758. return this.currentBoard.dateSettingsDefaultBoardID;
  759. },
  760. isNullBoardSelected() {
  761. return (
  762. this.currentBoard.dateSettingsDefaultBoardId === null ||
  763. this.currentBoard.dateSettingsDefaultBoardId === undefined
  764. );
  765. },
  766. boards() {
  767. return Boards.find(
  768. {
  769. archived: false,
  770. 'members.userId': Meteor.userId(),
  771. },
  772. {
  773. sort: { sort: 1 /* boards default sorting */ },
  774. },
  775. );
  776. },
  777. lists() {
  778. return Lists.find(
  779. {
  780. boardId: this.currentBoard._id,
  781. archived: false,
  782. },
  783. {
  784. sort: ['title'],
  785. },
  786. );
  787. },
  788. hasLists() {
  789. return this.lists().count() > 0;
  790. },
  791. isListSelected() {
  792. return (
  793. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  794. );
  795. },
  796. events() {
  797. return [
  798. {
  799. 'click .js-field-has-receiveddate'(evt) {
  800. evt.preventDefault();
  801. this.currentBoard.allowsReceivedDate = !this.currentBoard
  802. .allowsReceivedDate;
  803. this.currentBoard.setAllowsReceivedDate(
  804. this.currentBoard.allowsReceivedDate,
  805. );
  806. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  807. CKCLS,
  808. this.currentBoard.allowsReceivedDate,
  809. );
  810. $('.js-field-has-receiveddate').toggleClass(
  811. CKCLS,
  812. this.currentBoard.allowsReceivedDate,
  813. );
  814. },
  815. 'click .js-field-has-startdate'(evt) {
  816. evt.preventDefault();
  817. this.currentBoard.allowsStartDate = !this.currentBoard
  818. .allowsStartDate;
  819. this.currentBoard.setAllowsStartDate(
  820. this.currentBoard.allowsStartDate,
  821. );
  822. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  823. CKCLS,
  824. this.currentBoard.allowsStartDate,
  825. );
  826. $('.js-field-has-startdate').toggleClass(
  827. CKCLS,
  828. this.currentBoard.allowsStartDate,
  829. );
  830. },
  831. 'click .js-field-has-enddate'(evt) {
  832. evt.preventDefault();
  833. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  834. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  835. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  836. CKCLS,
  837. this.currentBoard.allowsEndDate,
  838. );
  839. $('.js-field-has-enddate').toggleClass(
  840. CKCLS,
  841. this.currentBoard.allowsEndDate,
  842. );
  843. },
  844. 'click .js-field-has-duedate'(evt) {
  845. evt.preventDefault();
  846. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  847. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  848. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  849. CKCLS,
  850. this.currentBoard.allowsDueDate,
  851. );
  852. $('.js-field-has-duedate').toggleClass(
  853. CKCLS,
  854. this.currentBoard.allowsDueDate,
  855. );
  856. },
  857. 'click .js-field-has-subtasks'(evt) {
  858. evt.preventDefault();
  859. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  860. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  861. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  862. CKCLS,
  863. this.currentBoard.allowsSubtasks,
  864. );
  865. $('.js-field-has-subtasks').toggleClass(
  866. CKCLS,
  867. this.currentBoard.allowsSubtasks,
  868. );
  869. },
  870. 'click .js-field-has-creator'(evt) {
  871. evt.preventDefault();
  872. this.currentBoard.allowsCreator = !this.currentBoard.allowsCreator;
  873. this.currentBoard.setAllowsCreator(this.currentBoard.allowsCreator);
  874. $(`.js-field-has-creator ${MCB}`).toggleClass(
  875. CKCLS,
  876. this.currentBoard.allowsCreator,
  877. );
  878. $('.js-field-has-creator').toggleClass(
  879. CKCLS,
  880. this.currentBoard.allowsCreator,
  881. );
  882. },
  883. 'click .js-field-has-members'(evt) {
  884. evt.preventDefault();
  885. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  886. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  887. $(`.js-field-has-members ${MCB}`).toggleClass(
  888. CKCLS,
  889. this.currentBoard.allowsMembers,
  890. );
  891. $('.js-field-has-members').toggleClass(
  892. CKCLS,
  893. this.currentBoard.allowsMembers,
  894. );
  895. },
  896. 'click .js-field-has-assignee'(evt) {
  897. evt.preventDefault();
  898. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  899. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  900. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  901. CKCLS,
  902. this.currentBoard.allowsAssignee,
  903. );
  904. $('.js-field-has-assignee').toggleClass(
  905. CKCLS,
  906. this.currentBoard.allowsAssignee,
  907. );
  908. },
  909. 'click .js-field-has-assigned-by'(evt) {
  910. evt.preventDefault();
  911. this.currentBoard.allowsAssignedBy = !this.currentBoard
  912. .allowsAssignedBy;
  913. this.currentBoard.setAllowsAssignedBy(
  914. this.currentBoard.allowsAssignedBy,
  915. );
  916. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  917. CKCLS,
  918. this.currentBoard.allowsAssignedBy,
  919. );
  920. $('.js-field-has-assigned-by').toggleClass(
  921. CKCLS,
  922. this.currentBoard.allowsAssignedBy,
  923. );
  924. },
  925. 'click .js-field-has-requested-by'(evt) {
  926. evt.preventDefault();
  927. this.currentBoard.allowsRequestedBy = !this.currentBoard
  928. .allowsRequestedBy;
  929. this.currentBoard.setAllowsRequestedBy(
  930. this.currentBoard.allowsRequestedBy,
  931. );
  932. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  933. CKCLS,
  934. this.currentBoard.allowsRequestedBy,
  935. );
  936. $('.js-field-has-requested-by').toggleClass(
  937. CKCLS,
  938. this.currentBoard.allowsRequestedBy,
  939. );
  940. },
  941. 'click .js-field-has-card-sorting-by-number'(evt) {
  942. evt.preventDefault();
  943. this.currentBoard.allowsCardSortingByNumber = !this.currentBoard
  944. .allowsCardSortingByNumber;
  945. this.currentBoard.setAllowsCardSortingByNumber(
  946. this.currentBoard.allowsCardSortingByNumber,
  947. );
  948. $(`.js-field-has-card-sorting-by-number ${MCB}`).toggleClass(
  949. CKCLS,
  950. this.currentBoard.allowsCardSortingByNumber,
  951. );
  952. $('.js-field-has-card-sorting-by-number').toggleClass(
  953. CKCLS,
  954. this.currentBoard.allowsCardSortingByNumber,
  955. );
  956. },
  957. 'click .js-field-has-labels'(evt) {
  958. evt.preventDefault();
  959. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  960. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  961. $(`.js-field-has-labels ${MCB}`).toggleClass(
  962. CKCLS,
  963. this.currentBoard.allowsAssignee,
  964. );
  965. $('.js-field-has-labels').toggleClass(
  966. CKCLS,
  967. this.currentBoard.allowsLabels,
  968. );
  969. },
  970. 'click .js-field-has-description-title'(evt) {
  971. evt.preventDefault();
  972. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  973. .allowsDescriptionTitle;
  974. this.currentBoard.setAllowsDescriptionTitle(
  975. this.currentBoard.allowsDescriptionTitle,
  976. );
  977. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  978. CKCLS,
  979. this.currentBoard.allowsDescriptionTitle,
  980. );
  981. $('.js-field-has-description-title').toggleClass(
  982. CKCLS,
  983. this.currentBoard.allowsDescriptionTitle,
  984. );
  985. },
  986. 'click .js-field-has-card-number'(evt) {
  987. evt.preventDefault();
  988. this.currentBoard.allowsCardNumber = !this.currentBoard
  989. .allowsCardNumber;
  990. this.currentBoard.setAllowsCardNumber(
  991. this.currentBoard.allowsCardNumber,
  992. );
  993. $(`.js-field-has-card-number ${MCB}`).toggleClass(
  994. CKCLS,
  995. this.currentBoard.allowsCardNumber,
  996. );
  997. $('.js-field-has-card-number').toggleClass(
  998. CKCLS,
  999. this.currentBoard.allowsCardNumber,
  1000. );
  1001. },
  1002. 'click .js-field-has-description-text'(evt) {
  1003. evt.preventDefault();
  1004. this.currentBoard.allowsDescriptionText = !this.currentBoard
  1005. .allowsDescriptionText;
  1006. this.currentBoard.setAllowsDescriptionText(
  1007. this.currentBoard.allowsDescriptionText,
  1008. );
  1009. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  1010. CKCLS,
  1011. this.currentBoard.allowsDescriptionText,
  1012. );
  1013. $('.js-field-has-description-text').toggleClass(
  1014. CKCLS,
  1015. this.currentBoard.allowsDescriptionText,
  1016. );
  1017. },
  1018. 'click .js-field-has-checklists'(evt) {
  1019. evt.preventDefault();
  1020. this.currentBoard.allowsChecklists = !this.currentBoard
  1021. .allowsChecklists;
  1022. this.currentBoard.setAllowsChecklists(
  1023. this.currentBoard.allowsChecklists,
  1024. );
  1025. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  1026. CKCLS,
  1027. this.currentBoard.allowsChecklists,
  1028. );
  1029. $('.js-field-has-checklists').toggleClass(
  1030. CKCLS,
  1031. this.currentBoard.allowsChecklists,
  1032. );
  1033. },
  1034. 'click .js-field-has-attachments'(evt) {
  1035. evt.preventDefault();
  1036. this.currentBoard.allowsAttachments = !this.currentBoard
  1037. .allowsAttachments;
  1038. this.currentBoard.setAllowsAttachments(
  1039. this.currentBoard.allowsAttachments,
  1040. );
  1041. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  1042. CKCLS,
  1043. this.currentBoard.allowsAttachments,
  1044. );
  1045. $('.js-field-has-attachments').toggleClass(
  1046. CKCLS,
  1047. this.currentBoard.allowsAttachments,
  1048. );
  1049. },
  1050. 'click .js-field-has-comments'(evt) {
  1051. evt.preventDefault();
  1052. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  1053. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  1054. $(`.js-field-has-comments ${MCB}`).toggleClass(
  1055. CKCLS,
  1056. this.currentBoard.allowsComments,
  1057. );
  1058. $('.js-field-has-comments').toggleClass(
  1059. CKCLS,
  1060. this.currentBoard.allowsComments,
  1061. );
  1062. },
  1063. 'click .js-field-has-activities'(evt) {
  1064. evt.preventDefault();
  1065. this.currentBoard.allowsActivities = !this.currentBoard
  1066. .allowsActivities;
  1067. this.currentBoard.setAllowsActivities(
  1068. this.currentBoard.allowsActivities,
  1069. );
  1070. $(`.js-field-has-activities ${MCB}`).toggleClass(
  1071. CKCLS,
  1072. this.currentBoard.allowsActivities,
  1073. );
  1074. $('.js-field-has-activities').toggleClass(
  1075. CKCLS,
  1076. this.currentBoard.allowsActivities,
  1077. );
  1078. },
  1079. },
  1080. ];
  1081. },
  1082. }).register('boardCardSettingsPopup');
  1083. BlazeComponent.extendComponent({
  1084. onCreated() {
  1085. this.error = new ReactiveVar('');
  1086. this.loading = new ReactiveVar(false);
  1087. },
  1088. onRendered() {
  1089. this.find('.js-search-member input').focus();
  1090. this.setLoading(false);
  1091. },
  1092. isBoardMember() {
  1093. const userId = this.currentData()._id;
  1094. const user = Users.findOne(userId);
  1095. return user && user.isBoardMember();
  1096. },
  1097. isValidEmail(email) {
  1098. return SimpleSchema.RegEx.Email.test(email);
  1099. },
  1100. setError(error) {
  1101. this.error.set(error);
  1102. },
  1103. setLoading(w) {
  1104. this.loading.set(w);
  1105. },
  1106. isLoading() {
  1107. return this.loading.get();
  1108. },
  1109. inviteUser(idNameEmail) {
  1110. const boardId = Session.get('currentBoard');
  1111. this.setLoading(true);
  1112. const self = this;
  1113. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  1114. self.setLoading(false);
  1115. if (err) self.setError(err.error);
  1116. else if (ret.email) self.setError('email-sent');
  1117. else Popup.close();
  1118. });
  1119. },
  1120. events() {
  1121. return [
  1122. {
  1123. 'keyup input'() {
  1124. this.setError('');
  1125. },
  1126. 'click .js-select-member'() {
  1127. const userId = this.currentData()._id;
  1128. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1129. if (!currentBoard.hasMember(userId)) {
  1130. this.inviteUser(userId);
  1131. }
  1132. },
  1133. 'click .js-email-invite'() {
  1134. const idNameEmail = $('.js-search-member input').val();
  1135. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  1136. this.inviteUser(idNameEmail);
  1137. } else this.setError('email-invalid');
  1138. },
  1139. },
  1140. ];
  1141. },
  1142. }).register('addMemberPopup');
  1143. BlazeComponent.extendComponent({
  1144. onCreated() {
  1145. this.error = new ReactiveVar('');
  1146. this.loading = new ReactiveVar(false);
  1147. this.findOrgsOptions = new ReactiveVar({});
  1148. this.page = new ReactiveVar(1);
  1149. this.autorun(() => {
  1150. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1151. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1152. });
  1153. },
  1154. onRendered() {
  1155. this.setLoading(false);
  1156. },
  1157. setError(error) {
  1158. this.error.set(error);
  1159. },
  1160. setLoading(w) {
  1161. this.loading.set(w);
  1162. },
  1163. isLoading() {
  1164. return this.loading.get();
  1165. },
  1166. events() {
  1167. return [
  1168. {
  1169. 'keyup input'() {
  1170. this.setError('');
  1171. },
  1172. 'change #jsBoardOrgs'() {
  1173. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1174. let selectElt = document.getElementById("jsBoardOrgs");
  1175. let selectedOrgId = selectElt.options[selectElt.selectedIndex].value;
  1176. let selectedOrgDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1177. let boardOrganizations = [];
  1178. if(currentBoard.orgs !== undefined){
  1179. for(let i = 0; i < currentBoard.orgs.length; i++){
  1180. boardOrganizations.push(currentBoard.orgs[i]);
  1181. }
  1182. }
  1183. if(!boardOrganizations.some((org) => org.orgDisplayName == selectedOrgDisplayName)){
  1184. boardOrganizations.push({
  1185. "orgId": selectedOrgId,
  1186. "orgDisplayName": selectedOrgDisplayName,
  1187. "isActive" : true,
  1188. })
  1189. if (selectedOrgId != "-1") {
  1190. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1191. }
  1192. }
  1193. Popup.close();
  1194. },
  1195. },
  1196. ];
  1197. },
  1198. }).register('addBoardOrgPopup');
  1199. Template.addBoardOrgPopup.helpers({
  1200. orgsDatas() {
  1201. // return Org.find({}, {sort: { createdAt: -1 }});
  1202. let orgs = Org.find({}, {sort: { createdAt: -1 }});
  1203. return orgs;
  1204. },
  1205. });
  1206. BlazeComponent.extendComponent({
  1207. onCreated() {
  1208. this.error = new ReactiveVar('');
  1209. this.loading = new ReactiveVar(false);
  1210. this.findOrgsOptions = new ReactiveVar({});
  1211. this.page = new ReactiveVar(1);
  1212. this.autorun(() => {
  1213. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1214. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1215. });
  1216. },
  1217. onRendered() {
  1218. this.setLoading(false);
  1219. },
  1220. setError(error) {
  1221. this.error.set(error);
  1222. },
  1223. setLoading(w) {
  1224. this.loading.set(w);
  1225. },
  1226. isLoading() {
  1227. return this.loading.get();
  1228. },
  1229. events() {
  1230. return [
  1231. {
  1232. 'keyup input'() {
  1233. this.setError('');
  1234. },
  1235. 'click #leaveBoardBtn'(){
  1236. let stringOrgId = document.getElementById('hideOrgId').value;
  1237. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1238. let boardOrganizations = [];
  1239. if(currentBoard.orgs !== undefined){
  1240. for(let i = 0; i < currentBoard.orgs.length; i++){
  1241. if(currentBoard.orgs[i].orgId != stringOrgId){
  1242. boardOrganizations.push(currentBoard.orgs[i]);
  1243. }
  1244. }
  1245. }
  1246. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1247. Popup.close();
  1248. },
  1249. 'click #cancelLeaveBoardBtn'(){
  1250. Popup.close();
  1251. },
  1252. },
  1253. ];
  1254. },
  1255. }).register('removeBoardOrgPopup');
  1256. Template.removeBoardOrgPopup.helpers({
  1257. org() {
  1258. return Org.findOne(this.orgId);
  1259. },
  1260. });
  1261. BlazeComponent.extendComponent({
  1262. onCreated() {
  1263. this.error = new ReactiveVar('');
  1264. this.loading = new ReactiveVar(false);
  1265. this.findOrgsOptions = new ReactiveVar({});
  1266. this.page = new ReactiveVar(1);
  1267. this.autorun(() => {
  1268. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1269. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1270. });
  1271. },
  1272. onRendered() {
  1273. this.setLoading(false);
  1274. },
  1275. setError(error) {
  1276. this.error.set(error);
  1277. },
  1278. setLoading(w) {
  1279. this.loading.set(w);
  1280. },
  1281. isLoading() {
  1282. return this.loading.get();
  1283. },
  1284. events() {
  1285. return [
  1286. {
  1287. 'keyup input'() {
  1288. this.setError('');
  1289. },
  1290. 'change #jsBoardTeams'() {
  1291. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1292. let selectElt = document.getElementById("jsBoardTeams");
  1293. let selectedTeamId = selectElt.options[selectElt.selectedIndex].value;
  1294. let selectedTeamDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1295. let boardTeams = [];
  1296. if(currentBoard.teams !== undefined){
  1297. for(let i = 0; i < currentBoard.teams.length; i++){
  1298. boardTeams.push(currentBoard.teams[i]);
  1299. }
  1300. }
  1301. if(!boardTeams.some((team) => team.teamDisplayName == selectedTeamDisplayName)){
  1302. boardTeams.push({
  1303. "teamId": selectedTeamId,
  1304. "teamDisplayName": selectedTeamDisplayName,
  1305. "isActive" : true,
  1306. })
  1307. if (selectedTeamId != "-1") {
  1308. Meteor.call('setBoardTeams', boardTeams, currentBoard._id);
  1309. }
  1310. }
  1311. Popup.close();
  1312. },
  1313. },
  1314. ];
  1315. },
  1316. }).register('addBoardTeamPopup');
  1317. Template.addBoardTeamPopup.helpers({
  1318. teamsDatas() {
  1319. let teams = Team.find({}, {sort: { createdAt: -1 }});
  1320. return teams;
  1321. },
  1322. });
  1323. BlazeComponent.extendComponent({
  1324. onCreated() {
  1325. this.error = new ReactiveVar('');
  1326. this.loading = new ReactiveVar(false);
  1327. this.findOrgsOptions = new ReactiveVar({});
  1328. this.page = new ReactiveVar(1);
  1329. this.autorun(() => {
  1330. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1331. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1332. });
  1333. },
  1334. onRendered() {
  1335. this.setLoading(false);
  1336. },
  1337. setError(error) {
  1338. this.error.set(error);
  1339. },
  1340. setLoading(w) {
  1341. this.loading.set(w);
  1342. },
  1343. isLoading() {
  1344. return this.loading.get();
  1345. },
  1346. events() {
  1347. return [
  1348. {
  1349. 'keyup input'() {
  1350. this.setError('');
  1351. },
  1352. 'click #leaveBoardTeamBtn'(){
  1353. let stringTeamId = document.getElementById('hideTeamId').value;
  1354. let currentBoard = Boards.findOne(Session.get('currentBoard'));
  1355. let boardTeams = [];
  1356. if(currentBoard.teams !== undefined){
  1357. for(let i = 0; i < currentBoard.teams.length; i++){
  1358. if(currentBoard.teams[i].teamId != stringTeamId){
  1359. boardTeams.push(currentBoard.teams[i]);
  1360. }
  1361. }
  1362. }
  1363. Meteor.call('setBoardTeams', boardTeams, currentBoard._id);
  1364. Popup.close();
  1365. },
  1366. 'click #cancelLeaveBoardTeamBtn'(){
  1367. Popup.close();
  1368. },
  1369. },
  1370. ];
  1371. },
  1372. }).register('removeBoardTeamPopup');
  1373. Template.removeBoardTeamPopup.helpers({
  1374. team() {
  1375. return Team.findOne(this.teamId);
  1376. },
  1377. });
  1378. Template.changePermissionsPopup.events({
  1379. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  1380. event,
  1381. ) {
  1382. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1383. const memberId = this.userId;
  1384. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  1385. const isCommentOnly = $(event.currentTarget).hasClass(
  1386. 'js-set-comment-only',
  1387. );
  1388. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  1389. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  1390. currentBoard.setMemberPermission(
  1391. memberId,
  1392. isAdmin,
  1393. isNoComments,
  1394. isCommentOnly,
  1395. isWorker,
  1396. );
  1397. Popup.back(1);
  1398. },
  1399. });
  1400. Template.changePermissionsPopup.helpers({
  1401. isAdmin() {
  1402. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1403. return currentBoard.hasAdmin(this.userId);
  1404. },
  1405. isNormal() {
  1406. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1407. return (
  1408. !currentBoard.hasAdmin(this.userId) &&
  1409. !currentBoard.hasNoComments(this.userId) &&
  1410. !currentBoard.hasCommentOnly(this.userId) &&
  1411. !currentBoard.hasWorker(this.userId)
  1412. );
  1413. },
  1414. isNoComments() {
  1415. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1416. return (
  1417. !currentBoard.hasAdmin(this.userId) &&
  1418. currentBoard.hasNoComments(this.userId)
  1419. );
  1420. },
  1421. isCommentOnly() {
  1422. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1423. return (
  1424. !currentBoard.hasAdmin(this.userId) &&
  1425. currentBoard.hasCommentOnly(this.userId)
  1426. );
  1427. },
  1428. isWorker() {
  1429. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1430. return (
  1431. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  1432. );
  1433. },
  1434. isLastAdmin() {
  1435. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  1436. return (
  1437. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1438. );
  1439. },
  1440. });