2
0

sidebar.js 42 KB

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