listBody.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. const subManager = new SubsManager();
  2. const InfiniteScrollIter = 10;
  3. BlazeComponent.extendComponent({
  4. onCreated() {
  5. // for infinite scrolling
  6. this.cardlimit = new ReactiveVar(InfiniteScrollIter);
  7. this.linkCardsEnabled = new ReactiveVar(true);
  8. Meteor.call('getLinkedCardsEnabled', (error, ret) => {
  9. if (!error && ret) {
  10. this.linkCardsEnabled.set(ret);
  11. }
  12. });
  13. },
  14. linkCardsEnabled() {
  15. return this.linkCardsEnabled.get();
  16. },
  17. mixins() {
  18. return [Mixins.PerfectScrollbar];
  19. },
  20. openForm(options) {
  21. options = options || {};
  22. options.position = options.position || 'top';
  23. const forms = this.childComponents('inlinedForm');
  24. let form = forms.find(component => {
  25. return component.data().position === options.position;
  26. });
  27. if (!form && forms.length > 0) {
  28. form = forms[0];
  29. }
  30. form.open();
  31. },
  32. addCard(evt) {
  33. evt.preventDefault();
  34. const firstCardDom = this.find('.js-minicard:first');
  35. const lastCardDom = this.find('.js-minicard:last');
  36. const textarea = $(evt.currentTarget).find('textarea');
  37. const position = this.currentData().position;
  38. const title = textarea.val().trim();
  39. const formComponent = this.childComponents('addCardForm')[0];
  40. let sortIndex;
  41. if (position === 'top') {
  42. sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  43. } else if (position === 'bottom') {
  44. sortIndex = Utils.calculateIndex(lastCardDom, null).base;
  45. }
  46. const members = formComponent.members.get();
  47. const labelIds = formComponent.labels.get();
  48. const customFields = formComponent.customFields.get();
  49. const board = this.data().board();
  50. let linkedId = '';
  51. let swimlaneId = '';
  52. let cardType = 'cardType-card';
  53. if (title) {
  54. if (board.isTemplatesBoard()) {
  55. swimlaneId = this.parentComponent()
  56. .parentComponent()
  57. .data()._id; // Always swimlanes view
  58. const swimlane = Swimlanes.findOne(swimlaneId);
  59. // If this is the card templates swimlane, insert a card template
  60. if (swimlane.isCardTemplatesSwimlane()) cardType = 'template-card';
  61. // If this is the board templates swimlane, insert a board template and a linked card
  62. else if (swimlane.isBoardTemplatesSwimlane()) {
  63. linkedId = Boards.insert({
  64. title,
  65. permission: 'private',
  66. type: 'template-board',
  67. });
  68. Swimlanes.insert({
  69. title: TAPi18n.__('default'),
  70. boardId: linkedId,
  71. });
  72. cardType = 'cardType-linkedBoard';
  73. }
  74. } else if (Utils.boardView() === 'board-view-swimlanes')
  75. swimlaneId = this.parentComponent()
  76. .parentComponent()
  77. .data()._id;
  78. else if (
  79. Utils.boardView() === 'board-view-lists' ||
  80. Utils.boardView() === 'board-view-cal' ||
  81. !Utils.boardView
  82. )
  83. swimlaneId = board.getDefaultSwimline()._id;
  84. const _id = Cards.insert({
  85. title,
  86. members,
  87. labelIds,
  88. customFields,
  89. listId: this.data()._id,
  90. boardId: board._id,
  91. sort: sortIndex,
  92. swimlaneId,
  93. type: cardType,
  94. linkedId,
  95. });
  96. // if the displayed card count is less than the total cards in the list,
  97. // we need to increment the displayed card count to prevent the spinner
  98. // to appear
  99. const cardCount = this.data()
  100. .cards(this.idOrNull(swimlaneId))
  101. .count();
  102. if (this.cardlimit.get() < cardCount) {
  103. this.cardlimit.set(this.cardlimit.get() + InfiniteScrollIter);
  104. }
  105. // In case the filter is active we need to add the newly inserted card in
  106. // the list of exceptions -- cards that are not filtered. Otherwise the
  107. // card will disappear instantly.
  108. // See https://github.com/wekan/wekan/issues/80
  109. Filter.addException(_id);
  110. // We keep the form opened, empty it, and scroll to it.
  111. textarea.val('').focus();
  112. autosize.update(textarea);
  113. if (position === 'bottom') {
  114. this.scrollToBottom();
  115. }
  116. formComponent.reset();
  117. }
  118. },
  119. scrollToBottom() {
  120. const container = this.firstNode();
  121. $(container).animate({
  122. scrollTop: container.scrollHeight,
  123. });
  124. },
  125. clickOnMiniCard(evt) {
  126. if (MultiSelection.isActive() || evt.shiftKey) {
  127. evt.stopImmediatePropagation();
  128. evt.preventDefault();
  129. const methodName = evt.shiftKey ? 'toggleRange' : 'toggle';
  130. MultiSelection[methodName](this.currentData()._id);
  131. // If the card is already selected, we want to de-select it.
  132. // XXX We should probably modify the minicard href attribute instead of
  133. // overwriting the event in case the card is already selected.
  134. } else if (Session.equals('currentCard', this.currentData()._id)) {
  135. evt.stopImmediatePropagation();
  136. evt.preventDefault();
  137. Utils.goBoardId(Session.get('currentBoard'));
  138. }
  139. },
  140. cardIsSelected() {
  141. return Session.equals('currentCard', this.currentData()._id);
  142. },
  143. toggleMultiSelection(evt) {
  144. evt.stopPropagation();
  145. evt.preventDefault();
  146. MultiSelection.toggle(this.currentData()._id);
  147. },
  148. idOrNull(swimlaneId) {
  149. if (
  150. Utils.boardView() === 'board-view-swimlanes' ||
  151. this.data()
  152. .board()
  153. .isTemplatesBoard()
  154. )
  155. return swimlaneId;
  156. return undefined;
  157. },
  158. cardsWithLimit(swimlaneId) {
  159. const limit = this.cardlimit.get();
  160. const selector = {
  161. listId: this.currentData()._id,
  162. archived: false,
  163. };
  164. if (swimlaneId) selector.swimlaneId = swimlaneId;
  165. return Cards.find(Filter.mongoSelector(selector), {
  166. sort: ['sort'],
  167. limit,
  168. });
  169. },
  170. showSpinner(swimlaneId) {
  171. const list = Template.currentData();
  172. return list.cards(swimlaneId).count() > this.cardlimit.get();
  173. },
  174. canSeeAddCard() {
  175. return (
  176. !this.reachedWipLimit() &&
  177. Meteor.user() &&
  178. Meteor.user().isBoardMember() &&
  179. !Meteor.user().isCommentOnly()
  180. );
  181. },
  182. reachedWipLimit() {
  183. const list = Template.currentData();
  184. return (
  185. !list.getWipLimit('soft') &&
  186. list.getWipLimit('enabled') &&
  187. list.getWipLimit('value') <= list.cards().count()
  188. );
  189. },
  190. events() {
  191. return [
  192. {
  193. 'click .js-minicard': this.clickOnMiniCard,
  194. 'click .js-toggle-multi-selection': this.toggleMultiSelection,
  195. 'click .open-minicard-composer': this.scrollToBottom,
  196. submit: this.addCard,
  197. },
  198. ];
  199. },
  200. }).register('listBody');
  201. function toggleValueInReactiveArray(reactiveValue, value) {
  202. const array = reactiveValue.get();
  203. const valueIndex = array.indexOf(value);
  204. if (valueIndex === -1) {
  205. array.push(value);
  206. } else {
  207. array.splice(valueIndex, 1);
  208. }
  209. reactiveValue.set(array);
  210. }
  211. BlazeComponent.extendComponent({
  212. onCreated() {
  213. this.labels = new ReactiveVar([]);
  214. this.members = new ReactiveVar([]);
  215. this.customFields = new ReactiveVar([]);
  216. const currentBoardId = Session.get('currentBoard');
  217. arr = [];
  218. _.forEach(
  219. Boards.findOne(currentBoardId)
  220. .customFields()
  221. .fetch(),
  222. function(field) {
  223. if (field.automaticallyOnCard)
  224. arr.push({ _id: field._id, value: null });
  225. },
  226. );
  227. this.customFields.set(arr);
  228. },
  229. reset() {
  230. this.labels.set([]);
  231. this.members.set([]);
  232. this.customFields.set([]);
  233. },
  234. getLabels() {
  235. const currentBoardId = Session.get('currentBoard');
  236. return Boards.findOne(currentBoardId).labels.filter(label => {
  237. return this.labels.get().indexOf(label._id) > -1;
  238. });
  239. },
  240. pressKey(evt) {
  241. // Pressing Enter should submit the card
  242. if (evt.keyCode === 13 && !evt.shiftKey) {
  243. evt.preventDefault();
  244. const $form = $(evt.currentTarget).closest('form');
  245. // XXX For some reason $form.submit() does not work (it's probably a bug
  246. // of blaze-component related to the fact that the submit event is non-
  247. // bubbling). This is why we click on the submit button instead -- which
  248. // work.
  249. $form.find('button[type=submit]').click();
  250. // Pressing Tab should open the form of the next column, and Maj+Tab go
  251. // in the reverse order
  252. } else if (evt.keyCode === 9) {
  253. evt.preventDefault();
  254. const isReverse = evt.shiftKey;
  255. const list = $(`#js-list-${this.data().listId}`);
  256. const listSelector = '.js-list:not(.js-list-composer)';
  257. let nextList = list[isReverse ? 'prev' : 'next'](listSelector).get(0);
  258. // If there is no next list, loop back to the beginning.
  259. if (!nextList) {
  260. nextList = $(listSelector + (isReverse ? ':last' : ':first')).get(0);
  261. }
  262. BlazeComponent.getComponentForElement(nextList).openForm({
  263. position: this.data().position,
  264. });
  265. }
  266. },
  267. events() {
  268. return [
  269. {
  270. keydown: this.pressKey,
  271. 'click .js-link': Popup.open('linkCard'),
  272. 'click .js-search': Popup.open('searchElement'),
  273. 'click .js-card-template': Popup.open('searchElement'),
  274. },
  275. ];
  276. },
  277. onRendered() {
  278. const editor = this;
  279. const $textarea = this.$('textarea');
  280. autosize($textarea);
  281. $textarea.escapeableTextComplete(
  282. [
  283. // User mentions
  284. {
  285. match: /\B@([\w.]*)$/,
  286. search(term, callback) {
  287. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  288. callback(
  289. $.map(currentBoard.activeMembers(), member => {
  290. const user = Users.findOne(member.userId);
  291. return user.username.indexOf(term) === 0 ? user : null;
  292. }),
  293. );
  294. },
  295. template(user) {
  296. return user.username;
  297. },
  298. replace(user) {
  299. toggleValueInReactiveArray(editor.members, user._id);
  300. return '';
  301. },
  302. index: 1,
  303. },
  304. // Labels
  305. {
  306. match: /\B#(\w*)$/,
  307. search(term, callback) {
  308. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  309. callback(
  310. $.map(currentBoard.labels, label => {
  311. if (
  312. label.name.indexOf(term) > -1 ||
  313. label.color.indexOf(term) > -1
  314. ) {
  315. return label;
  316. }
  317. return null;
  318. }),
  319. );
  320. },
  321. template(label) {
  322. return Blaze.toHTMLWithData(Template.autocompleteLabelLine, {
  323. hasNoName: !label.name,
  324. colorName: label.color,
  325. labelName: label.name || label.color,
  326. });
  327. },
  328. replace(label) {
  329. toggleValueInReactiveArray(editor.labels, label._id);
  330. return '';
  331. },
  332. index: 1,
  333. },
  334. ],
  335. {
  336. // When the autocomplete menu is shown we want both a press of both `Tab`
  337. // or `Enter` to validation the auto-completion. We also need to stop the
  338. // event propagation to prevent the card from submitting (on `Enter`) or
  339. // going on the next column (on `Tab`).
  340. onKeydown(evt, commands) {
  341. if (evt.keyCode === 9 || evt.keyCode === 13) {
  342. evt.stopPropagation();
  343. return commands.KEY_ENTER;
  344. }
  345. return null;
  346. },
  347. },
  348. );
  349. },
  350. }).register('addCardForm');
  351. BlazeComponent.extendComponent({
  352. onCreated() {
  353. this.selectedBoardId = new ReactiveVar('');
  354. this.selectedSwimlaneId = new ReactiveVar('');
  355. this.selectedListId = new ReactiveVar('');
  356. this.boardId = Session.get('currentBoard');
  357. // In order to get current board info
  358. subManager.subscribe('board', this.boardId, false);
  359. this.board = Boards.findOne(this.boardId);
  360. // List where to insert card
  361. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  362. this.listId = Blaze.getData(list[0])._id;
  363. // Swimlane where to insert card
  364. const swimlane = $(Popup._getTopStack().openerElement).closest(
  365. '.js-swimlane',
  366. );
  367. this.swimlaneId = '';
  368. if (Utils.boardView() === 'board-view-swimlanes')
  369. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  370. else if (Utils.boardView() === 'board-view-lists' || !Utils.boardView)
  371. this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  372. },
  373. boards() {
  374. const boards = Boards.find(
  375. {
  376. archived: false,
  377. 'members.userId': Meteor.userId(),
  378. _id: { $ne: Session.get('currentBoard') },
  379. type: 'board',
  380. },
  381. {
  382. sort: ['title'],
  383. },
  384. );
  385. return boards;
  386. },
  387. swimlanes() {
  388. if (!this.selectedBoardId.get()) {
  389. return [];
  390. }
  391. const swimlanes = Swimlanes.find({ boardId: this.selectedBoardId.get() });
  392. if (swimlanes.count())
  393. this.selectedSwimlaneId.set(swimlanes.fetch()[0]._id);
  394. return swimlanes;
  395. },
  396. lists() {
  397. if (!this.selectedBoardId.get()) {
  398. return [];
  399. }
  400. const lists = Lists.find({ boardId: this.selectedBoardId.get() });
  401. if (lists.count()) this.selectedListId.set(lists.fetch()[0]._id);
  402. return lists;
  403. },
  404. cards() {
  405. if (!this.board) {
  406. return [];
  407. }
  408. const ownCardsIds = this.board.cards().map(card => {
  409. return card.linkedId || card._id;
  410. });
  411. return Cards.find({
  412. boardId: this.selectedBoardId.get(),
  413. swimlaneId: this.selectedSwimlaneId.get(),
  414. listId: this.selectedListId.get(),
  415. archived: false,
  416. linkedId: { $nin: ownCardsIds },
  417. _id: { $nin: ownCardsIds },
  418. type: { $nin: ['template-card'] },
  419. });
  420. },
  421. events() {
  422. return [
  423. {
  424. 'change .js-select-boards'(evt) {
  425. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  426. this.selectedBoardId.set($(evt.currentTarget).val());
  427. },
  428. 'change .js-select-swimlanes'(evt) {
  429. this.selectedSwimlaneId.set($(evt.currentTarget).val());
  430. },
  431. 'change .js-select-lists'(evt) {
  432. this.selectedListId.set($(evt.currentTarget).val());
  433. },
  434. 'click .js-done'(evt) {
  435. // LINK CARD
  436. evt.stopPropagation();
  437. evt.preventDefault();
  438. const linkedId = $('.js-select-cards option:selected').val();
  439. if (!linkedId) {
  440. Popup.close();
  441. return;
  442. }
  443. const _id = Cards.insert({
  444. title: $('.js-select-cards option:selected').text(), //dummy
  445. listId: this.listId,
  446. swimlaneId: this.swimlaneId,
  447. boardId: this.boardId,
  448. sort: Lists.findOne(this.listId)
  449. .cards()
  450. .count(),
  451. type: 'cardType-linkedCard',
  452. linkedId,
  453. });
  454. Filter.addException(_id);
  455. Popup.close();
  456. },
  457. 'click .js-link-board'(evt) {
  458. //LINK BOARD
  459. evt.stopPropagation();
  460. evt.preventDefault();
  461. const impBoardId = $('.js-select-boards option:selected').val();
  462. if (
  463. !impBoardId ||
  464. Cards.findOne({ linkedId: impBoardId, archived: false })
  465. ) {
  466. Popup.close();
  467. return;
  468. }
  469. const _id = Cards.insert({
  470. title: $('.js-select-boards option:selected').text(), //dummy
  471. listId: this.listId,
  472. swimlaneId: this.swimlaneId,
  473. boardId: this.boardId,
  474. sort: Lists.findOne(this.listId)
  475. .cards()
  476. .count(),
  477. type: 'cardType-linkedBoard',
  478. linkedId: impBoardId,
  479. });
  480. Filter.addException(_id);
  481. Popup.close();
  482. },
  483. },
  484. ];
  485. },
  486. }).register('linkCardPopup');
  487. BlazeComponent.extendComponent({
  488. mixins() {
  489. return [Mixins.PerfectScrollbar];
  490. },
  491. onCreated() {
  492. this.isCardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  493. 'js-card-template',
  494. );
  495. this.isListTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  496. 'js-list-template',
  497. );
  498. this.isSwimlaneTemplateSearch = $(
  499. Popup._getTopStack().openerElement,
  500. ).hasClass('js-open-add-swimlane-menu');
  501. this.isBoardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  502. 'js-add-board',
  503. );
  504. this.isTemplateSearch =
  505. this.isCardTemplateSearch ||
  506. this.isListTemplateSearch ||
  507. this.isSwimlaneTemplateSearch ||
  508. this.isBoardTemplateSearch;
  509. let board = {};
  510. if (this.isTemplateSearch) {
  511. board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
  512. } else {
  513. // Prefetch first non-current board id
  514. board = Boards.findOne({
  515. archived: false,
  516. 'members.userId': Meteor.userId(),
  517. _id: {
  518. $nin: [
  519. Session.get('currentBoard'),
  520. (Meteor.user().profile || {}).templatesBoardId,
  521. ],
  522. },
  523. });
  524. }
  525. if (!board) {
  526. Popup.close();
  527. return;
  528. }
  529. const boardId = board._id;
  530. // Subscribe to this board
  531. subManager.subscribe('board', boardId, false);
  532. this.selectedBoardId = new ReactiveVar(boardId);
  533. if (!this.isBoardTemplateSearch) {
  534. this.boardId = Session.get('currentBoard');
  535. // In order to get current board info
  536. subManager.subscribe('board', this.boardId, false);
  537. this.swimlaneId = '';
  538. // Swimlane where to insert card
  539. const swimlane = $(Popup._getTopStack().openerElement).parents(
  540. '.js-swimlane',
  541. );
  542. if (Utils.boardView() === 'board-view-swimlanes')
  543. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  544. else this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  545. // List where to insert card
  546. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  547. this.listId = Blaze.getData(list[0])._id;
  548. }
  549. this.term = new ReactiveVar('');
  550. },
  551. boards() {
  552. const boards = Boards.find(
  553. {
  554. archived: false,
  555. 'members.userId': Meteor.userId(),
  556. _id: { $ne: Session.get('currentBoard') },
  557. type: 'board',
  558. },
  559. {
  560. sort: ['title'],
  561. },
  562. );
  563. return boards;
  564. },
  565. results() {
  566. if (!this.selectedBoardId) {
  567. return [];
  568. }
  569. const board = Boards.findOne(this.selectedBoardId.get());
  570. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  571. return board.searchCards(this.term.get(), false);
  572. } else if (this.isListTemplateSearch) {
  573. return board.searchLists(this.term.get());
  574. } else if (this.isSwimlaneTemplateSearch) {
  575. return board.searchSwimlanes(this.term.get());
  576. } else if (this.isBoardTemplateSearch) {
  577. const boards = board.searchBoards(this.term.get());
  578. boards.forEach(board => {
  579. subManager.subscribe('board', board.linkedId, false);
  580. });
  581. return boards;
  582. } else {
  583. return [];
  584. }
  585. },
  586. events() {
  587. return [
  588. {
  589. 'change .js-select-boards'(evt) {
  590. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  591. this.selectedBoardId.set($(evt.currentTarget).val());
  592. },
  593. 'submit .js-search-term-form'(evt) {
  594. evt.preventDefault();
  595. this.term.set(evt.target.searchTerm.value);
  596. },
  597. 'click .js-minicard'(evt) {
  598. // 0. Common
  599. const title = $('.js-element-title')
  600. .val()
  601. .trim();
  602. if (!title) return;
  603. const element = Blaze.getData(evt.currentTarget);
  604. element.title = title;
  605. let _id = '';
  606. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  607. // Card insertion
  608. // 1. Common
  609. element.sort = Lists.findOne(this.listId)
  610. .cards()
  611. .count();
  612. // 1.A From template
  613. if (this.isTemplateSearch) {
  614. element.type = 'cardType-card';
  615. element.linkedId = '';
  616. _id = element.copy(this.boardId, this.swimlaneId, this.listId);
  617. // 1.B Linked card
  618. } else {
  619. delete element._id;
  620. element.type = 'cardType-linkedCard';
  621. element.linkedId = element.linkedId || element._id;
  622. _id = Cards.insert(element);
  623. }
  624. Filter.addException(_id);
  625. // List insertion
  626. } else if (this.isListTemplateSearch) {
  627. element.sort = Swimlanes.findOne(this.swimlaneId)
  628. .lists()
  629. .count();
  630. element.type = 'list';
  631. _id = element.copy(this.boardId, this.swimlaneId);
  632. } else if (this.isSwimlaneTemplateSearch) {
  633. element.sort = Boards.findOne(this.boardId)
  634. .swimlanes()
  635. .count();
  636. element.type = 'swimlalne';
  637. _id = element.copy(this.boardId);
  638. } else if (this.isBoardTemplateSearch) {
  639. board = Boards.findOne(element.linkedId);
  640. board.sort = Boards.find({ archived: false }).count();
  641. board.type = 'board';
  642. board.title = element.title;
  643. delete board.slug;
  644. _id = board.copy();
  645. }
  646. Popup.close();
  647. },
  648. },
  649. ];
  650. },
  651. }).register('searchElementPopup');
  652. BlazeComponent.extendComponent({
  653. onCreated() {
  654. this.cardlimit = this.parentComponent().cardlimit;
  655. this.listId = this.parentComponent().data()._id;
  656. this.swimlaneId = '';
  657. const isSandstorm =
  658. Meteor.settings &&
  659. Meteor.settings.public &&
  660. Meteor.settings.public.sandstorm;
  661. if (isSandstorm) {
  662. const user = Meteor.user();
  663. if (user) {
  664. if (Utils.boardView() === 'board-view-swimlanes') {
  665. this.swimlaneId = this.parentComponent()
  666. .parentComponent()
  667. .parentComponent()
  668. .data()._id;
  669. }
  670. }
  671. } else if (Utils.boardView() === 'board-view-swimlanes') {
  672. this.swimlaneId = this.parentComponent()
  673. .parentComponent()
  674. .parentComponent()
  675. .data()._id;
  676. }
  677. },
  678. onRendered() {
  679. this.spinner = this.find('.sk-spinner-list');
  680. this.container = this.$(this.spinner).parents('.js-perfect-scrollbar')[0];
  681. $(this.container).on(
  682. `scroll.spinner_${this.swimlaneId}_${this.listId}`,
  683. () => this.updateList(),
  684. );
  685. $(window).on(`resize.spinner_${this.swimlaneId}_${this.listId}`, () =>
  686. this.updateList(),
  687. );
  688. this.updateList();
  689. },
  690. onDestroyed() {
  691. $(this.container).off(`scroll.spinner_${this.swimlaneId}_${this.listId}`);
  692. $(window).off(`resize.spinner_${this.swimlaneId}_${this.listId}`);
  693. },
  694. updateList() {
  695. if (this.spinnerInView()) {
  696. this.cardlimit.set(this.cardlimit.get() + InfiniteScrollIter);
  697. window.requestIdleCallback(() => this.updateList());
  698. }
  699. },
  700. spinnerInView() {
  701. const parentViewHeight = this.container.clientHeight;
  702. const bottomViewPosition = this.container.scrollTop + parentViewHeight;
  703. const threshold = this.spinner.offsetTop;
  704. // spinner deleted
  705. if (!this.spinner.offsetTop) {
  706. return false;
  707. }
  708. return bottomViewPosition > threshold;
  709. },
  710. }).register('spinnerList');