sidebar.js 54 KB

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