sidebar.js 53 KB

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