sidebar.js 56 KB

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