sidebar.js 54 KB

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