From 5069649e14f7323fb424eeaac4fdb69c846819da Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 9 Jan 2016 17:32:33 +0100 Subject: [PATCH] Fix autoupdate after auth Remove data after logout --- openslides/core/static/js/core/base.js | 57 ++++++++++++++---------- openslides/users/static/js/users/base.js | 9 +++- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 169a1aa66..623544a31 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -30,33 +30,42 @@ angular.module('OpenSlidesApp.core', [ DSHttpAdapterProvider.defaults.forceTrailingSlash = true; }]) -.factory('autoupdate', function() { - var url = location.origin + "/sockjs"; +.factory('autoupdate', [ + 'DS', + function (DS) { + var url = location.origin + "/sockjs"; + var socket; + var Autoupdate = { + socket: null, + message_receivers: [], + connect: function () { + var autoupdate = this; + socket = this.socket = new SockJS(url); - var Autoupdate = { - socket: null, - message_receivers: [], - connect: function() { - var autoupdate = this; - this.socket = new SockJS(url); - this.socket.onmessage = function(event) { - _.forEach(autoupdate.message_receivers, function(receiver) { - receiver(event.data); - }); - }; + this.socket.onmessage = function (event) { + _.forEach(autoupdate.message_receivers, function (receiver) { + receiver(event.data); + }); + }; - this.socket.onclose = function() { - setTimeout(autoupdate.connect, 5000); - }; - }, - on_message: function(receiver) { - this.message_receivers.push(receiver); - } - }; - Autoupdate.connect(); - return Autoupdate; -}) + this.socket.onclose = function () { + setTimeout(autoupdate.connect, 5000); + }; + }, + on_message: function (receiver) { + this.message_receivers.push(receiver); + }, + reconnect: function () { + socket.close(); + DS.clear(); + Autoupdate.connect(); + } + }; + Autoupdate.connect(); + return Autoupdate; + } +]) .run(['DS', 'autoupdate', function(DS, autoupdate) { autoupdate.on_message(function(data) { diff --git a/openslides/users/static/js/users/base.js b/openslides/users/static/js/users/base.js index 6f782e1fc..a09057c28 100644 --- a/openslides/users/static/js/users/base.js +++ b/openslides/users/static/js/users/base.js @@ -8,8 +8,9 @@ angular.module('OpenSlidesApp.users', []) 'User', 'Group', 'loadGlobalData', - function(User, Group, loadGlobalData) { - var operatorChangeCallbacks = []; + 'autoupdate', + function (User, Group, loadGlobalData, autoupdate) { + var operatorChangeCallbacks = [autoupdate.reconnect]; var operator = { user: null, perms: [], @@ -33,6 +34,10 @@ angular.module('OpenSlidesApp.users', []) }); } else { operator.user = null; + operator.perms = []; + _.forEach(operatorChangeCallbacks, function (callback) { + callback(); + }); Group.find(1).then(function(group) { operator.perms = group.permissions; _.forEach(operatorChangeCallbacks, function (callback) {