sidebar.js 54 KB

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