sidebar.js 54 KB

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