2015-07-06 09:19:42 +02:00
|
|
|
"use strict";
|
|
|
|
|
2015-02-08 14:57:02 +01:00
|
|
|
angular.module('OpenSlidesApp.users', [])
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-07-06 09:19:42 +02:00
|
|
|
.factory('User', ['DS', 'Group', 'jsDataModel', function(DS, Group, jsDataModel) {
|
2015-06-24 12:31:39 +02:00
|
|
|
var name = 'users/user'
|
2015-06-17 09:45:00 +02:00
|
|
|
return DS.defineResource({
|
2015-06-24 12:31:39 +02:00
|
|
|
name: name,
|
|
|
|
useClass: jsDataModel,
|
2015-06-17 09:45:00 +02:00
|
|
|
methods: {
|
2015-06-24 12:31:39 +02:00
|
|
|
getResourceName: function () {
|
|
|
|
return name;
|
|
|
|
},
|
2015-06-17 09:45:00 +02:00
|
|
|
get_short_name: function() {
|
|
|
|
// should be the same as in the python user model.
|
|
|
|
var firstName = _.trim(this.first_name),
|
|
|
|
lastName = _.trim(this.last_name),
|
|
|
|
name;
|
|
|
|
|
|
|
|
if (firstName && lastName) {
|
|
|
|
// TODO: check config
|
|
|
|
name = [firstName, lastName].join(' ');
|
|
|
|
} else {
|
|
|
|
name = firstName || lastName || this.username;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
},
|
2015-06-17 18:30:30 +02:00
|
|
|
get_full_name: function() {
|
|
|
|
// should be the same as in the python user model.
|
|
|
|
var firstName = _.trim(this.first_name),
|
|
|
|
lastName = _.trim(this.last_name),
|
|
|
|
structure_level = _.trim(this.structure_level),
|
|
|
|
name;
|
|
|
|
|
|
|
|
if (firstName && lastName) {
|
|
|
|
// TODO: check config
|
|
|
|
name = [firstName, lastName].join(' ');
|
2015-06-15 19:56:12 +02:00
|
|
|
} else {
|
|
|
|
name = firstName || lastName || this.username;
|
|
|
|
}
|
|
|
|
if (structure_level) {
|
|
|
|
name = name + " (" + structure_level + ")";
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
},
|
2015-06-17 09:45:00 +02:00
|
|
|
getPerms: function() {
|
|
|
|
var allPerms = [];
|
2015-06-30 20:04:14 +02:00
|
|
|
var allGroups = this.groups;
|
|
|
|
// Add registered group
|
|
|
|
allGroups.push(2);
|
|
|
|
_.forEach(allGroups, function(groupId) {
|
2015-06-17 09:45:00 +02:00
|
|
|
// Get group from server
|
|
|
|
Group.find(groupId);
|
|
|
|
// But do not work with the returned promise, because in
|
|
|
|
// this case this method can not be called in $watch
|
2015-07-06 09:19:42 +02:00
|
|
|
var group = Group.get(groupId);
|
2015-06-17 09:45:00 +02:00
|
|
|
if (group) {
|
|
|
|
_.forEach(group.permissions, function(perm) {
|
|
|
|
allPerms.push(perm);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return _.uniq(allPerms);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2015-07-06 09:19:42 +02:00
|
|
|
}])
|
2015-06-17 09:45:00 +02:00
|
|
|
|
2015-07-06 09:19:42 +02:00
|
|
|
.factory('Group', ['DS', function(DS) {
|
2015-06-17 09:45:00 +02:00
|
|
|
return DS.defineResource({
|
|
|
|
name: 'users/group',
|
|
|
|
});
|
2015-07-06 09:19:42 +02:00
|
|
|
}])
|
2015-06-17 09:45:00 +02:00
|
|
|
|
2015-07-06 09:19:42 +02:00
|
|
|
.run(['User', 'Group', function(User, Group) {}]);
|
2015-06-17 09:45:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|
|
|
|
2015-09-05 17:15:37 +02:00
|
|
|
.config([
|
|
|
|
'mainMenuProvider',
|
|
|
|
function (mainMenuProvider) {
|
|
|
|
mainMenuProvider.register({
|
|
|
|
'ui_sref': 'users.user.list',
|
|
|
|
'img_class': 'user',
|
|
|
|
'title': 'Participants',
|
|
|
|
'weight': 500,
|
|
|
|
'perm': 'users.can_see_name',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2015-02-08 14:57:02 +01:00
|
|
|
.config(function($stateProvider) {
|
|
|
|
$stateProvider
|
2015-02-14 10:10:08 +01:00
|
|
|
.state('users', {
|
|
|
|
url: '/users',
|
|
|
|
abstract: true,
|
|
|
|
template: "<ui-view/>",
|
|
|
|
})
|
|
|
|
.state('users.user', {
|
|
|
|
abstract: true,
|
|
|
|
template: "<ui-view/>",
|
|
|
|
})
|
|
|
|
.state('users.user.list', {
|
|
|
|
resolve: {
|
|
|
|
users: function(User) {
|
|
|
|
return User.findAll();
|
2015-01-30 11:58:36 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.user.create', {
|
|
|
|
resolve: {
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.user.detail', {
|
|
|
|
resolve: {
|
|
|
|
user: function(User, $stateParams) {
|
|
|
|
return User.find($stateParams.id);
|
2015-06-25 10:19:38 +02:00
|
|
|
},
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
2015-01-30 11:58:36 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.user.detail.update', {
|
|
|
|
views: {
|
|
|
|
'@users.user': {}
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
2015-09-04 18:26:48 +02:00
|
|
|
.state('users.user.detail.profile', {
|
|
|
|
views: {
|
|
|
|
'@users.user': {},
|
|
|
|
},
|
|
|
|
url: '/profile',
|
|
|
|
controller: 'UserProfileCtrl',
|
|
|
|
})
|
2015-06-24 15:04:40 +02:00
|
|
|
.state('users.user.import', {
|
|
|
|
url: '/import',
|
|
|
|
controller: 'UserImportCtrl',
|
2015-02-14 10:10:08 +01:00
|
|
|
})
|
|
|
|
// groups
|
|
|
|
.state('users.group', {
|
|
|
|
url: '/groups',
|
|
|
|
abstract: true,
|
|
|
|
template: "<ui-view/>",
|
|
|
|
})
|
|
|
|
.state('users.group.list', {
|
|
|
|
resolve: {
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.group.create', {
|
|
|
|
resolve: {
|
2015-03-09 15:40:54 +01:00
|
|
|
permissions: function($http) {
|
|
|
|
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' })
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.group.detail', {
|
|
|
|
resolve: {
|
|
|
|
group: function(Group, $stateParams) {
|
|
|
|
return Group.find($stateParams.id);
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('users.group.detail.update', {
|
|
|
|
views: {
|
|
|
|
'@users.group': {}
|
2015-03-09 15:40:54 +01:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
permissions: function($http) {
|
|
|
|
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' })
|
|
|
|
}
|
2015-02-14 10:10:08 +01:00
|
|
|
}
|
|
|
|
});
|
2015-02-08 14:57:02 +01:00
|
|
|
})
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-09-05 17:15:37 +02:00
|
|
|
.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();
|
|
|
|
});
|
|
|
|
});
|
2015-02-12 22:42:54 +01:00
|
|
|
});
|
2015-09-05 17:15:37 +02:00
|
|
|
} 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;
|
2015-02-12 22:42:54 +01:00
|
|
|
}
|
2015-09-05 17:15:37 +02:00
|
|
|
])
|
2015-02-12 22:42:54 +01:00
|
|
|
|
|
|
|
.run(function(operator, $rootScope, $http) {
|
|
|
|
// Put the operator into the root scope
|
|
|
|
$http.get('/users/whoami/').success(function(data) {
|
|
|
|
operator.setUser(data.user_id);
|
|
|
|
});
|
|
|
|
$rootScope.operator = operator;
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Directive to check for permissions
|
|
|
|
*
|
|
|
|
* This is the Code from angular.js ngIf.
|
|
|
|
*
|
|
|
|
* TODO: find a way not to copy the code.
|
|
|
|
*/
|
|
|
|
.directive('osPerms', ['$animate', function($animate) {
|
|
|
|
return {
|
|
|
|
multiElement: true,
|
|
|
|
transclude: 'element',
|
|
|
|
priority: 600,
|
|
|
|
terminal: true,
|
|
|
|
restrict: 'A',
|
|
|
|
$$tlb: true,
|
|
|
|
link: function($scope, $element, $attr, ctrl, $transclude) {
|
|
|
|
var block, childScope, previousElements, perms;
|
|
|
|
if ($attr.osPerms[0] === '!') {
|
|
|
|
perms = _.trimLeft($attr.osPerms, '!')
|
|
|
|
} else {
|
|
|
|
perms = $attr.osPerms;
|
|
|
|
}
|
|
|
|
$scope.$watch(
|
|
|
|
function (scope) {
|
|
|
|
return scope.operator.hasPerms(perms);
|
|
|
|
},
|
|
|
|
function (value) {
|
|
|
|
if ($attr.osPerms[0] === '!') {
|
|
|
|
value = !value;
|
|
|
|
}
|
|
|
|
if (value) {
|
|
|
|
if (!childScope) {
|
|
|
|
$transclude(function(clone, newScope) {
|
|
|
|
childScope = newScope;
|
|
|
|
clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
|
|
|
|
// Note: We only need the first/last node of the cloned nodes.
|
|
|
|
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
|
|
|
|
// by a directive with templateUrl when its template arrives.
|
|
|
|
block = {
|
|
|
|
clone: clone
|
|
|
|
};
|
|
|
|
$animate.enter(clone, $element.parent(), $element);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (previousElements) {
|
|
|
|
previousElements.remove();
|
|
|
|
previousElements = null;
|
|
|
|
}
|
|
|
|
if (childScope) {
|
|
|
|
childScope.$destroy();
|
|
|
|
childScope = null;
|
|
|
|
}
|
|
|
|
if (block) {
|
|
|
|
previousElements = getBlockNodes(block.clone);
|
|
|
|
$animate.leave(previousElements).then(function() {
|
|
|
|
previousElements = null;
|
|
|
|
});
|
|
|
|
block = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
|
|
|
|
2015-09-05 19:12:04 +02:00
|
|
|
/*
|
|
|
|
* Like osPermsLite but does only hide the DOM-Elements
|
|
|
|
*
|
|
|
|
* This is the Code from angular.js ngShow.
|
|
|
|
*/
|
|
|
|
.directive('osPermsLite', [
|
|
|
|
'$animate',
|
|
|
|
function($animate) {
|
|
|
|
var NG_HIDE_CLASS = 'ng-hide';
|
|
|
|
var NG_HIDE_IN_PROGRESS_CLASS = 'ng-hide-animate';
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
multiElement: true,
|
|
|
|
link: function(scope, element, $attr) {
|
|
|
|
var perms;
|
|
|
|
if ($attr.osPermsLite[0] === '!') {
|
|
|
|
perms = _.trimLeft($attr.osPermsLite, '!')
|
|
|
|
} else {
|
|
|
|
perms = $attr.osPermsLite;
|
|
|
|
}
|
|
|
|
scope.$watch(
|
|
|
|
function (scope) {
|
|
|
|
return scope.operator.hasPerms(perms);
|
|
|
|
}, function ngShowWatchAction(value) {
|
|
|
|
if ($attr.osPermsLite[0] === '!') {
|
|
|
|
value = !value;
|
|
|
|
}
|
|
|
|
// we're adding a temporary, animation-specific class for ng-hide since this way
|
|
|
|
// we can control when the element is actually displayed on screen without having
|
|
|
|
// to have a global/greedy CSS selector that breaks when other animations are run.
|
|
|
|
// Read: https://github.com/angular/angular.js/issues/9103#issuecomment-58335845
|
|
|
|
$animate[value ? 'removeClass' : 'addClass'](element, NG_HIDE_CLASS, {
|
|
|
|
tempClasses: NG_HIDE_IN_PROGRESS_CLASS
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2015-10-15 17:27:59 +02:00
|
|
|
.controller('UserListCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'User',
|
|
|
|
'Group',
|
|
|
|
function($scope, $state, User, Group) {
|
|
|
|
User.bindAll({}, $scope, 'users');
|
|
|
|
Group.bindAll({}, $scope, 'groups');
|
2015-03-09 15:40:54 +01:00
|
|
|
|
2015-10-15 17:27:59 +02:00
|
|
|
// setup table sorting
|
|
|
|
$scope.sortColumn = 'first_name'; //TODO: sort by first OR last name
|
|
|
|
$scope.filterPresent = '';
|
|
|
|
$scope.reverse = false;
|
|
|
|
// function to sort by clicked column
|
|
|
|
$scope.toggleSort = function ( column ) {
|
|
|
|
if ( $scope.sortColumn === column ) {
|
|
|
|
$scope.reverse = !$scope.reverse;
|
|
|
|
}
|
|
|
|
$scope.sortColumn = column;
|
|
|
|
};
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-10-15 17:27:59 +02:00
|
|
|
// open detail view link
|
|
|
|
$scope.openDetail = function (id) {
|
|
|
|
$state.go('users.user.detail', {id: id});
|
|
|
|
};
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-10-15 17:27:59 +02:00
|
|
|
// save changed user
|
|
|
|
$scope.togglePresent = function (user) {
|
|
|
|
//the value was changed by the template (checkbox)
|
|
|
|
User.save(user);
|
|
|
|
};
|
|
|
|
|
|
|
|
// *** delete mode functions ***
|
|
|
|
$scope.isDeleteMode = false;
|
|
|
|
// check all checkboxes
|
|
|
|
$scope.checkAll = function () {
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
user.selected = $scope.selectedAll;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
// uncheck all checkboxes if isDeleteMode is closed
|
|
|
|
$scope.uncheckAll = function () {
|
|
|
|
if (!$scope.isDeleteMode) {
|
|
|
|
$scope.selectedAll = false;
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
user.selected = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// delete selected user
|
|
|
|
$scope.delete = function () {
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
if (user.selected)
|
|
|
|
User.destroy(user.id);
|
|
|
|
});
|
|
|
|
$scope.isDeleteMode = false;
|
|
|
|
$scope.uncheckAll();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-06-25 10:19:38 +02:00
|
|
|
.controller('UserDetailCtrl', function($scope, User, user, Group) {
|
2015-02-13 23:23:48 +01:00
|
|
|
User.bindOne(user.id, $scope, 'user');
|
2015-06-25 10:19:38 +02:00
|
|
|
Group.bindAll({}, $scope, 'groups');
|
2015-01-30 11:58:36 +01:00
|
|
|
})
|
|
|
|
|
2015-02-08 22:37:55 +01:00
|
|
|
.controller('UserCreateCtrl', function($scope, $state, User, Group) {
|
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
2015-01-30 11:58:36 +01:00
|
|
|
$scope.user = {};
|
|
|
|
$scope.save = function (user) {
|
2015-06-24 15:04:40 +02:00
|
|
|
if (!user.groups) {
|
|
|
|
user.groups = [];
|
|
|
|
}
|
2015-02-08 22:37:55 +01:00
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
|
|
|
$state.go('users.user.list');
|
|
|
|
}
|
|
|
|
);
|
2015-01-30 11:58:36 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2015-02-08 22:37:55 +01:00
|
|
|
.controller('UserUpdateCtrl', function($scope, $state, User, user, Group) {
|
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
|
|
|
$scope.user = user; // autoupdate is not activated
|
|
|
|
$scope.save = function (user) {
|
2015-06-24 15:04:40 +02:00
|
|
|
if (!user.groups) {
|
|
|
|
user.groups = [];
|
|
|
|
}
|
2015-02-08 22:37:55 +01:00
|
|
|
User.save(user).then(
|
|
|
|
function(success) {
|
|
|
|
$state.go('users.user.list');
|
|
|
|
}
|
|
|
|
);
|
2015-01-30 11:58:36 +01:00
|
|
|
};
|
2015-02-12 22:42:54 +01:00
|
|
|
})
|
|
|
|
|
2015-09-04 18:26:48 +02:00
|
|
|
.controller('UserProfileCtrl', function($scope, $state, User, user) {
|
|
|
|
$scope.user = user; // autoupdate is not activated
|
|
|
|
$scope.save = function (user) {
|
|
|
|
User.save(user).then(
|
|
|
|
function(success) {
|
|
|
|
// TODO: show success message
|
|
|
|
console.log("profile saved");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2015-06-24 15:04:40 +02:00
|
|
|
.controller('UserImportCtrl', function($scope, $state, User) {
|
|
|
|
// import from textarea
|
|
|
|
$scope.importByLine = function () {
|
|
|
|
$scope.users = $scope.userlist[0].split("\n");
|
|
|
|
$scope.importcounter = 0;
|
|
|
|
$scope.users.forEach(function(name) {
|
2015-06-25 10:19:38 +02:00
|
|
|
// Split each full name in first and last name.
|
|
|
|
// The last word is set as last name, rest is the first name(s).
|
|
|
|
// (e.g.: "Max Martin Mustermann" -> last_name = "Mustermann")
|
|
|
|
var names = name.split(" ");
|
|
|
|
var last_name = names.slice(-1)[0];
|
|
|
|
var first_name = names.slice(0, -1).join(" ");
|
|
|
|
var user = {
|
|
|
|
first_name: first_name,
|
|
|
|
last_name: last_name,
|
|
|
|
groups: []
|
|
|
|
};
|
2015-06-24 15:04:40 +02:00
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
|
|
|
$scope.importcounter++;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// import from csv file
|
2015-03-09 15:40:54 +01:00
|
|
|
$scope.csv = {
|
|
|
|
content: null,
|
|
|
|
header: true,
|
|
|
|
separator: ',',
|
|
|
|
result: null
|
|
|
|
};
|
|
|
|
|
2015-06-24 15:04:40 +02:00
|
|
|
$scope.importByCSV = function (result) {
|
|
|
|
var obj = JSON.parse(JSON.stringify(result));
|
|
|
|
$scope.csvimporting = true;
|
|
|
|
$scope.csvlines = Object.keys(obj).length;
|
|
|
|
$scope.csvimportcounter = 0;
|
2015-03-09 15:40:54 +01:00
|
|
|
for (var i = 0; i < obj.length; i++) {
|
|
|
|
var user = {};
|
2015-06-24 15:04:40 +02:00
|
|
|
user.title = obj[i].titel;
|
|
|
|
user.first_name = obj[i].first_name;
|
|
|
|
user.last_name = obj[i].last_name;
|
|
|
|
user.structure_level = obj[i].structure_level;
|
2015-10-15 17:27:59 +02:00
|
|
|
user.groups = [];
|
|
|
|
if (obj[i].groups != '') {
|
|
|
|
var groups = obj[i].groups.replace('"','').split(",");
|
|
|
|
groups.forEach(function(group) {
|
|
|
|
user.groups.push(group);
|
|
|
|
console.log(group);
|
|
|
|
});
|
|
|
|
}
|
2015-06-24 15:04:40 +02:00
|
|
|
user.comment = obj[i].comment;
|
2015-03-09 15:40:54 +01:00
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
2015-06-24 15:04:40 +02:00
|
|
|
$scope.csvimportcounter++;
|
2015-03-09 15:40:54 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2015-06-24 15:04:40 +02:00
|
|
|
$scope.csvimported = true;
|
2015-03-09 15:40:54 +01:00
|
|
|
}
|
2015-06-24 15:04:40 +02:00
|
|
|
|
|
|
|
$scope.clear = function () {
|
|
|
|
$scope.csv.result = null;
|
|
|
|
};
|
2015-02-08 22:37:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
.controller('GroupListCtrl', function($scope, Group) {
|
|
|
|
Group.bindAll({}, $scope, 'groups');
|
|
|
|
|
2015-06-24 15:04:40 +02:00
|
|
|
// delete selected group
|
2015-02-08 22:37:55 +01:00
|
|
|
$scope.delete = function (group) {
|
2015-03-09 15:40:54 +01:00
|
|
|
Group.destroy(group.id);
|
2015-02-08 22:37:55 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2015-03-09 15:40:54 +01:00
|
|
|
.controller('GroupCreateCtrl', function($scope, $state, Group, permissions) {
|
|
|
|
// get all permissions
|
|
|
|
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
2015-02-08 22:37:55 +01:00
|
|
|
$scope.group = {};
|
|
|
|
$scope.save = function (group) {
|
|
|
|
Group.create(group).then(
|
|
|
|
function(success) {
|
2015-03-09 15:40:54 +01:00
|
|
|
$state.go('users.group.list');
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2015-03-09 15:40:54 +01:00
|
|
|
.controller('GroupUpdateCtrl', function($scope, $state, Group, permissions, group) {
|
|
|
|
// get all permissions
|
|
|
|
$scope.permissions = permissions.data.actions.POST.permissions.choices;
|
2015-02-08 22:37:55 +01:00
|
|
|
$scope.group = group; // autoupdate is not activated
|
|
|
|
$scope.save = function (group) {
|
|
|
|
Group.save(group).then(
|
|
|
|
function(success) {
|
|
|
|
$state.go('users.group.list');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
.controller('GroupDetailCtrl', function($scope, Group, group) {
|
|
|
|
Group.bindOne(group.id, $scope, 'group');
|
|
|
|
})
|
|
|
|
|
2015-02-12 22:42:54 +01:00
|
|
|
.controller('userMenu', function($scope, $http, DS, User, operator) {
|
|
|
|
$scope.logout = function() {
|
|
|
|
$http.post('/users/logout/').success(function(data) {
|
|
|
|
operator.setUser(null);
|
|
|
|
// TODO: remove all data from cache and reload page
|
|
|
|
// DS.flush();
|
|
|
|
});
|
|
|
|
};
|
2015-06-17 09:45:00 +02:00
|
|
|
});
|
|
|
|
|
2015-02-12 22:42:54 +01:00
|
|
|
|
2015-06-17 09:45:00 +02:00
|
|
|
angular.module('OpenSlidesApp.users.projector', ['OpenSlidesApp.users'])
|
|
|
|
|
|
|
|
.config(function(slidesProvider) {
|
|
|
|
slidesProvider.registerSlide('users/user', {
|
|
|
|
template: 'static/templates/users/slide_user.html',
|
|
|
|
});
|
|
|
|
})
|
2015-02-12 22:42:54 +01:00
|
|
|
|
2015-06-24 15:04:40 +02:00
|
|
|
.controller('SlideUserCtrl', function($scope, User) {
|
2015-06-17 09:45:00 +02:00
|
|
|
// 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.
|
2015-09-08 14:14:11 +02:00
|
|
|
var id = $scope.element.id;
|
2015-06-17 09:45:00 +02:00
|
|
|
User.find(id);
|
|
|
|
User.bindOne(id, $scope, 'user');
|
|
|
|
});
|
2015-02-12 22:42:54 +01:00
|
|
|
|
|
|
|
// this is code from angular.js. Find a way to call this function from this file
|
|
|
|
function getBlockNodes(nodes) {
|
|
|
|
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
|
|
|
|
// collection, otherwise update the original collection.
|
|
|
|
var node = nodes[0];
|
|
|
|
var endNode = nodes[nodes.length - 1];
|
|
|
|
var blockNodes = [node];
|
|
|
|
|
|
|
|
do {
|
|
|
|
node = node.nextSibling;
|
|
|
|
if (!node) break;
|
|
|
|
blockNodes.push(node);
|
|
|
|
} while (node !== endNode);
|
|
|
|
|
|
|
|
return $(blockNodes);
|
|
|
|
}
|