Commit 8ed78a38 by Brian Jacobel Committed by GitHub

Fix TNL-5011 (#13031)

Vote button is now disabled for yourself, but count is still visible
parent 92010f00
...@@ -107,10 +107,10 @@ ...@@ -107,10 +107,10 @@
}, },
can_vote: { can_vote: {
enable: function() { enable: function() {
return this.$(".action-vote").closest(".actions-item").removeClass("is-hidden"); this.$('.action-vote').closest('.actions-item').removeClass('is-disabled');
}, },
disable: function() { disable: function() {
return this.$(".action-vote").closest(".actions-item").addClass("is-hidden"); this.$('.action-vote').closest('.actions-item').addClass('is-disabled');
} }
} }
}; };
...@@ -415,17 +415,19 @@ ...@@ -415,17 +415,19 @@
updates = { updates = {
upvoted_ids: (is_voting ? _.union : _.difference)(user.get('upvoted_ids'), [this.model.id]) upvoted_ids: (is_voting ? _.union : _.difference)(user.get('upvoted_ids'), [this.model.id])
}; };
return DiscussionUtil.updateWithUndo(user, updates, { if (!$(event.target.closest(".actions-item")).hasClass('is-disabled')) {
url: url, return DiscussionUtil.updateWithUndo(user, updates, {
type: "POST", url: url,
$elem: $(event.currentTarget) type: "POST",
}, gettext("We had some trouble saving your vote. Please try again.")).done(function() { $elem: $(event.currentTarget)
if (is_voting) { }, gettext("We had some trouble saving your vote. Please try again.")).done(function() {
return self.model.vote(); if (is_voting) {
} else { return self.model.vote();
return self.model.unvote(); } else {
} return self.model.unvote();
}); }
});
}
}; };
DiscussionContentShowView.prototype.togglePin = function(event) { DiscussionContentShowView.prototype.togglePin = function(event) {
......
...@@ -474,7 +474,7 @@ ...@@ -474,7 +474,7 @@
}); });
it("doesn't show voting button if can_vote ability is disabled", function() { it("doesn't show voting button if can_vote ability is disabled", function() {
this.view.render(); this.view.render();
return expect(this.view.$el.find(".action-vote").closest(".actions-item")).toHaveClass('is-hidden'); return expect(this.view.$el.find(".action-vote").closest(".actions-item")).toHaveClass('is-disabled');
}); });
}); });
}); });
......
...@@ -18,6 +18,28 @@ ...@@ -18,6 +18,28 @@
&.is-hidden { &.is-hidden {
display: none; display: none;
} }
&.is-disabled {
a {
pointer-events: none;
.action-icon {
display: none;
}
.action-label {
padding-right: 0px;
}
&:hover {
border-color: transparent;
.action-label {
color: $forum-color-active-text;
}
}
}
}
} }
.more-wrapper { .more-wrapper {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment