sidebar.js 54 KB

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