From fbc57cc23aa19d4fdd2f77b2f2543fcfe75a9d0d Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 5 Sep 2015 11:11:46 +0200 Subject: [PATCH] Reload config after login Fix errors by saving tags to motions --- openslides/core/static/js/core/core.js | 95 +++++++++++-------- .../motions/static/js/motions/motions.js | 56 ++++++----- 2 files changed, 90 insertions(+), 61 deletions(-) diff --git a/openslides/core/static/js/core/core.js b/openslides/core/static/js/core/core.js index fc735eda6..ad837df9e 100644 --- a/openslides/core/static/js/core/core.js +++ b/openslides/core/static/js/core/core.js @@ -74,22 +74,33 @@ angular.module('OpenSlidesApp.core', [ }); }]) -.run(['$rootScope', 'Config', 'Projector', function($rootScope, Config, Projector) { - // Puts the config object into each scope. - Config.findAll().then(function() { - $rootScope.config = function(key) { - try { - return Config.get(key).value; - } - catch(err) { - console.log("Unkown config key: " + key); - return '' - } - } - }); +.factory('loadGlobalData', [ + '$rootScope', + 'Config', + 'Projector', + function ($rootScope, Config, Projector) { + return function () { + // Puts the config object into each scope. + Config.findAll().then(function() { + $rootScope.config = function(key) { + try { + return Config.get(key).value; + } + catch(err) { + console.log("Unkown config key: " + key); + return '' + } + } + }); - // Loads all projector data - Projector.findAll(); + // Loads all projector data + Projector.findAll(); + } + } +]) + +.run(['loadGlobalData', function(loadGlobalData) { + loadGlobalData(); }]) .factory('jsDataModel', ['$http', 'Projector', function($http, Projector) { @@ -433,31 +444,39 @@ angular.module('OpenSlidesApp.core.site', [ } }) -.controller('LoginFormModalCtrl', function ($scope, $modalInstance, $http, operator) { - $scope.login = function () { - $http.post( - '/users/login/', - {'username': $scope.username, 'password': $scope.password} - ).success(function(data) { - if (data.success) { - operator.setUser(data.user_id); - $scope.loginFailed = false; - $modalInstance.close(); - } else { - $scope.loginFailed = true; - } - }); - }; - $scope.guest = function () { - $modalInstance.dismiss('cancel'); - }; - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; -}) +.controller('LoginFormModalCtrl', [ + '$scope', + '$modalInstance', + '$http', + 'operator', + 'loadGlobalData', + function ($scope, $modalInstance, $http, operator, loadGlobalData) { + $scope.login = function () { + $http.post( + '/users/login/', + {'username': $scope.username, 'password': $scope.password} + ).success(function(data) { + if (data.success) { + operator.setUser(data.user_id); + loadGlobalData(); + $scope.loginFailed = false; + $modalInstance.close(); + } else { + $scope.loginFailed = true; + } + }); + }; + $scope.guest = function () { + $modalInstance.dismiss('cancel'); + }; + $scope.cancel = function () { + $modalInstance.dismiss('cancel'); + }; + } +]) // Version Controller -.controller('VersionCtrl', function($scope, $http) { +.controller('VersionCtrl', function ($scope, $http) { $http.get('/core/version/').success(function(data) { $scope.core_version = data.openslides_version; $scope.plugins = data.plugins; diff --git a/openslides/motions/static/js/motions/motions.js b/openslides/motions/static/js/motions/motions.js index abc108517..41abff805 100644 --- a/openslides/motions/static/js/motions/motions.js +++ b/openslides/motions/static/js/motions/motions.js @@ -248,31 +248,41 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions']) }; }) -.controller('MotionUpdateCtrl', - function($scope, $state, $http, Motion, Agenda, User, Category, Workflow, Tag, Mediafile, motion) { - Agenda.bindAll({}, $scope, 'items'); - User.bindAll({}, $scope, 'users'); - Category.bindAll({}, $scope, 'categories'); - Workflow.bindAll({}, $scope, 'workflows'); - Tag.bindAll({}, $scope, 'tags'); - Mediafile.bindAll({}, $scope, 'mediafiles'); +.controller('MotionUpdateCtrl', [ + '$scope', + '$state', + '$http', + 'Motion', + 'Agenda', + 'User', + 'Category', + 'Workflow', + 'Tag', + 'Mediafile', + 'motion', + function ($scope, $state, $http, Motion, Agenda, User, Category, Workflow, Tag, Mediafile, motion) { + Agenda.bindAll({}, $scope, 'items'); + User.bindAll({}, $scope, 'users'); + Category.bindAll({}, $scope, 'categories'); + Workflow.bindAll({}, $scope, 'workflows'); + Tag.bindAll({}, $scope, 'tags'); + Mediafile.bindAll({}, $scope, 'mediafiles'); - $scope.motion = motion; - // get latest version for edit - $scope.motion.title = $scope.motion.getTitle(-1); - $scope.motion.text = $scope.motion.getText(-1); - $scope.motion.reason = $scope.motion.getReason(-1); + $scope.motion = motion; + // get latest version for edit + $scope.motion.title = $scope.motion.getTitle(-1); + $scope.motion.text = $scope.motion.getText(-1); + $scope.motion.reason = $scope.motion.getReason(-1); - $scope.save = function (motion) { - motion.tags = []; // TODO: REST API should do it! (Bug in Django REST framework) - motion.attachments = []; // TODO: REST API should do it! (Bug in Django REST framework) - Motion.save(motion).then( - function(success) { - $state.go('motions.motion.list'); - } - ); - }; -}) + $scope.save = function (motion) { + Motion.save(motion).then( + function(success) { + $state.go('motions.motion.list'); + } + ); + }; + } +]) .controller('MotionCSVImportCtrl', function($scope, Motion) { // TODO