From 4b8fc5fa198ace69f51c2dc67c5f01ba6ec31e14 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 11 Nov 2016 09:57:54 +0100 Subject: [PATCH] Highlighting motions for multiprojector and move httpProvider (fixes #2590) --- openslides/core/static/js/core/base.js | 9 ++++ openslides/core/static/js/core/site.js | 9 ---- .../motions/static/js/motions/projector.js | 42 +++---------------- openslides/motions/static/js/motions/site.js | 20 +++++---- 4 files changed, 26 insertions(+), 54 deletions(-) diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 70045efaa..f3078a1fc 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -15,6 +15,15 @@ angular.module('OpenSlidesApp.core', [ 'OpenSlidesApp-templates', ]) +.config([ + '$httpProvider', + function($httpProvider) { + // Combine the django csrf system with the angular csrf system + $httpProvider.defaults.xsrfCookieName = 'csrftoken'; + $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; + } +]) + .config([ 'DSProvider', 'DSHttpAdapterProvider', diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 20aca611c..2db92e4e6 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -139,15 +139,6 @@ angular.module('OpenSlidesApp.core.site', [ } ]) -.config([ - '$httpProvider', - function($httpProvider) { - // Combine the django csrf system with the angular csrf system - $httpProvider.defaults.xsrfCookieName = 'csrftoken'; - $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; - } -]) - .config([ '$stateProvider', '$urlMatcherFactoryProvider', diff --git a/openslides/motions/static/js/motions/projector.js b/openslides/motions/static/js/motions/projector.js index b5054dc8e..e128cf614 100644 --- a/openslides/motions/static/js/motions/projector.js +++ b/openslides/motions/static/js/motions/projector.js @@ -25,45 +25,15 @@ angular.module('OpenSlidesApp.motions.projector', [ 'Config', 'Projector', '$timeout', - function($scope, $rootScope, $http, Motion, User, Config, Projector, $timeout) { + 'ProjectorID', + function($scope, $rootScope, $http, Motion, User, Config, Projector, $timeout, ProjectorID) { // Attention! Each object that is used here has to be dealt on server side. // Add it to the coresponding get_requirements method of the ProjectorElement // class. var id = $scope.element.id; + var thisProjector = Projector.get(ProjectorID()); $scope.line = $scope.element.highlightAndScroll; - - // get cookie using jQuery - var getCookie = function (name) { - var cookieValue = null; - if (document.cookie && document.cookie !== '') { - var cookies = document.cookie.split(';'); - for (var i = 0; i < cookies.length; i++) { - var cookie = jQuery.trim(cookies[i]); - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) == (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; - }; - - var scrollRequest = function (position) { - // request with csrf token - // TODO: Why is the X-CSRFToken not included in the header by default? - var csrfToken = getCookie('csrftoken'); - var request = { - method: 'POST', - url: '/rest/core/projector/1/set_scroll/', - data: position, - headers: { - 'X-CSRFToken': csrfToken - } - }; - $http(request); - }; $scope.scroll = function () { // Prevent getting in an infinite loop by updating only if the value has changed. // (if this check is removed this happends: controller loads --> call of $scope.scroll @@ -73,11 +43,11 @@ angular.module('OpenSlidesApp.motions.projector', [ var lineElement = document.getElementsByName('L' + $scope.line); if (lineElement[0]) { $rootScope.motion_projector_line = $scope.line; - var pos = lineElement[0].getBoundingClientRect().top + Projector.get(1).scroll*80; - scrollRequest(Math.floor(pos/80.0) - 1); + var pos = lineElement[0].getBoundingClientRect().top + thisProjector.scroll*80; + $http.post('/rest/core/projector/' + thisProjector.id + '/set_scroll/', Math.floor(pos/80.0) - 1); } else if ($scope.line === 0) { $rootScope.motion_projector_line = $scope.line; - scrollRequest(0); + $http.post('/rest/core/projector/' + thisProjector.id + '/set_scroll/', 0); } } }; diff --git a/openslides/motions/static/js/motions/site.js b/openslides/motions/static/js/motions/site.js index 4f0534610..6c491c7ff 100644 --- a/openslides/motions/static/js/motions/site.js +++ b/openslides/motions/static/js/motions/site.js @@ -1066,15 +1066,17 @@ angular.module('OpenSlidesApp.motions.site', [ $scope.linesForProjector = false; // Set 0 for disable highlighting on projector var setHighlightOnProjector = function (line) { - var elements = _.map(Projector.get(1).elements, function(element) { return element; }); - elements.forEach(function (element) { - if (element.name == 'motions/motion') { - var data = {}; - data[element.uuid] = { - highlightAndScroll: line, - }; - $http.post('/rest/core/projector/1/update_elements/', data); - } + _.forEach(Projector.getAll(), function (projector) { + var elements = _.map(projector.elements, function(element) { return element; }); + elements.forEach(function (element) { + if (element.name == 'motions/motion' && element.id == motion.id) { + var data = {}; + data[element.uuid] = { + highlightAndScroll: line, + }; + $http.post('/rest/core/projector/' + projector.id + '/update_elements/', data); + } + }); }); }; $scope.scrollToAndHighlight = function (line) {