diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index fe2d0443b..3ce5f05dc 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -495,16 +495,25 @@ angular.module('OpenSlidesApp.motions', [ return false; } }, - // Overrides from jsDataModel factory + /* Overrides from jsDataModel factory. + * Also sets the projection mode if given; If not it projects in 'original' mode. */ project: function (projectorId, mode) { // if this object is already projected on projectorId, delete this element from this projector - var isProjectedIds = this.isProjected(mode); - _.forEach(isProjectedIds, function (id) { - $http.post('/rest/core/projector/' + id + '/clear_elements/'); + var isProjected = this.isProjectedWithMode(); + _.forEach(isProjected, function (mapping) { + $http.post('/rest/core/projector/' + mapping.projectorId + '/clear_elements/'); + }); + // Was there a projector with the same id and mode as the given id and mode? + // If not, project the motion. + var wasProjectedBefore = _.some(isProjected, function (mapping) { + var value = (mapping.projectorId === projectorId); + if (mode) { + value = value && (mapping.mode === mode); + } + return value; }); mode = mode || 'original'; - // Show the element, if it was not projected before on the given projector - if (_.indexOf(isProjectedIds, projectorId) === -1) { + if (!wasProjectedBefore) { return $http.post( '/rest/core/projector/' + projectorId + '/prune_elements/', [{name: name, @@ -531,6 +540,23 @@ angular.module('OpenSlidesApp.motions', [ }); return projectorIds; }, + /* returns a list of mappings between projector id and mode: + * [ {projectorId: 2, mode: 'original'}, ... ] */ + isProjectedWithMode: function () { + var self = this; + var mapping = []; + _.forEach(Projector.getAll(), function (projector) { + _.forEach(projector.elements, function (element) { + if (element.name === name && element.id === self.id) { + mapping.push({ + projectorId: projector.id, + mode: element.mode || 'original', + }); + } + }); + }); + return mapping; + }, }, relations: { belongsTo: { diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 9a593f671..0df4fafb5 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -1075,7 +1075,6 @@ angular.module('OpenSlidesApp.motions.site', [ .controller('MotionDetailCtrl', [ '$scope', '$http', - '$timeout', 'operator', 'ngDialog', 'MotionForm', @@ -1096,7 +1095,7 @@ angular.module('OpenSlidesApp.motions.site', [ 'MotionCommentsInlineEditing', 'Projector', 'ProjectionDefault', - function($scope, $http, $timeout, operator, ngDialog, MotionForm, + function($scope, $http, operator, ngDialog, MotionForm, ChangeRecommmendationCreate, ChangeRecommmendationView, MotionChangeRecommendation, MotionPDFExport, Motion, MotionComment, Category, Mediafile, Tag, User, Workflow, Config, motion, MotionInlineEditing, MotionCommentsInlineEditing, Projector, ProjectionDefault) { @@ -1138,35 +1137,25 @@ angular.module('OpenSlidesApp.motions.site', [ {mode: 'agreed', label: 'Resolution'}, ]; - var getProjectionMode = function () { - var projectedIds = motion.isProjected(); - if (projectedIds.length) { - var element = _.find(Projector.get(projectedIds[0]).elements, function (element) { - return element.name === 'motions/motion' && element.id === motion.id; - }); - var modeName = element.mode || 'original', mode; - _.forEach($scope.projectionModes, function (_mode) { - if (_mode.mode === modeName) { - mode = _mode; - } - }); - return mode || $scope.projectionModes[0]; - } else { - return $scope.projectionModes[0]; - } - }; - $scope.projectionMode = getProjectionMode(); - // TODO: Fix this timeout; check what mode is projected. + $scope.projectionMode = $scope.projectionModes[0]; + if (motion.isProjected().length) { + var modeMapping = motion.isProjectedWithMode(); + _.forEach($scope.projectionModes, function (mode) { + if (mode.mode === modeMapping[0].mode) { + $scope.projectionMode = mode; + } + }); + } $scope.setProjectionMode = function (mode) { $scope.projectionMode = mode; - - var projectedIds = motion.isProjected(); - _.forEach(projectedIds, function (id) { - motion.project(id, mode.mode); - $timeout(function () { - motion.project(id, mode.mode); - }, 100); - }); + var isProjected = motion.isProjectedWithMode(); + if (isProjected.length) { + _.forEach(isProjected, function (mapping) { + if (mapping.mode != mode.mode) { // change the mode if it is different + motion.project(mapping.projectorId, mode.mode); + } + }); + } }; $scope.commentsFields = Config.get('motions_comments').value; $scope.commentFieldForState = MotionComment.getFieldNameForFlag('forState');