From 2495ba609b7d49c07f8b20ae2a41c188283255ac Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 13 Oct 2015 21:23:21 +0200 Subject: [PATCH] create MotionPoll in JS --- openslides/motions/serializers.py | 1 + .../motions/static/js/motions/motions.js | 50 ++++++++++++++++--- .../templates/motions/motion-detail.html | 6 +++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/openslides/motions/serializers.py b/openslides/motions/serializers.py index f86689280..67eddad0c 100644 --- a/openslides/motions/serializers.py +++ b/openslides/motions/serializers.py @@ -97,6 +97,7 @@ class MotionPollSerializer(ModelSerializer): model = MotionPoll fields = ( 'id', + 'motion', 'yes', 'no', 'abstain', diff --git a/openslides/motions/static/js/motions/motions.js b/openslides/motions/static/js/motions/motions.js index c08bc8cd3..0fa5f22a4 100644 --- a/openslides/motions/static/js/motions/motions.js +++ b/openslides/motions/static/js/motions/motions.js @@ -2,10 +2,20 @@ angular.module('OpenSlidesApp.motions', []) +.factory('MotionPoll', [ + 'DS', + function(DS) { + return DS.defineResource({ + name: 'motions/motionpoll', + }); + } +]) + .factory('Motion', [ 'DS', + 'MotionPoll', 'jsDataModel', - function(DS, jsDataModel) { + function(DS, MotionPoll, jsDataModel) { var name = 'motions/motion' return DS.defineResource({ name: name, @@ -70,6 +80,10 @@ angular.module('OpenSlidesApp.motions', []) localKeys: 'supporters_id', } ], + 'motions/motionpoll': { + localField: 'polls', + foreignKey: 'motion_id', + } } } }); @@ -252,12 +266,34 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions']) }; }) -.controller('MotionDetailCtrl', function($scope, Motion, Category, User, motion) { - Motion.bindOne(motion.id, $scope, 'motion'); - Category.bindAll({}, $scope, 'categories'); - User.bindAll({}, $scope, 'users'); - Motion.loadRelations(motion); -}) +.controller('MotionDetailCtrl', [ + '$scope', + 'Motion', + 'Category', + 'User', + 'motion', + '$http', + function($scope, Motion, Category, User, motion, $http) { + Motion.bindOne(motion.id, $scope, 'motion'); + Category.bindAll({}, $scope, 'categories'); + User.bindAll({}, $scope, 'users'); + Motion.loadRelations(motion); + + $scope.create_poll = function () { + $http.post('/rest/motions/motion/' + motion.id + '/create_poll/', {}) + .success(function(data){ + $scope.alert.show = false; + }) + .error(function(data){ + $scope.alert = { type: 'danger', msg: data.detail, show: true }; + }); + } + + $scope.delete_poll = function (poll) { + poll.DSDestroy(); + } + } +]) .controller('MotionCreateCtrl', function($scope, $state, $http, Motion, Agenda, User, Category, Workflow, Tag, Mediafile) { diff --git a/openslides/motions/static/templates/motions/motion-detail.html b/openslides/motions/static/templates/motions/motion-detail.html index ef8e7e0cc..d9915a9f1 100644 --- a/openslides/motions/static/templates/motions/motion-detail.html +++ b/openslides/motions/static/templates/motions/motion-detail.html @@ -39,6 +39,12 @@ +Create Poll +
+ {{ poll.id }} + delete +
+

Text