From ee95af9acc1073073c86c31e6931484eeda03ed1 Mon Sep 17 00:00:00 2001 From: Finn Stutzenstein Date: Wed, 17 Aug 2016 12:26:27 +0200 Subject: [PATCH] Added a possibility to sort and renumber all motions in a category --- openslides/core/static/css/app.css | 8 +++ openslides/motions/static/js/motions/base.js | 15 +++++ openslides/motions/static/js/motions/site.js | 59 +++++++++++++++++++ .../templates/motions/category-list.html | 2 + .../templates/motions/category-sort.html | 34 +++++++++++ 5 files changed, 118 insertions(+) create mode 100644 openslides/motions/static/templates/motions/category-sort.html diff --git a/openslides/core/static/css/app.css b/openslides/core/static/css/app.css index 27ac93096..f6d2974d4 100644 --- a/openslides/core/static/css/app.css +++ b/openslides/core/static/css/app.css @@ -578,6 +578,14 @@ img { margin-right: 5px; } +.lead-div { + margin-bottom: 20px; +} + +.lead-div .lead { + margin-bottom: 0; +} + .italic { font-style: italic; } diff --git a/openslides/motions/static/js/motions/base.js b/openslides/motions/static/js/motions/base.js index 174cf9df1..69d7b8c1d 100644 --- a/openslides/motions/static/js/motions/base.js +++ b/openslides/motions/static/js/motions/base.js @@ -273,6 +273,21 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users']) } ]) +.factory('MotionList', [ + function () { + return { + getList: function (items){ + var list = []; + _.each(items, function (item) { + list.push({ id: item.id, + item: item }); + }); + return list; + } + }; + } +]) + .run([ 'Motion', 'Category', diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 8f4b0eaf0..c9ace08fb 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -153,6 +153,19 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions']) views: { '@motions.category': {} } + }) + .state('motions.category.sort', { + url: '/sort/{id}', + resolve: { + category: function(Category, $stateParams) { + return Category.find($stateParams.id); + }, + motions: function(Motion) { + return Motion.findAll(); + } + }, + controller: 'CategorySortCtrl', + templateUrl: 'static/templates/motions/category-sort.html' }); } ]) @@ -1065,6 +1078,52 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions']) } ]) +.controller('CategorySortCtrl', [ + '$scope', + '$stateParams', + '$http', + 'MotionList', + 'Category', + 'category', + 'Motion', + 'motions', + function($scope, $stateParams, $http, MotionList, Category, category, Motion, motions) { + Category.bindOne(category.id, $scope, 'category'); + Motion.bindAll({}, $scope, 'motions'); + $scope.filter = { category_id: category.id, + orderBy: 'identifier' }; + + $scope.$watch( + function () { + return Motion.lastModified(); + }, + function () { + $scope.items = MotionList.getTree(Motion.filter($scope.filter)); + } + ); + + $scope.alert = {}; + // Numbers all motions in this category by the given order in $scope.items + $scope.numbering = function () { + // Create a list of all motion ids in the current order. + var sorted_motions = []; + $scope.items.forEach(function (item) { + sorted_motions.push(item.item.id); + }); + + // renumber them + $http.post('/rest/motions/category/' + $scope.category.id + '/numbering/', + {'motions': sorted_motions} ) + .success(function(data) { + $scope.alert = { type: 'success', msg: data.detail, show: true }; + }) + .error(function(data) { + $scope.alert = { type: 'danger', msg: data.detail, show: true }; + }); + }; + } +]) + //mark all motions config strings for translation in javascript .config([ 'gettext', diff --git a/openslides/motions/static/templates/motions/category-list.html b/openslides/motions/static/templates/motions/category-list.html index 0b56b67ad..d9774e1ee 100644 --- a/openslides/motions/static/templates/motions/category-list.html +++ b/openslides/motions/static/templates/motions/category-list.html @@ -40,6 +40,8 @@ {{ category.name }}
+ + Sort | Edit | diff --git a/openslides/motions/static/templates/motions/category-sort.html b/openslides/motions/static/templates/motions/category-sort.html new file mode 100644 index 000000000..c4cdc5e2f --- /dev/null +++ b/openslides/motions/static/templates/motions/category-sort.html @@ -0,0 +1,34 @@ +
+
+ +

Category {{ category.name }}

+
+
+ +
+
+

+ Drag and drop motions to reorder the category and when finished, renumber them. +

+ + + Numbering + +
+ + {{ alert.msg }} + +
+
    +
  1. +
    + {{ item.item.identifier }}: {{ item.item.getTitle() }} +
    +
+
+