sidebar.js 54 KB

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