Fix 'operator' error in projector view.

Move operator factory from users/site.js to users/base.js.
The Motion factory uses 'operator' in motions/base.js which is also
loaded on projector. So operator is required in users/base.js.
This commit is contained in:
Emanuel Schuetze 2015-11-23 22:01:30 +01:00
parent f26188e0ff
commit 9af302ce36
4 changed files with 51 additions and 52 deletions

View File

@ -2,7 +2,7 @@
"use strict"; "use strict";
angular.module('OpenSlidesApp.motions', []) angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
.factory('WorkflowState', [ .factory('WorkflowState', [
'DS', 'DS',

View File

@ -316,7 +316,6 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
'$scope', '$scope',
'$state', '$state',
'gettext', 'gettext',
'operator',
'Motion', 'Motion',
'MotionFormFieldFactory', 'MotionFormFieldFactory',
'Category', 'Category',
@ -325,7 +324,7 @@ angular.module('OpenSlidesApp.motions.site', ['OpenSlidesApp.motions'])
'Tag', 'Tag',
'User', 'User',
'Workflow', 'Workflow',
function($scope, $state, gettext, operator, Motion, MotionFormFieldFactory, Category, Config, Mediafile, Tag, User, Workflow) { function($scope, $state, gettext, Motion, MotionFormFieldFactory, Category, Config, Mediafile, Tag, User, Workflow) {
Category.bindAll({}, $scope, 'categories'); Category.bindAll({}, $scope, 'categories');
Mediafile.bindAll({}, $scope, 'mediafiles'); Mediafile.bindAll({}, $scope, 'mediafiles');
Tag.bindAll({}, $scope, 'tags'); Tag.bindAll({}, $scope, 'tags');

View File

@ -4,6 +4,55 @@
angular.module('OpenSlidesApp.users', []) angular.module('OpenSlidesApp.users', [])
.factory('operator', [
'User',
'Group',
'loadGlobalData',
function(User, Group, loadGlobalData) {
var operatorChangeCallbacks = [];
var operator = {
user: null,
perms: [],
isAuthenticated: function () {
return !!this.user;
},
onOperatorChange: function (func) {
operatorChangeCallbacks.push(func);
},
setUser: function(user_id) {
if (user_id) {
User.find(user_id).then(function(user) {
operator.user = user;
// TODO: load only the needed groups
Group.findAll().then(function() {
operator.perms = user.getPerms();
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
});
});
} else {
operator.user = null;
Group.find(1).then(function(group) {
operator.perms = group.permissions;
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
});
}
},
// Returns true if the operator has at least one perm of the perms-list.
hasPerms: function(perms) {
if (typeof perms == 'string') {
perms = perms.split(' ');
}
return _.intersection(perms, operator.perms).length > 0;
},
};
return operator;
}
])
.factory('User', ['DS', 'Group', 'jsDataModel', function(DS, Group, jsDataModel) { .factory('User', ['DS', 'Group', 'jsDataModel', function(DS, Group, jsDataModel) {
var name = 'users/user'; var name = 'users/user';
return DS.defineResource({ return DS.defineResource({

View File

@ -119,55 +119,6 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
}); });
}) })
.factory('operator', [
'User',
'Group',
'loadGlobalData',
function(User, Group, loadGlobalData) {
var operatorChangeCallbacks = [];
var operator = {
user: null,
perms: [],
isAuthenticated: function () {
return !!this.user;
},
onOperatorChange: function (func) {
operatorChangeCallbacks.push(func);
},
setUser: function(user_id) {
if (user_id) {
User.find(user_id).then(function(user) {
operator.user = user;
// TODO: load only the needed groups
Group.findAll().then(function() {
operator.perms = user.getPerms();
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
});
});
} else {
operator.user = null;
Group.find(1).then(function(group) {
operator.perms = group.permissions;
_.forEach(operatorChangeCallbacks, function (callback) {
callback();
});
});
}
},
// Returns true if the operator has at least one perm of the perms-list.
hasPerms: function(perms) {
if (typeof perms == 'string') {
perms = perms.split(' ');
}
return _.intersection(perms, operator.perms).length > 0;
},
};
return operator;
}
])
.run([ .run([
'operator', 'operator',
'$rootScope', '$rootScope',