sidebar.js 55 KB

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