sidebar.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  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 = Meteor.user();
  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 = Meteor.user();
  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 Users.findOne(this.userId);
  148. },
  149. isBoardAdmin() {
  150. return Meteor.user().isBoardAdmin();
  151. },
  152. memberType() {
  153. const type = Users.findOne(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 Users.findOne(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 Meteor.user().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. Cards.find({ boardId, members: memberId }).forEach(card => {
  252. card.unassignMember(memberId);
  253. });
  254. Cards.find({ 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 Users.findOne(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 = Meteor.user();
  322. return user && user.isInvitedTo(Session.get('currentBoard'));
  323. },
  324. isWorker() {
  325. const user = Meteor.user();
  326. if (user) {
  327. return Meteor.call(Boards.hasWorker(user.memberId));
  328. } else {
  329. return false;
  330. }
  331. },
  332. isBoardAdmin() {
  333. return Meteor.user().isBoardAdmin();
  334. },
  335. AtLeastOneOrgWasCreated(){
  336. let orgs = Org.find({}, {sort: { createdAt: -1 }});
  337. if(orgs === undefined)
  338. return false;
  339. return orgs.count() > 0;
  340. },
  341. AtLeastOneTeamWasCreated(){
  342. let teams = Team.find({}, {sort: { createdAt: -1 }});
  343. if(teams === undefined)
  344. return false;
  345. return teams.count() > 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. Meteor.user().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. Meteor.user().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. return Integrations.find({ boardId: `${boardId}` }).fetch();
  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 Integrations.findOne(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 Meteor.user().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. Boards.findOne(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 Meteor.user() && Meteor.user().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. return Boards.find(
  720. {
  721. archived: false,
  722. 'members.userId': Meteor.userId(),
  723. },
  724. {
  725. sort: { sort: 1 /* boards default sorting */ },
  726. },
  727. );
  728. },
  729. lists() {
  730. return Lists.find(
  731. {
  732. boardId: this.currentBoard._id,
  733. archived: false,
  734. },
  735. {
  736. sort: ['title'],
  737. },
  738. );
  739. },
  740. hasLists() {
  741. return this.lists().count() > 0;
  742. },
  743. isListSelected() {
  744. return this.currentBoard.subtasksDefaultBoardId === this.currentData()._id;
  745. },
  746. presentParentTask() {
  747. let result = this.currentBoard.presentParentTask;
  748. if (result === null || result === undefined) {
  749. result = 'no-parent';
  750. }
  751. return result;
  752. },
  753. events() {
  754. return [
  755. {
  756. 'click .js-field-has-subtasks'(evt) {
  757. evt.preventDefault();
  758. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  759. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  760. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  761. CKCLS,
  762. this.currentBoard.allowsSubtasks,
  763. );
  764. $('.js-field-has-subtasks').toggleClass(
  765. CKCLS,
  766. this.currentBoard.allowsSubtasks,
  767. );
  768. $('.js-field-deposit-board').prop(
  769. 'disabled',
  770. !this.currentBoard.allowsSubtasks,
  771. );
  772. },
  773. 'change .js-field-deposit-board'(evt) {
  774. let value = evt.target.value;
  775. if (value === 'null') {
  776. value = null;
  777. }
  778. this.currentBoard.setSubtasksDefaultBoardId(value);
  779. evt.preventDefault();
  780. },
  781. 'change .js-field-deposit-list'(evt) {
  782. this.currentBoard.setSubtasksDefaultListId(evt.target.value);
  783. evt.preventDefault();
  784. },
  785. 'click .js-field-show-parent-in-minicard'(evt) {
  786. const value =
  787. evt.target.id ||
  788. $(evt.target).parent()[0].id ||
  789. $(evt.target)
  790. .parent()[0]
  791. .parent()[0].id;
  792. const options = [
  793. 'prefix-with-full-path',
  794. 'prefix-with-parent',
  795. 'subtext-with-full-path',
  796. 'subtext-with-parent',
  797. 'no-parent',
  798. ];
  799. options.forEach(function(element) {
  800. if (element !== value) {
  801. $(`#${element} ${MCB}`).toggleClass(CKCLS, false);
  802. $(`#${element}`).toggleClass(CKCLS, false);
  803. }
  804. });
  805. $(`#${value} ${MCB}`).toggleClass(CKCLS, true);
  806. $(`#${value}`).toggleClass(CKCLS, true);
  807. this.currentBoard.setPresentParentTask(value);
  808. evt.preventDefault();
  809. },
  810. },
  811. ];
  812. },
  813. }).register('boardSubtaskSettingsPopup');
  814. BlazeComponent.extendComponent({
  815. onCreated() {
  816. this.currentBoard = Utils.getCurrentBoard();
  817. },
  818. allowsReceivedDate() {
  819. return this.currentBoard.allowsReceivedDate;
  820. },
  821. allowsStartDate() {
  822. return this.currentBoard.allowsStartDate;
  823. },
  824. allowsDueDate() {
  825. return this.currentBoard.allowsDueDate;
  826. },
  827. allowsEndDate() {
  828. return this.currentBoard.allowsEndDate;
  829. },
  830. allowsSubtasks() {
  831. return this.currentBoard.allowsSubtasks;
  832. },
  833. allowsCreator() {
  834. return (
  835. this.currentBoard.allowsCreator === null ||
  836. this.currentBoard.allowsCreator === undefined ||
  837. this.currentBoard.allowsCreator
  838. );
  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. boards() {
  889. return Boards.find(
  890. {
  891. archived: false,
  892. 'members.userId': Meteor.userId(),
  893. },
  894. {
  895. sort: { sort: 1 /* boards default sorting */ },
  896. },
  897. );
  898. },
  899. lists() {
  900. return Lists.find(
  901. {
  902. boardId: this.currentBoard._id,
  903. archived: false,
  904. },
  905. {
  906. sort: ['title'],
  907. },
  908. );
  909. },
  910. hasLists() {
  911. return this.lists().count() > 0;
  912. },
  913. isListSelected() {
  914. return (
  915. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  916. );
  917. },
  918. events() {
  919. return [
  920. {
  921. 'click .js-field-has-receiveddate'(evt) {
  922. evt.preventDefault();
  923. this.currentBoard.allowsReceivedDate = !this.currentBoard
  924. .allowsReceivedDate;
  925. this.currentBoard.setAllowsReceivedDate(
  926. this.currentBoard.allowsReceivedDate,
  927. );
  928. $(`.js-field-has-receiveddate ${MCB}`).toggleClass(
  929. CKCLS,
  930. this.currentBoard.allowsReceivedDate,
  931. );
  932. $('.js-field-has-receiveddate').toggleClass(
  933. CKCLS,
  934. this.currentBoard.allowsReceivedDate,
  935. );
  936. },
  937. 'click .js-field-has-startdate'(evt) {
  938. evt.preventDefault();
  939. this.currentBoard.allowsStartDate = !this.currentBoard
  940. .allowsStartDate;
  941. this.currentBoard.setAllowsStartDate(
  942. this.currentBoard.allowsStartDate,
  943. );
  944. $(`.js-field-has-startdate ${MCB}`).toggleClass(
  945. CKCLS,
  946. this.currentBoard.allowsStartDate,
  947. );
  948. $('.js-field-has-startdate').toggleClass(
  949. CKCLS,
  950. this.currentBoard.allowsStartDate,
  951. );
  952. },
  953. 'click .js-field-has-enddate'(evt) {
  954. evt.preventDefault();
  955. this.currentBoard.allowsEndDate = !this.currentBoard.allowsEndDate;
  956. this.currentBoard.setAllowsEndDate(this.currentBoard.allowsEndDate);
  957. $(`.js-field-has-enddate ${MCB}`).toggleClass(
  958. CKCLS,
  959. this.currentBoard.allowsEndDate,
  960. );
  961. $('.js-field-has-enddate').toggleClass(
  962. CKCLS,
  963. this.currentBoard.allowsEndDate,
  964. );
  965. },
  966. 'click .js-field-has-duedate'(evt) {
  967. evt.preventDefault();
  968. this.currentBoard.allowsDueDate = !this.currentBoard.allowsDueDate;
  969. this.currentBoard.setAllowsDueDate(this.currentBoard.allowsDueDate);
  970. $(`.js-field-has-duedate ${MCB}`).toggleClass(
  971. CKCLS,
  972. this.currentBoard.allowsDueDate,
  973. );
  974. $('.js-field-has-duedate').toggleClass(
  975. CKCLS,
  976. this.currentBoard.allowsDueDate,
  977. );
  978. },
  979. 'click .js-field-has-subtasks'(evt) {
  980. evt.preventDefault();
  981. this.currentBoard.allowsSubtasks = !this.currentBoard.allowsSubtasks;
  982. this.currentBoard.setAllowsSubtasks(this.currentBoard.allowsSubtasks);
  983. $(`.js-field-has-subtasks ${MCB}`).toggleClass(
  984. CKCLS,
  985. this.currentBoard.allowsSubtasks,
  986. );
  987. $('.js-field-has-subtasks').toggleClass(
  988. CKCLS,
  989. this.currentBoard.allowsSubtasks,
  990. );
  991. },
  992. 'click .js-field-has-creator'(evt) {
  993. evt.preventDefault();
  994. this.currentBoard.allowsCreator = !this.currentBoard.allowsCreator;
  995. this.currentBoard.setAllowsCreator(this.currentBoard.allowsCreator);
  996. $(`.js-field-has-creator ${MCB}`).toggleClass(
  997. CKCLS,
  998. this.currentBoard.allowsCreator,
  999. );
  1000. $('.js-field-has-creator').toggleClass(
  1001. CKCLS,
  1002. this.currentBoard.allowsCreator,
  1003. );
  1004. },
  1005. 'click .js-field-has-members'(evt) {
  1006. evt.preventDefault();
  1007. this.currentBoard.allowsMembers = !this.currentBoard.allowsMembers;
  1008. this.currentBoard.setAllowsMembers(this.currentBoard.allowsMembers);
  1009. $(`.js-field-has-members ${MCB}`).toggleClass(
  1010. CKCLS,
  1011. this.currentBoard.allowsMembers,
  1012. );
  1013. $('.js-field-has-members').toggleClass(
  1014. CKCLS,
  1015. this.currentBoard.allowsMembers,
  1016. );
  1017. },
  1018. 'click .js-field-has-assignee'(evt) {
  1019. evt.preventDefault();
  1020. this.currentBoard.allowsAssignee = !this.currentBoard.allowsAssignee;
  1021. this.currentBoard.setAllowsAssignee(this.currentBoard.allowsAssignee);
  1022. $(`.js-field-has-assignee ${MCB}`).toggleClass(
  1023. CKCLS,
  1024. this.currentBoard.allowsAssignee,
  1025. );
  1026. $('.js-field-has-assignee').toggleClass(
  1027. CKCLS,
  1028. this.currentBoard.allowsAssignee,
  1029. );
  1030. },
  1031. 'click .js-field-has-assigned-by'(evt) {
  1032. evt.preventDefault();
  1033. this.currentBoard.allowsAssignedBy = !this.currentBoard
  1034. .allowsAssignedBy;
  1035. this.currentBoard.setAllowsAssignedBy(
  1036. this.currentBoard.allowsAssignedBy,
  1037. );
  1038. $(`.js-field-has-assigned-by ${MCB}`).toggleClass(
  1039. CKCLS,
  1040. this.currentBoard.allowsAssignedBy,
  1041. );
  1042. $('.js-field-has-assigned-by').toggleClass(
  1043. CKCLS,
  1044. this.currentBoard.allowsAssignedBy,
  1045. );
  1046. },
  1047. 'click .js-field-has-requested-by'(evt) {
  1048. evt.preventDefault();
  1049. this.currentBoard.allowsRequestedBy = !this.currentBoard
  1050. .allowsRequestedBy;
  1051. this.currentBoard.setAllowsRequestedBy(
  1052. this.currentBoard.allowsRequestedBy,
  1053. );
  1054. $(`.js-field-has-requested-by ${MCB}`).toggleClass(
  1055. CKCLS,
  1056. this.currentBoard.allowsRequestedBy,
  1057. );
  1058. $('.js-field-has-requested-by').toggleClass(
  1059. CKCLS,
  1060. this.currentBoard.allowsRequestedBy,
  1061. );
  1062. },
  1063. 'click .js-field-has-card-sorting-by-number'(evt) {
  1064. evt.preventDefault();
  1065. this.currentBoard.allowsCardSortingByNumber = !this.currentBoard
  1066. .allowsCardSortingByNumber;
  1067. this.currentBoard.setAllowsCardSortingByNumber(
  1068. this.currentBoard.allowsCardSortingByNumber,
  1069. );
  1070. $(`.js-field-has-card-sorting-by-number ${MCB}`).toggleClass(
  1071. CKCLS,
  1072. this.currentBoard.allowsCardSortingByNumber,
  1073. );
  1074. $('.js-field-has-card-sorting-by-number').toggleClass(
  1075. CKCLS,
  1076. this.currentBoard.allowsCardSortingByNumber,
  1077. );
  1078. },
  1079. 'click .js-field-has-card-show-lists'(evt) {
  1080. evt.preventDefault();
  1081. this.currentBoard.allowsShowLists = !this.currentBoard
  1082. .allowsShowLists;
  1083. this.currentBoard.setAllowsShowLists(
  1084. this.currentBoard.allowsShowLists,
  1085. );
  1086. $(`.js-field-has-card-show-lists ${MCB}`).toggleClass(
  1087. CKCLS,
  1088. this.currentBoard.allowsShowLists,
  1089. );
  1090. $('.js-field-has-card-show-lists').toggleClass(
  1091. CKCLS,
  1092. this.currentBoard.allowsShowLists,
  1093. );
  1094. },
  1095. 'click .js-field-has-labels'(evt) {
  1096. evt.preventDefault();
  1097. this.currentBoard.allowsLabels = !this.currentBoard.allowsLabels;
  1098. this.currentBoard.setAllowsLabels(this.currentBoard.allowsLabels);
  1099. $(`.js-field-has-labels ${MCB}`).toggleClass(
  1100. CKCLS,
  1101. this.currentBoard.allowsAssignee,
  1102. );
  1103. $('.js-field-has-labels').toggleClass(
  1104. CKCLS,
  1105. this.currentBoard.allowsLabels,
  1106. );
  1107. },
  1108. 'click .js-field-has-description-title'(evt) {
  1109. evt.preventDefault();
  1110. this.currentBoard.allowsDescriptionTitle = !this.currentBoard
  1111. .allowsDescriptionTitle;
  1112. this.currentBoard.setAllowsDescriptionTitle(
  1113. this.currentBoard.allowsDescriptionTitle,
  1114. );
  1115. $(`.js-field-has-description-title ${MCB}`).toggleClass(
  1116. CKCLS,
  1117. this.currentBoard.allowsDescriptionTitle,
  1118. );
  1119. $('.js-field-has-description-title').toggleClass(
  1120. CKCLS,
  1121. this.currentBoard.allowsDescriptionTitle,
  1122. );
  1123. },
  1124. 'click .js-field-has-card-number'(evt) {
  1125. evt.preventDefault();
  1126. this.currentBoard.allowsCardNumber = !this.currentBoard
  1127. .allowsCardNumber;
  1128. this.currentBoard.setAllowsCardNumber(
  1129. this.currentBoard.allowsCardNumber,
  1130. );
  1131. $(`.js-field-has-card-number ${MCB}`).toggleClass(
  1132. CKCLS,
  1133. this.currentBoard.allowsCardNumber,
  1134. );
  1135. $('.js-field-has-card-number').toggleClass(
  1136. CKCLS,
  1137. this.currentBoard.allowsCardNumber,
  1138. );
  1139. },
  1140. 'click .js-field-has-description-text'(evt) {
  1141. evt.preventDefault();
  1142. this.currentBoard.allowsDescriptionText = !this.currentBoard
  1143. .allowsDescriptionText;
  1144. this.currentBoard.setAllowsDescriptionText(
  1145. this.currentBoard.allowsDescriptionText,
  1146. );
  1147. $(`.js-field-has-description-text ${MCB}`).toggleClass(
  1148. CKCLS,
  1149. this.currentBoard.allowsDescriptionText,
  1150. );
  1151. $('.js-field-has-description-text').toggleClass(
  1152. CKCLS,
  1153. this.currentBoard.allowsDescriptionText,
  1154. );
  1155. },
  1156. 'click .js-field-has-checklists'(evt) {
  1157. evt.preventDefault();
  1158. this.currentBoard.allowsChecklists = !this.currentBoard
  1159. .allowsChecklists;
  1160. this.currentBoard.setAllowsChecklists(
  1161. this.currentBoard.allowsChecklists,
  1162. );
  1163. $(`.js-field-has-checklists ${MCB}`).toggleClass(
  1164. CKCLS,
  1165. this.currentBoard.allowsChecklists,
  1166. );
  1167. $('.js-field-has-checklists').toggleClass(
  1168. CKCLS,
  1169. this.currentBoard.allowsChecklists,
  1170. );
  1171. },
  1172. 'click .js-field-has-attachments'(evt) {
  1173. evt.preventDefault();
  1174. this.currentBoard.allowsAttachments = !this.currentBoard
  1175. .allowsAttachments;
  1176. this.currentBoard.setAllowsAttachments(
  1177. this.currentBoard.allowsAttachments,
  1178. );
  1179. $(`.js-field-has-attachments ${MCB}`).toggleClass(
  1180. CKCLS,
  1181. this.currentBoard.allowsAttachments,
  1182. );
  1183. $('.js-field-has-attachments').toggleClass(
  1184. CKCLS,
  1185. this.currentBoard.allowsAttachments,
  1186. );
  1187. },
  1188. 'click .js-field-has-comments'(evt) {
  1189. evt.preventDefault();
  1190. this.currentBoard.allowsComments = !this.currentBoard.allowsComments;
  1191. this.currentBoard.setAllowsComments(this.currentBoard.allowsComments);
  1192. $(`.js-field-has-comments ${MCB}`).toggleClass(
  1193. CKCLS,
  1194. this.currentBoard.allowsComments,
  1195. );
  1196. $('.js-field-has-comments').toggleClass(
  1197. CKCLS,
  1198. this.currentBoard.allowsComments,
  1199. );
  1200. },
  1201. 'click .js-field-has-activities'(evt) {
  1202. evt.preventDefault();
  1203. this.currentBoard.allowsActivities = !this.currentBoard
  1204. .allowsActivities;
  1205. this.currentBoard.setAllowsActivities(
  1206. this.currentBoard.allowsActivities,
  1207. );
  1208. $(`.js-field-has-activities ${MCB}`).toggleClass(
  1209. CKCLS,
  1210. this.currentBoard.allowsActivities,
  1211. );
  1212. $('.js-field-has-activities').toggleClass(
  1213. CKCLS,
  1214. this.currentBoard.allowsActivities,
  1215. );
  1216. },
  1217. },
  1218. ];
  1219. },
  1220. }).register('boardCardSettingsPopup');
  1221. BlazeComponent.extendComponent({
  1222. onCreated() {
  1223. this.currentBoard = Utils.getCurrentBoard();
  1224. },
  1225. allowsDescriptionTextOnMinicard() {
  1226. return this.currentBoard.allowsDescriptionTextOnMinicard;
  1227. },
  1228. allowsCoverAttachmentOnMinicard() {
  1229. return this.currentBoard.allowsCoverAttachmentOnMinicard;
  1230. },
  1231. allowsBadgeAttachmentOnMinicard() {
  1232. return this.currentBoard.allowsBadgeAttachmentOnMinicard;
  1233. },
  1234. allowsCardSortingByNumberOnMinicard() {
  1235. return this.currentBoard.allowsCardSortingByNumberOnMinicard;
  1236. },
  1237. lists() {
  1238. return Lists.find(
  1239. {
  1240. boardId: this.currentBoard._id,
  1241. archived: false,
  1242. },
  1243. {
  1244. sort: ['title'],
  1245. },
  1246. );
  1247. },
  1248. hasLists() {
  1249. return this.lists().count() > 0;
  1250. },
  1251. isListSelected() {
  1252. return (
  1253. this.currentBoard.dateSettingsDefaultBoardId === this.currentData()._id
  1254. );
  1255. },
  1256. events() {
  1257. return [
  1258. {
  1259. 'click .js-field-has-description-text-on-minicard'(evt) {
  1260. evt.preventDefault();
  1261. this.currentBoard.allowsDescriptionTextOnMinicard = !this.currentBoard
  1262. .allowsDescriptionTextOnMinicard;
  1263. this.currentBoard.setallowsDescriptionTextOnMinicard(
  1264. this.currentBoard.allowsDescriptionTextOnMinicard,
  1265. );
  1266. $(`.js-field-has-description-text-on-minicard ${MCB}`).toggleClass(
  1267. CKCLS,
  1268. this.currentBoard.allowsDescriptionTextOnMinicard,
  1269. );
  1270. $('.js-field-has-description-text-on-minicard').toggleClass(
  1271. CKCLS,
  1272. this.currentBoard.allowsDescriptionTextOnMinicard,
  1273. );
  1274. },
  1275. 'click .js-field-has-cover-attachment-on-minicard'(evt) {
  1276. evt.preventDefault();
  1277. this.currentBoard.allowsCoverAttachmentOnMinicard = !this.currentBoard
  1278. .allowsCoverAttachmentOnMinicard;
  1279. this.currentBoard.setallowsCoverAttachmentOnMinicard(
  1280. this.currentBoard.allowsCoverAttachmentOnMinicard,
  1281. );
  1282. $(`.js-field-has-cover-attachment-on-minicard ${MCB}`).toggleClass(
  1283. CKCLS,
  1284. this.currentBoard.allowsCoverAttachmentOnMinicard,
  1285. );
  1286. $('.js-field-has-cover-attachment-on-minicard').toggleClass(
  1287. CKCLS,
  1288. this.currentBoard.allowsCoverAttachmentOnMinicard,
  1289. );
  1290. },
  1291. 'click .js-field-has-badge-attachment-on-minicard'(evt) {
  1292. evt.preventDefault();
  1293. this.currentBoard.allowsBadgeAttachmentOnMinicard = !this.currentBoard
  1294. .allowsBadgeAttachmentOnMinicard;
  1295. this.currentBoard.setallowsBadgeAttachmentOnMinicard(
  1296. this.currentBoard.allowsBadgeAttachmentOnMinicard,
  1297. );
  1298. $(`.js-field-has-badge-attachment-on-minicard ${MCB}`).toggleClass(
  1299. CKCLS,
  1300. this.currentBoard.allowsBadgeAttachmentOnMinicard,
  1301. );
  1302. $('.js-field-has-badge-attachment-on-minicard').toggleClass(
  1303. CKCLS,
  1304. this.currentBoard.allowsBadgeAttachmentOnMinicard,
  1305. );
  1306. },
  1307. 'click .js-field-has-card-sorting-by-number-on-minicard'(evt) {
  1308. evt.preventDefault();
  1309. this.currentBoard.allowsCardSortingByNumberOnMinicard = !this.currentBoard
  1310. .allowsCardSortingByNumberOnMinicard;
  1311. this.currentBoard.setallowsCardSortingByNumberOnMinicard(
  1312. this.currentBoard.allowsCardSortingByNumberOnMinicard,
  1313. );
  1314. $(`.js-field-has-card-sorting-by-number-on-minicard ${MCB}`).toggleClass(
  1315. CKCLS,
  1316. this.currentBoard.allowsCardSortingByNumberOnMinicard,
  1317. );
  1318. $('.js-field-has-card-sorting-by-number-on-minicard').toggleClass(
  1319. CKCLS,
  1320. this.currentBoard.allowsCardSortingByNumberOnMinicard,
  1321. );
  1322. },
  1323. },
  1324. ];
  1325. },
  1326. }).register('boardMinicardSettingsPopup');
  1327. BlazeComponent.extendComponent({
  1328. onCreated() {
  1329. this.error = new ReactiveVar('');
  1330. this.loading = new ReactiveVar(false);
  1331. },
  1332. onRendered() {
  1333. this.find('.js-search-member input').focus();
  1334. this.setLoading(false);
  1335. },
  1336. isBoardMember() {
  1337. const userId = this.currentData().__originalId;
  1338. const user = Users.findOne(userId);
  1339. return user && user.isBoardMember();
  1340. },
  1341. isValidEmail(email) {
  1342. return SimpleSchema.RegEx.Email.test(email);
  1343. },
  1344. setError(error) {
  1345. this.error.set(error);
  1346. },
  1347. setLoading(w) {
  1348. this.loading.set(w);
  1349. },
  1350. isLoading() {
  1351. return this.loading.get();
  1352. },
  1353. inviteUser(idNameEmail) {
  1354. const boardId = Session.get('currentBoard');
  1355. this.setLoading(true);
  1356. const self = this;
  1357. Meteor.call('inviteUserToBoard', idNameEmail, boardId, (err, ret) => {
  1358. self.setLoading(false);
  1359. if (err) self.setError(err.error);
  1360. else if (ret.email) self.setError('email-sent');
  1361. else Popup.back();
  1362. });
  1363. },
  1364. events() {
  1365. return [
  1366. {
  1367. 'keyup input'() {
  1368. this.setError('');
  1369. },
  1370. 'click .js-select-member'() {
  1371. const userId = this.currentData().__originalId;
  1372. const currentBoard = Utils.getCurrentBoard();
  1373. if (!currentBoard.hasMember(userId)) {
  1374. this.inviteUser(userId);
  1375. }
  1376. },
  1377. 'click .js-email-invite'() {
  1378. const idNameEmail = $('.js-search-member input').val();
  1379. if (idNameEmail.indexOf('@') < 0 || this.isValidEmail(idNameEmail)) {
  1380. this.inviteUser(idNameEmail);
  1381. } else this.setError('email-invalid');
  1382. },
  1383. },
  1384. ];
  1385. },
  1386. }).register('addMemberPopup');
  1387. Template.addMemberPopup.helpers({
  1388. searchIndex: () => UserSearchIndex,
  1389. })
  1390. BlazeComponent.extendComponent({
  1391. onCreated() {
  1392. this.error = new ReactiveVar('');
  1393. this.loading = new ReactiveVar(false);
  1394. this.findOrgsOptions = new ReactiveVar({});
  1395. this.page = new ReactiveVar(1);
  1396. this.autorun(() => {
  1397. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1398. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1399. });
  1400. },
  1401. onRendered() {
  1402. this.setLoading(false);
  1403. },
  1404. setError(error) {
  1405. this.error.set(error);
  1406. },
  1407. setLoading(w) {
  1408. this.loading.set(w);
  1409. },
  1410. isLoading() {
  1411. return this.loading.get();
  1412. },
  1413. events() {
  1414. return [
  1415. {
  1416. 'keyup input'() {
  1417. this.setError('');
  1418. },
  1419. 'change #jsBoardOrgs'() {
  1420. let currentBoard = Utils.getCurrentBoard();
  1421. let selectElt = document.getElementById("jsBoardOrgs");
  1422. let selectedOrgId = selectElt.options[selectElt.selectedIndex].value;
  1423. let selectedOrgDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1424. let boardOrganizations = [];
  1425. if(currentBoard.orgs !== undefined){
  1426. for(let i = 0; i < currentBoard.orgs.length; i++){
  1427. boardOrganizations.push(currentBoard.orgs[i]);
  1428. }
  1429. }
  1430. if(!boardOrganizations.some((org) => org.orgDisplayName == selectedOrgDisplayName)){
  1431. boardOrganizations.push({
  1432. "orgId": selectedOrgId,
  1433. "orgDisplayName": selectedOrgDisplayName,
  1434. "isActive" : true,
  1435. })
  1436. if (selectedOrgId != "-1") {
  1437. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1438. }
  1439. }
  1440. Popup.back();
  1441. },
  1442. },
  1443. ];
  1444. },
  1445. }).register('addBoardOrgPopup');
  1446. Template.addBoardOrgPopup.helpers({
  1447. orgsDatas() {
  1448. let orgs = Org.find({}, {sort: { orgDisplayName: 1 }});
  1449. return orgs;
  1450. },
  1451. });
  1452. BlazeComponent.extendComponent({
  1453. onCreated() {
  1454. this.error = new ReactiveVar('');
  1455. this.loading = new ReactiveVar(false);
  1456. this.findOrgsOptions = new ReactiveVar({});
  1457. this.page = new ReactiveVar(1);
  1458. this.autorun(() => {
  1459. const limitOrgs = this.page.get() * Number.MAX_SAFE_INTEGER;
  1460. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {});
  1461. });
  1462. },
  1463. onRendered() {
  1464. this.setLoading(false);
  1465. },
  1466. setError(error) {
  1467. this.error.set(error);
  1468. },
  1469. setLoading(w) {
  1470. this.loading.set(w);
  1471. },
  1472. isLoading() {
  1473. return this.loading.get();
  1474. },
  1475. events() {
  1476. return [
  1477. {
  1478. 'keyup input'() {
  1479. this.setError('');
  1480. },
  1481. 'click #leaveBoardBtn'(){
  1482. let stringOrgId = document.getElementById('hideOrgId').value;
  1483. let currentBoard = Utils.getCurrentBoard();
  1484. let boardOrganizations = [];
  1485. if(currentBoard.orgs !== undefined){
  1486. for(let i = 0; i < currentBoard.orgs.length; i++){
  1487. if(currentBoard.orgs[i].orgId != stringOrgId){
  1488. boardOrganizations.push(currentBoard.orgs[i]);
  1489. }
  1490. }
  1491. }
  1492. Meteor.call('setBoardOrgs', boardOrganizations, currentBoard._id);
  1493. Popup.back();
  1494. },
  1495. 'click #cancelLeaveBoardBtn'(){
  1496. Popup.back();
  1497. },
  1498. },
  1499. ];
  1500. },
  1501. }).register('removeBoardOrgPopup');
  1502. Template.removeBoardOrgPopup.helpers({
  1503. org() {
  1504. return Org.findOne(this.orgId);
  1505. },
  1506. });
  1507. BlazeComponent.extendComponent({
  1508. onCreated() {
  1509. this.error = new ReactiveVar('');
  1510. this.loading = new ReactiveVar(false);
  1511. this.findOrgsOptions = new ReactiveVar({});
  1512. this.page = new ReactiveVar(1);
  1513. this.autorun(() => {
  1514. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1515. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1516. });
  1517. this.findUsersOptions = new ReactiveVar({});
  1518. this.userPage = new ReactiveVar(1);
  1519. this.autorun(() => {
  1520. const limitUsers = this.userPage.get() * Number.MAX_SAFE_INTEGER;
  1521. this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {});
  1522. });
  1523. },
  1524. onRendered() {
  1525. this.setLoading(false);
  1526. },
  1527. setError(error) {
  1528. this.error.set(error);
  1529. },
  1530. setLoading(w) {
  1531. this.loading.set(w);
  1532. },
  1533. isLoading() {
  1534. return this.loading.get();
  1535. },
  1536. events() {
  1537. return [
  1538. {
  1539. 'keyup input'() {
  1540. this.setError('');
  1541. },
  1542. 'change #jsBoardTeams'() {
  1543. let currentBoard = Utils.getCurrentBoard();
  1544. let selectElt = document.getElementById("jsBoardTeams");
  1545. let selectedTeamId = selectElt.options[selectElt.selectedIndex].value;
  1546. let selectedTeamDisplayName = selectElt.options[selectElt.selectedIndex].text;
  1547. let boardTeams = [];
  1548. if(currentBoard.teams !== undefined){
  1549. for(let i = 0; i < currentBoard.teams.length; i++){
  1550. boardTeams.push(currentBoard.teams[i]);
  1551. }
  1552. }
  1553. if(!boardTeams.some((team) => team.teamDisplayName == selectedTeamDisplayName)){
  1554. boardTeams.push({
  1555. "teamId": selectedTeamId,
  1556. "teamDisplayName": selectedTeamDisplayName,
  1557. "isActive" : true,
  1558. })
  1559. if (selectedTeamId != "-1") {
  1560. let members = currentBoard.members;
  1561. let query = {
  1562. "teams.teamId": { $in: boardTeams.map(t => t.teamId) },
  1563. };
  1564. const boardTeamUsers = Users.find(query, {
  1565. sort: { sort: 1 },
  1566. });
  1567. if(boardTeams !== undefined && boardTeams.length > 0){
  1568. let index;
  1569. if(boardTeamUsers && boardTeamUsers.count() > 0){
  1570. boardTeamUsers.forEach((u) => {
  1571. index = members.findIndex(function(m){ return m.userId == u._id});
  1572. if(index == -1){
  1573. members.push({
  1574. "isActive": true,
  1575. "isAdmin": u.isAdmin !== undefined ? u.isAdmin : false,
  1576. "isCommentOnly" : false,
  1577. "isNoComments" : false,
  1578. "userId": u._id,
  1579. });
  1580. }
  1581. });
  1582. }
  1583. }
  1584. Meteor.call('setBoardTeams', boardTeams, members, currentBoard._id);
  1585. }
  1586. }
  1587. Popup.back();
  1588. },
  1589. },
  1590. ];
  1591. },
  1592. }).register('addBoardTeamPopup');
  1593. Template.addBoardTeamPopup.helpers({
  1594. teamsDatas() {
  1595. let teams = Team.find({}, {sort: { teamDisplayName: 1 }});
  1596. return teams;
  1597. },
  1598. });
  1599. BlazeComponent.extendComponent({
  1600. onCreated() {
  1601. this.error = new ReactiveVar('');
  1602. this.loading = new ReactiveVar(false);
  1603. this.findOrgsOptions = new ReactiveVar({});
  1604. this.page = new ReactiveVar(1);
  1605. this.autorun(() => {
  1606. const limitTeams = this.page.get() * Number.MAX_SAFE_INTEGER;
  1607. this.subscribe('team', this.findOrgsOptions.get(), limitTeams, () => {});
  1608. });
  1609. this.findUsersOptions = new ReactiveVar({});
  1610. this.userPage = new ReactiveVar(1);
  1611. this.autorun(() => {
  1612. const limitUsers = this.userPage.get() * Number.MAX_SAFE_INTEGER;
  1613. this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {});
  1614. });
  1615. },
  1616. onRendered() {
  1617. this.setLoading(false);
  1618. },
  1619. setError(error) {
  1620. this.error.set(error);
  1621. },
  1622. setLoading(w) {
  1623. this.loading.set(w);
  1624. },
  1625. isLoading() {
  1626. return this.loading.get();
  1627. },
  1628. events() {
  1629. return [
  1630. {
  1631. 'keyup input'() {
  1632. this.setError('');
  1633. },
  1634. 'click #leaveBoardTeamBtn'(){
  1635. let stringTeamId = document.getElementById('hideTeamId').value;
  1636. let currentBoard = Utils.getCurrentBoard();
  1637. let boardTeams = [];
  1638. if(currentBoard.teams !== undefined){
  1639. for(let i = 0; i < currentBoard.teams.length; i++){
  1640. if(currentBoard.teams[i].teamId != stringTeamId){
  1641. boardTeams.push(currentBoard.teams[i]);
  1642. }
  1643. }
  1644. }
  1645. let members = currentBoard.members;
  1646. let query = {
  1647. "teams.teamId": stringTeamId
  1648. };
  1649. const boardTeamUsers = Users.find(query, {
  1650. sort: { sort: 1 },
  1651. });
  1652. if(currentBoard.teams !== undefined && currentBoard.teams.length > 0){
  1653. let index;
  1654. if(boardTeamUsers && boardTeamUsers.count() > 0){
  1655. boardTeamUsers.forEach((u) => {
  1656. index = members.findIndex(function(m){ return m.userId == u._id});
  1657. if(index !== -1 && (u.isAdmin === undefined || u.isAdmin == false)){
  1658. members.splice(index, 1);
  1659. }
  1660. });
  1661. }
  1662. }
  1663. Meteor.call('setBoardTeams', boardTeams, members, currentBoard._id);
  1664. Popup.back();
  1665. },
  1666. 'click #cancelLeaveBoardTeamBtn'(){
  1667. Popup.back();
  1668. },
  1669. },
  1670. ];
  1671. },
  1672. }).register('removeBoardTeamPopup');
  1673. Template.removeBoardTeamPopup.helpers({
  1674. team() {
  1675. return Team.findOne(this.teamId);
  1676. },
  1677. });
  1678. Template.changePermissionsPopup.events({
  1679. 'click .js-set-admin, click .js-set-normal, click .js-set-no-comments, click .js-set-comment-only, click .js-set-worker'(
  1680. event,
  1681. ) {
  1682. const currentBoard = Utils.getCurrentBoard();
  1683. const memberId = this.userId;
  1684. const isAdmin = $(event.currentTarget).hasClass('js-set-admin');
  1685. const isCommentOnly = $(event.currentTarget).hasClass(
  1686. 'js-set-comment-only',
  1687. );
  1688. const isNoComments = $(event.currentTarget).hasClass('js-set-no-comments');
  1689. const isWorker = $(event.currentTarget).hasClass('js-set-worker');
  1690. currentBoard.setMemberPermission(
  1691. memberId,
  1692. isAdmin,
  1693. isNoComments,
  1694. isCommentOnly,
  1695. isWorker,
  1696. );
  1697. Popup.back(1);
  1698. },
  1699. });
  1700. Template.changePermissionsPopup.helpers({
  1701. isAdmin() {
  1702. const currentBoard = Utils.getCurrentBoard();
  1703. return currentBoard.hasAdmin(this.userId);
  1704. },
  1705. isNormal() {
  1706. const currentBoard = Utils.getCurrentBoard();
  1707. return (
  1708. !currentBoard.hasAdmin(this.userId) &&
  1709. !currentBoard.hasNoComments(this.userId) &&
  1710. !currentBoard.hasCommentOnly(this.userId) &&
  1711. !currentBoard.hasWorker(this.userId)
  1712. );
  1713. },
  1714. isNoComments() {
  1715. const currentBoard = Utils.getCurrentBoard();
  1716. return (
  1717. !currentBoard.hasAdmin(this.userId) &&
  1718. currentBoard.hasNoComments(this.userId)
  1719. );
  1720. },
  1721. isCommentOnly() {
  1722. const currentBoard = Utils.getCurrentBoard();
  1723. return (
  1724. !currentBoard.hasAdmin(this.userId) &&
  1725. currentBoard.hasCommentOnly(this.userId)
  1726. );
  1727. },
  1728. isWorker() {
  1729. const currentBoard = Utils.getCurrentBoard();
  1730. return (
  1731. !currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
  1732. );
  1733. },
  1734. isLastAdmin() {
  1735. const currentBoard = Utils.getCurrentBoard();
  1736. return (
  1737. currentBoard.hasAdmin(this.userId) && currentBoard.activeAdmins() === 1
  1738. );
  1739. },
  1740. });