sidebar.js 54 KB

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