sidebar.js 55 KB

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