Highlighting motions for multiprojector and move httpProvider (fixes #2590)

This commit is contained in:
FinnStutzenstein 2016-11-11 09:57:54 +01:00
parent 22ab7a15a3
commit 4b8fc5fa19
4 changed files with 26 additions and 54 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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);
}
}
};

View File

@ -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) {