123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- const subManager = new SubsManager();
- const { calculateIndexData, enableClickOnTouch } = Utils;
- let cardColors;
- Meteor.startup(() => {
- cardColors = Cards.simpleSchema()._schema.color.allowedValues;
- });
- BlazeComponent.extendComponent({
- mixins() {
- return [Mixins.InfiniteScrolling, Mixins.PerfectScrollbar];
- },
- calculateNextPeak() {
- const cardElement = this.find('.js-card-details');
- if (cardElement) {
- const altitude = cardElement.scrollHeight;
- this.callFirstWith(this, 'setNextPeak', altitude);
- }
- },
- reachNextPeak() {
- const activitiesComponent = this.childComponents('activities')[0];
- activitiesComponent.loadNextPage();
- },
- onCreated() {
- this.currentBoard = Boards.findOne(Session.get('currentBoard'));
- this.isLoaded = new ReactiveVar(false);
- const boardBody = this.parentComponent().parentComponent();
- //in Miniview parent is Board, not BoardBody.
- if (boardBody !== null) {
- boardBody.showOverlay.set(true);
- boardBody.mouseHasEnterCardDetails = false;
- }
- this.calculateNextPeak();
- Meteor.subscribe('unsaved-edits');
- },
- isWatching() {
- const card = this.currentData();
- return card.findWatcher(Meteor.userId());
- },
- hiddenSystemMessages() {
- return Meteor.user().hasHiddenSystemMessages();
- },
- canModifyCard() {
- return (
- Meteor.user() &&
- Meteor.user().isBoardMember() &&
- !Meteor.user().isCommentOnly()
- );
- },
- scrollParentContainer() {
- const cardPanelWidth = 510;
- const bodyBoardComponent = this.parentComponent().parentComponent();
- //On Mobile View Parent is Board, Not Board Body. I cant see how this funciton should work then.
- if (bodyBoardComponent === null) return;
- const $cardView = this.$(this.firstNode());
- const $cardContainer = bodyBoardComponent.$('.js-swimlanes');
- const cardContainerScroll = $cardContainer.scrollLeft();
- const cardContainerWidth = $cardContainer.width();
- const cardViewStart = $cardView.offset().left;
- const cardViewEnd = cardViewStart + cardPanelWidth;
- let offset = false;
- if (cardViewStart < 0) {
- offset = cardViewStart;
- } else if (cardViewEnd > cardContainerWidth) {
- offset = cardViewEnd - cardContainerWidth;
- }
- if (offset) {
- bodyBoardComponent.scrollLeft(cardContainerScroll + offset);
- }
- //Scroll top
- const cardViewStartTop = $cardView.offset().top;
- const cardContainerScrollTop = $cardContainer.scrollTop();
- let topOffset = false;
- if (cardViewStartTop !== 100) {
- topOffset = cardViewStartTop - 100;
- }
- if (topOffset !== false) {
- bodyBoardComponent.scrollTop(cardContainerScrollTop + topOffset);
- }
- },
- presentParentTask() {
- let result = this.currentBoard.presentParentTask;
- if (result === null || result === undefined) {
- result = 'no-parent';
- }
- return result;
- },
- linkForCard() {
- const card = this.currentData();
- let result = '#';
- if (card) {
- const board = Boards.findOne(card.boardId);
- if (board) {
- result = FlowRouter.url('card', {
- boardId: card.boardId,
- slug: board.slug,
- cardId: card._id,
- });
- }
- }
- return result;
- },
- onRendered() {
- if (!Utils.isMiniScreen()) {
- Meteor.setTimeout(() => {
- $('.card-details').mCustomScrollbar({
- theme: 'minimal-dark',
- setWidth: false,
- setLeft: 0,
- scrollbarPosition: 'outside',
- mouseWheel: true,
- });
- this.scrollParentContainer();
- }, 500);
- }
- const $checklistsDom = this.$('.card-checklist-items');
- $checklistsDom.sortable({
- tolerance: 'pointer',
- helper: 'clone',
- handle: '.checklist-title',
- items: '.js-checklist',
- placeholder: 'checklist placeholder',
- distance: 7,
- start(evt, ui) {
- ui.placeholder.height(ui.helper.height());
- EscapeActions.executeUpTo('popup-close');
- },
- stop(evt, ui) {
- let prevChecklist = ui.item.prev('.js-checklist').get(0);
- if (prevChecklist) {
- prevChecklist = Blaze.getData(prevChecklist).checklist;
- }
- let nextChecklist = ui.item.next('.js-checklist').get(0);
- if (nextChecklist) {
- nextChecklist = Blaze.getData(nextChecklist).checklist;
- }
- const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
- $checklistsDom.sortable('cancel');
- const checklist = Blaze.getData(ui.item.get(0)).checklist;
- Checklists.update(checklist._id, {
- $set: {
- sort: sortIndex.base,
- },
- });
- },
- });
- // ugly touch event hotfix
- enableClickOnTouch('.card-checklist-items .js-checklist');
- const $subtasksDom = this.$('.card-subtasks-items');
- $subtasksDom.sortable({
- tolerance: 'pointer',
- helper: 'clone',
- handle: '.subtask-title',
- items: '.js-subtasks',
- placeholder: 'subtasks placeholder',
- distance: 7,
- start(evt, ui) {
- ui.placeholder.height(ui.helper.height());
- EscapeActions.executeUpTo('popup-close');
- },
- stop(evt, ui) {
- let prevChecklist = ui.item.prev('.js-subtasks').get(0);
- if (prevChecklist) {
- prevChecklist = Blaze.getData(prevChecklist).subtask;
- }
- let nextChecklist = ui.item.next('.js-subtasks').get(0);
- if (nextChecklist) {
- nextChecklist = Blaze.getData(nextChecklist).subtask;
- }
- const sortIndex = calculateIndexData(prevChecklist, nextChecklist, 1);
- $subtasksDom.sortable('cancel');
- const subtask = Blaze.getData(ui.item.get(0)).subtask;
- Subtasks.update(subtask._id, {
- $set: {
- subtaskSort: sortIndex.base,
- },
- });
- },
- });
- // ugly touch event hotfix
- enableClickOnTouch('.card-subtasks-items .js-subtasks');
- function userIsMember() {
- return Meteor.user() && Meteor.user().isBoardMember();
- }
- // Disable sorting if the current user is not a board member
- this.autorun(() => {
- if ($checklistsDom.data('sortable')) {
- $checklistsDom.sortable('option', 'disabled', !userIsMember());
- }
- if ($subtasksDom.data('sortable')) {
- $subtasksDom.sortable('option', 'disabled', !userIsMember());
- }
- });
- },
- onDestroyed() {
- const parentComponent = this.parentComponent().parentComponent();
- //on mobile view parent is Board, not board body.
- if (parentComponent === null) return;
- parentComponent.showOverlay.set(false);
- },
- events() {
- const events = {
- [`${CSSEvents.transitionend} .js-card-details`]() {
- this.isLoaded.set(true);
- },
- [`${CSSEvents.animationend} .js-card-details`]() {
- this.isLoaded.set(true);
- },
- };
- return [
- {
- ...events,
- 'click .js-close-card-details'() {
- Utils.goBoardId(this.data().boardId);
- },
- 'click .js-open-card-details-menu': Popup.open('cardDetailsActions'),
- 'submit .js-card-description'(event) {
- event.preventDefault();
- const description = this.currentComponent().getValue();
- this.data().setDescription(description);
- },
- 'submit .js-card-details-title'(event) {
- event.preventDefault();
- const title = this.currentComponent()
- .getValue()
- .trim();
- if (title) {
- this.data().setTitle(title);
- }
- },
- 'submit .js-card-details-assigner'(event) {
- event.preventDefault();
- const assigner = this.currentComponent()
- .getValue()
- .trim();
- if (assigner) {
- this.data().setAssignedBy(assigner);
- }
- },
- 'submit .js-card-details-requester'(event) {
- event.preventDefault();
- const requester = this.currentComponent()
- .getValue()
- .trim();
- if (requester) {
- this.data().setRequestedBy(requester);
- }
- },
- 'click .js-member': Popup.open('cardMember'),
- 'click .js-add-members': Popup.open('cardMembers'),
- 'click .js-add-labels': Popup.open('cardLabels'),
- 'click .js-received-date': Popup.open('editCardReceivedDate'),
- 'click .js-start-date': Popup.open('editCardStartDate'),
- 'click .js-due-date': Popup.open('editCardDueDate'),
- 'click .js-end-date': Popup.open('editCardEndDate'),
- 'mouseenter .js-card-details'() {
- const parentComponent = this.parentComponent().parentComponent();
- //on mobile view parent is Board, not BoardBody.
- if (parentComponent === null) return;
- parentComponent.showOverlay.set(true);
- parentComponent.mouseHasEnterCardDetails = true;
- },
- 'click #toggleButton'() {
- Meteor.call('toggleSystemMessages');
- },
- },
- ];
- },
- }).register('cardDetails');
- // We extends the normal InlinedForm component to support UnsavedEdits draft
- // feature.
- (class extends InlinedForm {
- _getUnsavedEditKey() {
- return {
- fieldName: 'cardDescription',
- // XXX Recovering the currentCard identifier form a session variable is
- // fragile because this variable may change for instance if the route
- // change. We should use some component props instead.
- docId: Session.get('currentCard'),
- };
- }
- close(isReset = false) {
- if (this.isOpen.get() && !isReset) {
- const draft = this.getValue().trim();
- if (
- draft !== Cards.findOne(Session.get('currentCard')).getDescription()
- ) {
- UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue());
- }
- }
- super.close();
- }
- reset() {
- UnsavedEdits.reset(this._getUnsavedEditKey());
- this.close(true);
- }
- events() {
- const parentEvents = InlinedForm.prototype.events()[0];
- return [
- {
- ...parentEvents,
- 'click .js-close-inlined-form': this.reset,
- },
- ];
- }
- }.register('inlinedCardDescription'));
- Template.cardDetailsActionsPopup.helpers({
- isWatching() {
- return this.findWatcher(Meteor.userId());
- },
- canModifyCard() {
- return (
- Meteor.user() &&
- Meteor.user().isBoardMember() &&
- !Meteor.user().isCommentOnly()
- );
- },
- });
- Template.cardDetailsActionsPopup.events({
- 'click .js-members': Popup.open('cardMembers'),
- 'click .js-labels': Popup.open('cardLabels'),
- 'click .js-attachments': Popup.open('cardAttachments'),
- 'click .js-custom-fields': Popup.open('cardCustomFields'),
- 'click .js-received-date': Popup.open('editCardReceivedDate'),
- 'click .js-start-date': Popup.open('editCardStartDate'),
- 'click .js-due-date': Popup.open('editCardDueDate'),
- 'click .js-end-date': Popup.open('editCardEndDate'),
- 'click .js-spent-time': Popup.open('editCardSpentTime'),
- 'click .js-move-card': Popup.open('moveCard'),
- 'click .js-copy-card': Popup.open('copyCard'),
- 'click .js-copy-checklist-cards': Popup.open('copyChecklistToManyCards'),
- 'click .js-set-card-color': Popup.open('setCardColor'),
- 'click .js-move-card-to-top'(event) {
- event.preventDefault();
- const minOrder = _.min(
- this.list()
- .cards(this.swimlaneId)
- .map(c => c.sort),
- );
- this.move(this.boardId, this.swimlaneId, this.listId, minOrder - 1);
- },
- 'click .js-move-card-to-bottom'(event) {
- event.preventDefault();
- const maxOrder = _.max(
- this.list()
- .cards(this.swimlaneId)
- .map(c => c.sort),
- );
- this.move(this.boardId, this.swimlaneId, this.listId, maxOrder + 1);
- },
- 'click .js-archive'(event) {
- event.preventDefault();
- this.archive();
- Popup.close();
- },
- 'click .js-more': Popup.open('cardMore'),
- 'click .js-toggle-watch-card'() {
- const currentCard = this;
- const level = currentCard.findWatcher(Meteor.userId()) ? null : 'watching';
- Meteor.call('watch', 'card', currentCard._id, level, (err, ret) => {
- if (!err && ret) Popup.close();
- });
- },
- });
- Template.editCardTitleForm.onRendered(function() {
- autosize(this.$('.js-edit-card-title'));
- });
- Template.editCardTitleForm.events({
- 'keydown .js-edit-card-title'(event) {
- // If enter key was pressed, submit the data
- // Unless the shift key is also being pressed
- if (event.keyCode === 13 && !event.shiftKey) {
- $('.js-submit-edit-card-title-form').click();
- }
- },
- });
- Template.editCardRequesterForm.onRendered(function() {
- autosize(this.$('.js-edit-card-requester'));
- });
- Template.editCardRequesterForm.events({
- 'keydown .js-edit-card-requester'(event) {
- // If enter key was pressed, submit the data
- if (event.keyCode === 13) {
- $('.js-submit-edit-card-requester-form').click();
- }
- },
- });
- Template.editCardAssignerForm.onRendered(function() {
- autosize(this.$('.js-edit-card-assigner'));
- });
- Template.editCardAssignerForm.events({
- 'keydown .js-edit-card-assigner'(event) {
- // If enter key was pressed, submit the data
- if (event.keyCode === 13) {
- $('.js-submit-edit-card-assigner-form').click();
- }
- },
- });
- Template.moveCardPopup.events({
- 'click .js-done'() {
- // XXX We should *not* get the currentCard from the global state, but
- // instead from a “component” state.
- const card = Cards.findOne(Session.get('currentCard'));
- const bSelect = $('.js-select-boards')[0];
- const boardId = bSelect.options[bSelect.selectedIndex].value;
- const lSelect = $('.js-select-lists')[0];
- const listId = lSelect.options[lSelect.selectedIndex].value;
- const slSelect = $('.js-select-swimlanes')[0];
- const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
- card.move(boardId, swimlaneId, listId, 0);
- Popup.close();
- },
- });
- BlazeComponent.extendComponent({
- onCreated() {
- subManager.subscribe('board', Session.get('currentBoard'), false);
- this.selectedBoardId = new ReactiveVar(Session.get('currentBoard'));
- },
- boards() {
- const boards = Boards.find(
- {
- archived: false,
- 'members.userId': Meteor.userId(),
- _id: { $ne: Meteor.user().getTemplatesBoardId() },
- },
- {
- sort: ['title'],
- },
- );
- return boards;
- },
- swimlanes() {
- const board = Boards.findOne(this.selectedBoardId.get());
- return board.swimlanes();
- },
- aBoardLists() {
- const board = Boards.findOne(this.selectedBoardId.get());
- return board.lists();
- },
- events() {
- return [
- {
- 'change .js-select-boards'(event) {
- this.selectedBoardId.set($(event.currentTarget).val());
- subManager.subscribe('board', this.selectedBoardId.get(), false);
- },
- },
- ];
- },
- }).register('boardsAndLists');
- Template.copyCardPopup.events({
- 'click .js-done'() {
- const card = Cards.findOne(Session.get('currentCard'));
- const lSelect = $('.js-select-lists')[0];
- listId = lSelect.options[lSelect.selectedIndex].value;
- const slSelect = $('.js-select-swimlanes')[0];
- const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
- const bSelect = $('.js-select-boards')[0];
- const boardId = bSelect.options[bSelect.selectedIndex].value;
- const textarea = $('#copy-card-title');
- const title = textarea.val().trim();
- // insert new card to the bottom of new list
- card.sort = Lists.findOne(card.listId)
- .cards()
- .count();
- if (title) {
- card.title = title;
- card.coverId = '';
- const _id = card.copy(boardId, swimlaneId, listId);
- // In case the filter is active we need to add the newly inserted card in
- // the list of exceptions -- cards that are not filtered. Otherwise the
- // card will disappear instantly.
- // See https://github.com/wekan/wekan/issues/80
- Filter.addException(_id);
- Popup.close();
- }
- },
- });
- Template.copyChecklistToManyCardsPopup.events({
- 'click .js-done'() {
- const card = Cards.findOne(Session.get('currentCard'));
- const oldId = card._id;
- card._id = null;
- const lSelect = $('.js-select-lists')[0];
- card.listId = lSelect.options[lSelect.selectedIndex].value;
- const slSelect = $('.js-select-swimlanes')[0];
- card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
- const bSelect = $('.js-select-boards')[0];
- card.boardId = bSelect.options[bSelect.selectedIndex].value;
- const textarea = $('#copy-card-title');
- const titleEntry = textarea.val().trim();
- // insert new card to the bottom of new list
- card.sort = Lists.findOne(card.listId)
- .cards()
- .count();
- if (titleEntry) {
- const titleList = JSON.parse(titleEntry);
- for (let i = 0; i < titleList.length; i++) {
- const obj = titleList[i];
- card.title = obj.title;
- card.description = obj.description;
- card.coverId = '';
- const _id = Cards.insert(card);
- // In case the filter is active we need to add the newly inserted card in
- // the list of exceptions -- cards that are not filtered. Otherwise the
- // card will disappear instantly.
- // See https://github.com/wekan/wekan/issues/80
- Filter.addException(_id);
- // copy checklists
- Checklists.find({ cardId: oldId }).forEach(ch => {
- ch.copy(_id);
- });
- // copy subtasks
- cursor = Cards.find({ parentId: oldId });
- cursor.forEach(function() {
- 'use strict';
- const subtask = arguments[0];
- subtask.parentId = _id;
- subtask._id = null;
- /* const newSubtaskId = */ Cards.insert(subtask);
- });
- // copy card comments
- CardComments.find({ cardId: oldId }).forEach(cmt => {
- cmt.copy(_id);
- });
- }
- Popup.close();
- }
- },
- });
- BlazeComponent.extendComponent({
- onCreated() {
- this.currentCard = this.currentData();
- this.currentColor = new ReactiveVar(this.currentCard.color);
- },
- colors() {
- return cardColors.map(color => ({ color, name: '' }));
- },
- isSelected(color) {
- if (this.currentColor.get() === null) {
- return color === 'white';
- }
- return this.currentColor.get() === color;
- },
- events() {
- return [
- {
- 'click .js-palette-color'() {
- this.currentColor.set(this.currentData().color);
- },
- 'click .js-submit'() {
- this.currentCard.setColor(this.currentColor.get());
- Popup.close();
- },
- 'click .js-remove-color'() {
- this.currentCard.setColor(null);
- Popup.close();
- },
- },
- ];
- },
- }).register('setCardColorPopup');
- BlazeComponent.extendComponent({
- onCreated() {
- this.currentCard = this.currentData();
- this.parentBoard = new ReactiveVar(null);
- this.parentCard = this.currentCard.parentCard();
- if (this.parentCard) {
- const list = $('.js-field-parent-card');
- list.val(this.parentCard._id);
- this.parentBoard.set(this.parentCard.board()._id);
- } else {
- this.parentBoard.set(null);
- }
- },
- boards() {
- const boards = Boards.find(
- {
- archived: false,
- 'members.userId': Meteor.userId(),
- _id: {
- $ne: Meteor.user().getTemplatesBoardId(),
- },
- },
- {
- sort: ['title'],
- },
- );
- return boards;
- },
- cards() {
- const currentId = Session.get('currentCard');
- if (this.parentBoard.get()) {
- return Cards.find({
- boardId: this.parentBoard.get(),
- _id: { $ne: currentId },
- });
- } else {
- return [];
- }
- },
- isParentBoard() {
- const board = this.currentData();
- if (this.parentBoard.get()) {
- return board._id === this.parentBoard.get();
- }
- return false;
- },
- isParentCard() {
- const card = this.currentData();
- if (this.parentCard) {
- return card._id === this.parentCard;
- }
- return false;
- },
- setParentCardId(cardId) {
- if (cardId) {
- this.parentCard = Cards.findOne(cardId);
- } else {
- this.parentCard = null;
- }
- this.currentCard.setParentId(cardId);
- },
- events() {
- return [
- {
- 'click .js-copy-card-link-to-clipboard'() {
- // Clipboard code from:
- // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
- const StringToCopyElement = document.getElementById('cardURL');
- StringToCopyElement.select();
- if (document.execCommand('copy')) {
- StringToCopyElement.blur();
- } else {
- document.getElementById('cardURL').selectionStart = 0;
- document.getElementById('cardURL').selectionEnd = 999;
- document.execCommand('copy');
- if (window.getSelection) {
- if (window.getSelection().empty) {
- // Chrome
- window.getSelection().empty();
- } else if (window.getSelection().removeAllRanges) {
- // Firefox
- window.getSelection().removeAllRanges();
- }
- } else if (document.selection) {
- // IE?
- document.selection.empty();
- }
- }
- },
- 'click .js-delete': Popup.afterConfirm('cardDelete', function() {
- Popup.close();
- Cards.remove(this._id);
- Utils.goBoardId(this.boardId);
- }),
- 'change .js-field-parent-board'(event) {
- const selection = $(event.currentTarget).val();
- const list = $('.js-field-parent-card');
- if (selection === 'none') {
- this.parentBoard.set(null);
- } else {
- subManager.subscribe('board', $(event.currentTarget).val(), false);
- this.parentBoard.set(selection);
- list.prop('disabled', false);
- }
- this.setParentCardId(null);
- },
- 'change .js-field-parent-card'(event) {
- const selection = $(event.currentTarget).val();
- this.setParentCardId(selection);
- },
- },
- ];
- },
- }).register('cardMorePopup');
- // Close the card details pane by pressing escape
- EscapeActions.register(
- 'detailsPane',
- () => {
- Utils.goBoardId(Session.get('currentBoard'));
- },
- () => {
- return !Session.equals('currentCard', null);
- },
- {
- noClickEscapeOn: '.js-card-details,.board-sidebar,#header',
- },
- );
|