sidebar.js 54 KB

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