summaryrefslogtreecommitdiffstats
path: root/client/components/cards/cardDetails.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/components/cards/cardDetails.js')
-rw-r--r--client/components/cards/cardDetails.js120
1 files changed, 98 insertions, 22 deletions
diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js
index 271fbe2f..441068b0 100644
--- a/client/components/cards/cardDetails.js
+++ b/client/components/cards/cardDetails.js
@@ -54,21 +54,6 @@ BlazeComponent.extendComponent({
}
return null;
},
- votePublic() {
- const card = this.currentData();
- if (card.vote) return card.vote.public;
- return null;
- },
- voteCountPositive() {
- const card = this.currentData();
- if (card.vote && card.vote.positive) return card.vote.positive.length;
- return null;
- },
- voteCountNegative() {
- const card = this.currentData();
- if (card.vote && card.vote.negative) return card.vote.negative.length;
- return null;
- },
isWatching() {
const card = this.currentData();
return card.findWatcher(Meteor.userId());
@@ -148,6 +133,15 @@ BlazeComponent.extendComponent({
return result;
},
+ showVotingButtons() {
+ const card = this.currentData();
+ return (
+ (currentUser.isBoardMember() ||
+ (currentUser && card.voteAllowNonBoardMembers())) &&
+ !card.expiredVote()
+ );
+ },
+
onRendered() {
if (Meteor.settings.public.CARD_OPENED_WEBHOOK_ENABLED) {
// Send Webhook but not create Activities records ---
@@ -611,11 +605,6 @@ Template.cardDetailsActionsPopup.events({
'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-cancel-voting'(event) {
- event.preventDefault();
- this.unsetVote();
- Popup.close();
- },
'click .js-move-card-to-top'(event) {
event.preventDefault();
const minOrder = _.min(
@@ -967,7 +956,23 @@ BlazeComponent.extendComponent({
},
'click .js-delete': Popup.afterConfirm('cardDelete', function() {
Popup.close();
- Cards.remove(this._id);
+ // verify that there are no linked cards
+ if (Cards.find({ linkedId: this._id }).count() === 0) {
+ Cards.remove(this._id);
+ } else {
+ // TODO: Maybe later we can list where the linked cards are.
+ // Now here is popup with a hint that the card cannot be deleted
+ // as there are linked cards.
+ // Related:
+ // client/components/lists/listHeader.js about line 248
+ // https://github.com/wekan/wekan/issues/2785
+ const message = `${TAPi18n.__(
+ 'delete-linked-card-before-this-card',
+ )} linkedId: ${
+ this._id
+ } at client/components/cards/cardDetails.js and https://github.com/wekan/wekan/issues/2785`;
+ alert(message);
+ }
Utils.goBoardId(this.boardId);
}),
'change .js-field-parent-board'(event) {
@@ -1000,22 +1005,93 @@ BlazeComponent.extendComponent({
events() {
return [
{
+ 'click .js-end-date': Popup.open('editVoteEndDate'),
'submit .edit-vote-question'(evt) {
evt.preventDefault();
const voteQuestion = evt.target.vote.value;
const publicVote = $('#vote-public').hasClass('is-checked');
- this.currentCard.setVoteQuestion(voteQuestion, publicVote);
+ const allowNonBoardMembers = $('#vote-allow-non-members').hasClass(
+ 'is-checked',
+ );
+ const endString = this.currentCard.getVoteEnd();
+
+ this.currentCard.setVoteQuestion(
+ voteQuestion,
+ publicVote,
+ allowNonBoardMembers,
+ );
+ if (endString) {
+ this.currentCard.setVoteEnd(endString);
+ }
Popup.close();
},
+ 'click .js-remove-vote': Popup.afterConfirm('deleteVote', () => {
+ event.preventDefault();
+ this.currentCard.unsetVote();
+ Popup.close();
+ }),
'click a.js-toggle-vote-public'(event) {
event.preventDefault();
$('#vote-public').toggleClass('is-checked');
},
+ 'click a.js-toggle-vote-allow-non-members'(event) {
+ event.preventDefault();
+ $('#vote-allow-non-members').toggleClass('is-checked');
+ },
},
];
},
}).register('cardStartVotingPopup');
+// editVoteEndDatePopup
+(class extends DatePicker {
+ onCreated() {
+ super.onCreated(moment().format('YYYY-MM-DD HH:mm'));
+ this.data().getVoteEnd() && this.date.set(moment(this.data().getVoteEnd()));
+ }
+ events() {
+ return [
+ {
+ 'submit .edit-date'(evt) {
+ evt.preventDefault();
+
+ // if no time was given, init with 12:00
+ const time =
+ evt.target.time.value ||
+ moment(new Date().setHours(12, 0, 0)).format('LT');
+
+ const dateString = `${evt.target.date.value} ${time}`;
+ const newDate = moment(dateString, 'L LT', true);
+ if (newDate.isValid()) {
+ // if active vote - store it
+ if (this.currentData().getVoteQuestion()) {
+ this._storeDate(newDate.toDate());
+ Popup.close();
+ } else {
+ this.currentData().vote = { end: newDate.toDate() }; // set vote end temp
+ Popup.back();
+ }
+ } else {
+ this.error.set('invalid-date');
+ evt.target.date.focus();
+ }
+ },
+ 'click .js-delete-date'(evt) {
+ evt.preventDefault();
+ this._deleteDate();
+ Popup.close();
+ },
+ },
+ ];
+ }
+ _storeDate(newDate) {
+ this.card.setVoteEnd(newDate);
+ }
+ _deleteDate() {
+ this.card.unsetVoteEnd();
+ }
+}.register('editVoteEndDatePopup'));
+
// Close the card details pane by pressing escape
EscapeActions.register(
'detailsPane',