From 2bdaf85b674ddd926da3eb001ed2266d0bddbd81 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 17 Nov 2017 14:47:38 +0100 Subject: [PATCH] Give motions by id in state and recommendation. --- CHANGELOG | 1 + openslides/motions/static/js/motions/base.js | 51 +++++++++++-------- .../static/js/motions/motion-services.js | 4 +- openslides/motions/static/js/motions/site.js | 45 +++++++++------- .../templates/motions/motion-detail.html | 17 ++++++- 5 files changed, 74 insertions(+), 44 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 25fd3784b..b0af8d9a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,6 +49,7 @@ Motions: - Improved the multiselect state filter [#3459]. - Added karma:watch command [#3466]. - Show the number of next speakers in motion list view [#3470]. +- Reference to motions by id in state and recommendation special field [#3498]. Elections: - Added pagination for list view [#3393]. diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 6c1153c2a..96dde74f7 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -189,10 +189,34 @@ angular.module('OpenSlidesApp.motions', [ } ]) +.factory('MotionStateAndRecommendationParser', [ + 'DS', + 'gettextCatalog', + function (DS, gettextCatalog) { + return { + formatMotion: function (motion) { + return '[motion:' + motion.id + ']'; + }, + parse: function (recommendation) { + return recommendation.replace(/\[motion:(\d+)\]/g, function (match, id) { + var motion = DS.get('motions/motion', id); + if (motion) { + return motion.identifier ? motion.identifier : motion.getTitle(); + } else { + return gettextCatalog.getString(""); + } + }); + }, + }; + } +]) + + .factory('Motion', [ 'DS', '$http', 'MotionPoll', + 'MotionStateAndRecommendationParser', 'MotionChangeRecommendation', 'MotionComment', 'jsDataModel', @@ -204,7 +228,7 @@ angular.module('OpenSlidesApp.motions', [ 'OpenSlidesSettings', 'Projector', 'operator', - function(DS, $http, MotionPoll, MotionChangeRecommendation, MotionComment, jsDataModel, gettext, gettextCatalog, + function(DS, $http, MotionPoll, MotionStateAndRecommendationParser, MotionChangeRecommendation, MotionComment, jsDataModel, gettext, gettextCatalog, Config, lineNumberingService, diffService, OpenSlidesSettings, Projector, operator) { var name = 'motions/motion'; return DS.defineResource({ @@ -399,35 +423,33 @@ angular.module('OpenSlidesApp.motions', [ // depended by state and provided by a custom comment field getStateName: function () { var name = ''; - var additionalName = ''; if (this.state) { name = gettextCatalog.getString(this.state.name); if (this.state.show_state_extension_field) { // check motion comment fields for flag 'forState' var commentFieldForStateId = MotionComment.getFieldIdForFlag('forState'); if (commentFieldForStateId > -1) { - additionalName = ' ' + this.comments[commentFieldForStateId]; + name += ' ' + this.comments[commentFieldForStateId]; } } } - return name + additionalName; + return MotionStateAndRecommendationParser.parse(name); }, // full recommendation string - optional with custom recommendationextension // depended by state and provided by a custom comment field getRecommendationName: function () { var recommendation = ''; - var additionalName = ''; if (Config.get('motions_recommendations_by').value !== '' && this.recommendation) { recommendation = gettextCatalog.getString(this.recommendation.recommendation_label); if (this.recommendation.show_recommendation_extension_field) { // check motion comment fields for flag 'forRecommendation' var commentFieldForRecommendationId = MotionComment.getFieldIdForFlag('forRecommendation'); if (commentFieldForRecommendationId > -1) { - additionalName = ' ' + this.comments[commentFieldForRecommendationId]; + recommendation += ' ' + this.comments[commentFieldForRecommendationId]; } } } - return recommendation + additionalName; + return MotionStateAndRecommendationParser.parse(recommendation); }, // link name which is shown in search result getSearchResultName: function () { @@ -808,21 +830,6 @@ angular.module('OpenSlidesApp.motions', [ } ]) -.factory('MotionList', [ - function () { - return { - getList: function (items){ - var list = []; - _.each(items, function (item) { - list.push({ id: item.id, - item: item }); - }); - return list; - } - }; - } -]) - .factory('MotionChangeRecommendation', [ 'DS', 'Config', diff --git a/openslides/motions/static/js/motions/motion-services.js b/openslides/motions/static/js/motions/motion-services.js index 4c0ffb55b..4d8b3b40d 100644 --- a/openslides/motions/static/js/motions/motion-services.js +++ b/openslides/motions/static/js/motions/motion-services.js @@ -185,7 +185,7 @@ angular.module('OpenSlidesApp.motions.motionservices', ['OpenSlidesApp.motions', } ]) -.factory('ChangeRecommmendationCreate', [ +.factory('ChangeRecommendationCreate', [ 'ngDialog', 'ChangeRecommendationForm', function(ngDialog, ChangeRecommendationForm) { @@ -366,7 +366,7 @@ angular.module('OpenSlidesApp.motions.motionservices', ['OpenSlidesApp.motions', } ]) -.factory('ChangeRecommmendationView', [ +.factory('ChangeRecommendationView', [ 'Motion', 'MotionChangeRecommendation', 'Config', diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 155df53df..941817936 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -1230,8 +1230,9 @@ angular.module('OpenSlidesApp.motions.site', [ 'ngDialog', 'gettextCatalog', 'MotionForm', - 'ChangeRecommmendationCreate', - 'ChangeRecommmendationView', + 'ChangeRecommendationCreate', + 'ChangeRecommendationView', + 'MotionStateAndRecommendationParser', 'MotionChangeRecommendation', 'Motion', 'MotionComment', @@ -1253,11 +1254,11 @@ angular.module('OpenSlidesApp.motions.site', [ 'WebpageTitle', 'EditingWarning', function($scope, $http, $timeout, $window, $filter, operator, ngDialog, gettextCatalog, - MotionForm, ChangeRecommmendationCreate, ChangeRecommmendationView, - MotionChangeRecommendation, Motion, MotionComment, Category, Mediafile, Tag, User, - Workflow, Config, motionId, MotionInlineEditing, MotionCommentsInlineEditing, Editor, - Projector, ProjectionDefault, MotionBlock, MotionPdfExport, PersonalNoteManager, - WebpageTitle, EditingWarning) { + MotionForm, ChangeRecommendationCreate, ChangeRecommendationView, + MotionStateAndRecommendationParser, MotionChangeRecommendation, Motion, MotionComment, + Category, Mediafile, Tag, User, Workflow, Config, motionId, MotionInlineEditing, + MotionCommentsInlineEditing, Editor, Projector, ProjectionDefault, MotionBlock, + MotionPdfExport, PersonalNoteManager, WebpageTitle, EditingWarning) { var motion = Motion.get(motionId); Category.bindAll({}, $scope, 'categories'); Mediafile.bindAll({}, $scope, 'mediafiles'); @@ -1265,6 +1266,7 @@ angular.module('OpenSlidesApp.motions.site', [ User.bindAll({}, $scope, 'users'); Workflow.bindAll({}, $scope, 'workflows'); MotionBlock.bindAll({}, $scope, 'motionBlocks'); + Motion.bindAll({}, $scope, 'motions'); $scope.$watch(function () { return MotionChangeRecommendation.lastModified(); }, function () { @@ -1472,6 +1474,9 @@ angular.module('OpenSlidesApp.motions.site', [ motion['comment_' + $scope.commentFieldForRecommendationId] = recommendationExtension; $scope.save(motion); }; + $scope.addMotionToRecommendationField = function (motion) { + $scope.recommendationExtension += MotionStateAndRecommendationParser.formatMotion(motion); + }; // update recommendation $scope.updateRecommendation = function (recommendation_id) { $http.put('/rest/motions/motion/' + motion.id + '/set_recommendation/', {'recommendation': recommendation_id}); @@ -1645,11 +1650,11 @@ angular.module('OpenSlidesApp.motions.site', [ ); // Change recommendation creation functions - $scope.createChangeRecommendation = ChangeRecommmendationCreate; + $scope.createChangeRecommendation = ChangeRecommendationCreate; $scope.createChangeRecommendation.init($scope, motion); // Change recommendation viewing - $scope.viewChangeRecommendations = ChangeRecommmendationView; + $scope.viewChangeRecommendations = ChangeRecommendationView; $scope.viewChangeRecommendations.init($scope, Config.get('motions_recommendation_text_mode').value); // PDF creating functions @@ -2283,26 +2288,28 @@ angular.module('OpenSlidesApp.motions.site', [ '$scope', '$stateParams', '$http', - 'MotionList', 'Category', 'categoryId', 'Motion', 'ErrorMessage', - function($scope, $stateParams, $http, MotionList, Category, categoryId, Motion, ErrorMessage) { + function($scope, $stateParams, $http, Category, categoryId, Motion, ErrorMessage) { Category.bindOne(categoryId, $scope, 'category'); Motion.bindAll({}, $scope, 'motions'); $scope.filter = { category_id: categoryId, parent_id: null, orderBy: 'identifier' }; - $scope.$watch( - function () { - return Motion.lastModified(); - }, - function () { - $scope.items = MotionList.getList(Motion.filter($scope.filter)); - } - ); + $scope.$watch(function () { + return Motion.lastModified(); + }, function () { + var motions = Motion.filter($scope.filter); + $scope.items = _.map(motions, function (motion) { + return { + id: motion.id, + item: motion + }; + }); + }); $scope.alert = {}; // Numbers all motions in this category by the given order in $scope.items diff --git a/openslides/motions/static/templates/motions/motion-detail.html b/openslides/motions/static/templates/motions/motion-detail.html index 6f72b8338..eab9621e4 100644 --- a/openslides/motions/static/templates/motions/motion-detail.html +++ b/openslides/motions/static/templates/motions/motion-detail.html @@ -224,7 +224,7 @@ - @@ -232,6 +232,21 @@ + + + + + Motion + + + +