diff --git a/openslides/agenda/static/js/agenda/agenda.js b/openslides/agenda/static/js/agenda/agenda.js index 62d4868f9..7934cbd80 100644 --- a/openslides/agenda/static/js/agenda/agenda.js +++ b/openslides/agenda/static/js/agenda/agenda.js @@ -47,6 +47,19 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users']) angular.module('OpenSlidesApp.agenda.site', ['OpenSlidesApp.agenda']) +.config([ + 'mainMenuProvider', + function (mainMenuProvider) { + mainMenuProvider.register({ + 'ui_sref': 'agenda.item.list', + 'img_class': 'calendar-o', + 'title': 'Agenda', + 'weight': 200, + 'perm': 'agenda.can_see', + }); + } +]) + .config(function($stateProvider) { $stateProvider .state('agenda', { diff --git a/openslides/assignments/static/js/assignments/assignments.js b/openslides/assignments/static/js/assignments/assignments.js index 7eaef749c..c9f4ced1d 100644 --- a/openslides/assignments/static/js/assignments/assignments.js +++ b/openslides/assignments/static/js/assignments/assignments.js @@ -20,6 +20,19 @@ angular.module('OpenSlidesApp.assignments', []) angular.module('OpenSlidesApp.assignments.site', ['OpenSlidesApp.assignments']) +.config([ + 'mainMenuProvider', + function (mainMenuProvider) { + mainMenuProvider.register({ + 'ui_sref': 'assignments.assignment.list', + 'img_class': 'pie-chart', + 'title': 'Elections', + 'weight': 400, + 'perm': 'assignments.can_see' + }); + } +]) + .config(function($stateProvider) { $stateProvider .state('assignments', { diff --git a/openslides/core/static/js/core/core.js b/openslides/core/static/js/core/core.js index ad837df9e..6c72ed062 100644 --- a/openslides/core/static/js/core/core.js +++ b/openslides/core/static/js/core/core.js @@ -99,9 +99,15 @@ angular.module('OpenSlidesApp.core', [ } ]) -.run(['loadGlobalData', function(loadGlobalData) { - loadGlobalData(); -}]) +// Load the global data on startup and when the operator changes +.run([ + 'loadGlobalData', + 'operator', + function(loadGlobalData, operator) { + loadGlobalData(); + operator.onOperatorChange(loadGlobalData); + } +]) .factory('jsDataModel', ['$http', 'Projector', function($http, Projector) { var BaseModel = function() {}; @@ -176,6 +182,70 @@ angular.module('OpenSlidesApp.core.site', [ 'xeditable', ]) +// Provider to register entries for the main menu. +.provider('mainMenu', [ + function() { + var mainMenuList = []; + var scope; + + this.register = function(config) { + mainMenuList.push(config); + }; + + this.$get = ['operator', function(operator) { + return { + registerScope: function (scope) { + var that = this; + this.scope = scope; + this.updateMainMenu(); + operator.onOperatorChange(function () {that.updateMainMenu()}); + }, + updateMainMenu: function () { + this.scope.elements = this.getElements(); + }, + getElements: function() { + var elements = mainMenuList.filter(function (element) { + return typeof element.perm === "undefined" || operator.hasPerms(element.perm); + }); + + elements.sort(function (a, b) { + return a.weight - b.weight; + }); + return elements; + } + } + }]; + } +]) + +.config([ + 'mainMenuProvider', + function (mainMenuProvider) { + mainMenuProvider.register({ + 'ui_sref': 'dashboard', + 'img_class': 'home', + 'title': 'Home', + 'weight': 100, + }); + + mainMenuProvider.register({ + 'ui_sref': 'core.customslide.list', + 'img_class': 'video-camera', + 'title': 'Projector', + 'weight': 110, + 'perm': 'core.can_see_projector', + }); + + mainMenuProvider.register({ + 'ui_sref': 'config', + 'img_class': 'cog', + 'title': 'Settings', + 'weight': 1000, + 'perm': 'core.can_manage_config', + }); + } +]) + .config(function($urlRouterProvider, $locationProvider) { // define fallback url and html5Mode $urlRouterProvider.otherwise('/'); @@ -419,6 +489,14 @@ angular.module('OpenSlidesApp.core.site', [ } }) +.controller("MainMenuCtrl", [ + '$scope', + 'mainMenu', + function ($scope, mainMenu) { + mainMenu.registerScope($scope); + } +]) + .controller("LanguageCtrl", function ($scope, gettextCatalog) { // controller to switch app language // TODO: detect browser language for default language @@ -449,8 +527,7 @@ angular.module('OpenSlidesApp.core.site', [ '$modalInstance', '$http', 'operator', - 'loadGlobalData', - function ($scope, $modalInstance, $http, operator, loadGlobalData) { + function ($scope, $modalInstance, $http, operator) { $scope.login = function () { $http.post( '/users/login/', @@ -458,7 +535,6 @@ angular.module('OpenSlidesApp.core.site', [ ).success(function(data) { if (data.success) { operator.setUser(data.user_id); - loadGlobalData(); $scope.loginFailed = false; $modalInstance.close(); } else { diff --git a/openslides/core/static/templates/index.html b/openslides/core/static/templates/index.html index 51af20959..11e7641ad 100644 --- a/openslides/core/static/templates/index.html +++ b/openslides/core/static/templates/index.html @@ -103,18 +103,21 @@
@@ -124,48 +127,12 @@