diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index 9d6ab1266..58c2ca1b4 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -116,21 +116,6 @@ class MotionPollSerializer(ModelSerializer): 'votes', 'has_votes') - def to_representation(self, obj): - """ - Overrides the output of this serializer. Replaces vote values -1 - through the translated string 'majority' and -2 through the - translated string 'undocumented'. - """ - result = super().to_representation(obj) - for key in result: - if key in ('yes', 'no', 'abstain', 'votesvalid', 'votesinvalid', 'votescast'): - if result[key] == -1: - result[key] = _('majority') - elif result[key] == -2: - result[key] = _('undocumented') - return result - def get_yes(self, obj): try: result = obj.get_votes().get(value='Yes').weight diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 3f399cf5c..5f880f2d1 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -52,8 +52,9 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users']) .factory('MotionPoll', [ 'DS', + 'gettextCatalog', 'Config', - function (DS, Config) { + function (DS, gettextCatalog, Config) { return DS.defineResource({ name: 'motions/motionpoll', relations: { @@ -65,92 +66,40 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users']) } }, methods: { - getYesPercent: function (valueOnly) { + // returns object with value and percent + getVote: function (vote) { + if (!this.has_votes || !vote) { + return; + } + var value = ''; + switch (vote) { + case -1: + value = gettextCatalog.getString('majority'); + break; + case -2: + value = gettextCatalog.getString('undocumented'); + break; + default: + value = vote; + break; + } + // calculate percent value var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITHOUT_INVALID" && this.votesvalid > 0 && this.yes >= 0) { - returnvalue = Math.round(this.yes * 100 / this.votesvalid * 10) / 10; - } else if (config == "WITH_INVALID" && this.votescast > 0 && this.yes >= 0) { - returnvalue = Math.round(this.yes * 100 / (this.votescast) * 10) / 10; - } else { - returnvalue = null; + var percentStr, percentNumber; + if (config == "WITHOUT_INVALID" && this.votesvalid > 0 && vote >= 0) { + percentNumber = Math.round(vote * 100 / this.votesvalid * 10) / 10; + } else if (config == "WITH_INVALID" && this.votescast > 0 && vote >= 0) { + percentNumber = Math.round(vote * 100 / (this.votescast) * 10) / 10; } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; + if (percentNumber) { + percentStr = "(" + percentNumber + "%)"; } - return returnvalue; + return { + 'value': value, + 'percentStr': percentStr, + 'percentNumber': percentNumber + }; }, - getNoPercent: function (valueOnly) { - var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITHOUT_INVALID" && this.votesvalid > 0 && this.no >= 0) { - returnvalue = Math.round(this.no * 100 / this.votesvalid * 10) / 10; - } else if (config == "WITH_INVALID" && this.votescast > 0 && this.no >= 0) { - returnvalue = Math.round(this.no * 100 / (this.votescast) * 10) / 10; - } else { - returnvalue = null; - } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; - } - return returnvalue; - }, - getAbstainPercent: function (valueOnly) { - var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITHOUT_INVALID" && this.votesvalid > 0 && this.abstain >= 0) { - returnvalue = Math.round(this.abstain * 100 / this.votesvalid * 10) / 10; - } else if (config == "WITH_INVALID" && this.votescast > 0 && this.abstain >= 0) { - returnvalue = Math.round(this.abstain * 100 / (this.votescast) * 10) / 10; - } else { - returnvalue = null; - } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; - } - return returnvalue; - }, - getVotesValidPercent: function (valueOnly) { - var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITHOUT_INVALID" && this.votevalid >= 0) { - returnvalue = 100; - } else if (config == "WITH_INVALID" && this.votevalid >= 0) { - returnvalue = Math.round(this.votesvalid * 100 / (this.votescast) * 10) / 10; - } else { - returnvalue = null; - } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; - } - return returnvalue; - }, - getVotesInvalidPercent: function (valueOnly) { - var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITH_INVALID" && this.voteinvalid >= 0) { - returnvalue = Math.round(this.votesinvalid * 100 / (this.votescast) * 10) / 10; - } else { - returnvalue = null; - } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; - } - return returnvalue; - }, - getVotesCastPercent: function (valueOnly) { - var config = Config.get('motions_poll_100_percent_base').value; - var returnvalue; - if (config == "WITH_INVALID" && this.votecast >= 0) { - returnvalue = 100; - } else { - returnvalue = null; - } - if (!valueOnly && returnvalue != null) { - returnvalue = "(" + returnvalue + "%)"; - } - return returnvalue; - } } }); } diff --git a/openslides/motions/static/templates/motions/motion-detail.html b/openslides/motions/static/templates/motions/motion-detail.html index db735b7b2..e71bb4659 100644 --- a/openslides/motions/static/templates/motions/motion-detail.html +++ b/openslides/motions/static/templates/motions/motion-detail.html @@ -138,53 +138,71 @@ - + Yes: - {{ poll.yes }} {{ poll.getYesPercent() }} -
- + + {{ voteYes.value }} {{ voteYes.percentStr }} + +
+
- + No: - {{ poll.no }} {{ poll.getNoPercent() }} -
- + + {{ voteNo.value }} {{ voteNo.percentStr }} + +
+
- + Abstain: - {{ poll.abstain }} {{ poll.getAbstainPercent() }} -
- + + {{ voteAbstain.value }} {{ voteAbstain.percentStr }} + +
+
- + Valid votes: - {{ poll.votesvalid }} {{ poll.getVotesValidPercent() }} + + {{ votesValid.value }} {{ votesValid.percentStr }} + - + Invalid votes: - {{ poll.votesinvalid }} {{ poll.getVotesInvalidPercent() }} + + {{ votesInvalid.value }} + + {{ votesInvalid.percentStr }} + + - + Votes cast: - {{ poll.votescast }} {{ poll.getVotesCastPercent() }} + + {{ votesCast.value }} + + {{ votesCast.percentStr }} + +