sidebar.js 56 KB

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