2015-10-21 22:44:07 +02:00
|
|
|
(function () {
|
2015-06-17 09:45:00 +02:00
|
|
|
|
2015-10-21 22:44:07 +02:00
|
|
|
'use strict';
|
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',
|
2015-11-30 23:52:42 +01:00
|
|
|
'gettext',
|
|
|
|
function (mainMenuProvider, gettext) {
|
2015-09-05 17:15:37 +02:00
|
|
|
mainMenuProvider.register({
|
|
|
|
'ui_sref': 'users.user.list',
|
|
|
|
'img_class': 'user',
|
2015-11-30 23:52:42 +01:00
|
|
|
'title': gettext('Participants'),
|
2015-09-05 17:15:37 +02:00
|
|
|
'weight': 500,
|
|
|
|
'perm': 'users.can_see_name',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2016-01-17 21:16:04 +01:00
|
|
|
.config([
|
|
|
|
'$stateProvider',
|
|
|
|
function($stateProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.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();
|
2016-01-21 20:43:04 +01:00
|
|
|
},
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
2016-01-17 21:16:04 +01:00
|
|
|
}
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
|
|
|
.state('users.user.create', {
|
|
|
|
resolve: {
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
|
|
|
}
|
2015-01-30 11:58:36 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
|
|
|
.state('users.user.detail', {
|
|
|
|
resolve: {
|
|
|
|
user: function(User, $stateParams) {
|
|
|
|
return User.find($stateParams.id);
|
|
|
|
},
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
|
|
|
}
|
2015-12-11 21:36:09 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
2016-03-19 13:41:03 +01:00
|
|
|
// Redirects to user detail view and opens user edit form dialog, uses edit url.
|
|
|
|
// Used by $state.go(..) from core/site.js only (for edit current slide button).
|
|
|
|
// (from users list controller use UserForm factory instead to open dialog in front of
|
|
|
|
// current view without redirect)
|
|
|
|
.state('users.user.detail.update', {
|
|
|
|
onEnter: ['$stateParams', '$state', 'ngDialog', 'User',
|
|
|
|
function($stateParams, $state, ngDialog, User) {
|
|
|
|
ngDialog.open({
|
|
|
|
template: 'static/templates/users/user-form.html',
|
|
|
|
controller: 'UserUpdateCtrl',
|
|
|
|
className: 'ngdialog-theme-default wide-form',
|
|
|
|
closeByEscape: false,
|
|
|
|
closeByDocument: false,
|
|
|
|
resolve: {
|
|
|
|
user: function() {return User.find($stateParams.id);}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2016-01-17 21:16:04 +01:00
|
|
|
.state('users.user.detail.profile', {
|
|
|
|
views: {
|
|
|
|
'@users.user': {},
|
|
|
|
},
|
|
|
|
url: '/profile',
|
|
|
|
controller: 'UserProfileCtrl',
|
|
|
|
})
|
|
|
|
.state('users.user.detail.password', {
|
|
|
|
views: {
|
|
|
|
'@users.user': {},
|
|
|
|
},
|
|
|
|
url: '/password',
|
|
|
|
controller: 'UserPasswordCtrl',
|
|
|
|
})
|
|
|
|
.state('users.user.import', {
|
|
|
|
url: '/import',
|
|
|
|
controller: 'UserImportCtrl',
|
|
|
|
resolve: {
|
|
|
|
groups: function(Group) {
|
|
|
|
return Group.findAll();
|
|
|
|
}
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +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
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
|
|
|
.state('users.group.create', {
|
|
|
|
resolve: {
|
2016-01-27 13:41:19 +01:00
|
|
|
permissions: function(Group) {
|
|
|
|
return Group.getPermissions();
|
2016-01-17 21:16:04 +01:00
|
|
|
}
|
2015-02-08 22:37:55 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
|
|
|
.state('users.group.detail', {
|
|
|
|
resolve: {
|
|
|
|
group: function(Group, $stateParams) {
|
|
|
|
return Group.find($stateParams.id);
|
2016-02-24 20:50:32 +01:00
|
|
|
},
|
|
|
|
permissions: function(Group) {
|
|
|
|
return Group.getPermissions();
|
2016-01-17 21:16:04 +01:00
|
|
|
}
|
2015-03-09 15:40:54 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
})
|
|
|
|
.state('users.group.detail.update', {
|
|
|
|
views: {
|
|
|
|
'@users.group': {}
|
|
|
|
},
|
|
|
|
resolve: {
|
2016-01-27 13:41:19 +01:00
|
|
|
permissions: function(Group) {
|
|
|
|
return Group.getPermissions();
|
2015-12-10 08:35:56 +01:00
|
|
|
}
|
2016-01-17 21:16:04 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('login', {
|
|
|
|
template: null,
|
|
|
|
url: '/login',
|
|
|
|
params: { guest_enabled: false },
|
|
|
|
onEnter: ['$state', '$stateParams', 'ngDialog', function($state, $stateParams, ngDialog) {
|
|
|
|
ngDialog.open({
|
|
|
|
template: 'static/templates/core/login-form.html',
|
|
|
|
controller: 'LoginFormCtrl',
|
|
|
|
showClose: $stateParams.guest_enabled,
|
|
|
|
closeByEscape: $stateParams.guest_enabled,
|
|
|
|
closeByDocument: $stateParams.guest_enabled,
|
|
|
|
});
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
])
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.run([
|
|
|
|
'operator',
|
|
|
|
'$rootScope',
|
|
|
|
'$http',
|
2015-12-09 20:45:52 +01:00
|
|
|
'$state',
|
2015-11-19 20:51:39 +01:00
|
|
|
'Group',
|
2015-12-09 20:45:52 +01:00
|
|
|
function(operator, $rootScope, $http, $state, Group) {
|
2015-11-06 15:44:27 +01:00
|
|
|
// Put the operator into the root scope
|
|
|
|
$http.get('/users/whoami/').success(function(data) {
|
|
|
|
operator.setUser(data.user_id);
|
2016-01-21 21:13:24 +01:00
|
|
|
$rootScope.guest_enabled = data.guest_enabled;
|
2015-12-11 21:18:45 +01:00
|
|
|
if (data.user_id === null && !data.guest_enabled) {
|
2015-12-09 20:45:52 +01:00
|
|
|
// redirect to login dialog if use is not logged in
|
2015-12-10 00:02:16 +01:00
|
|
|
$state.go('login', {guest_enabled: data.guest_enabled});
|
2015-12-09 20:45:52 +01:00
|
|
|
}
|
2015-11-06 15:44:27 +01:00
|
|
|
});
|
|
|
|
$rootScope.operator = operator;
|
2015-11-19 21:49:51 +01:00
|
|
|
// Load all Groups. They are needed later
|
|
|
|
Group.findAll();
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
])
|
2015-02-12 22:42:54 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Directive to check for permissions
|
|
|
|
*
|
|
|
|
* This is the Code from angular.js ngIf.
|
|
|
|
*
|
|
|
|
* TODO: find a way not to copy the code.
|
|
|
|
*/
|
2015-11-06 15:44:27 +01:00
|
|
|
.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;
|
2015-02-12 22:42:54 +01:00
|
|
|
}
|
2015-11-06 15:44:27 +01:00
|
|
|
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();
|
2015-02-12 22:42:54 +01:00
|
|
|
previousElements = null;
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
if (childScope) {
|
|
|
|
childScope.$destroy();
|
|
|
|
childScope = null;
|
|
|
|
}
|
|
|
|
if (block) {
|
|
|
|
previousElements = getBlockNodes(block.clone);
|
|
|
|
$animate.leave(previousElements).then(function() {
|
|
|
|
previousElements = null;
|
|
|
|
});
|
|
|
|
block = null;
|
|
|
|
}
|
2015-02-12 22:42:54 +01:00
|
|
|
}
|
|
|
|
}
|
2015-11-06 15:44:27 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2015-02-12 22:42:54 +01:00
|
|
|
|
2016-01-10 13:47:59 +01:00
|
|
|
// Service for generic assignment form (create and update)
|
|
|
|
.factory('UserForm', [
|
2015-11-27 23:09:38 +01:00
|
|
|
'$http',
|
2015-11-30 23:52:42 +01:00
|
|
|
'gettextCatalog',
|
2016-02-12 00:15:35 +01:00
|
|
|
'Editor',
|
2015-11-27 23:09:38 +01:00
|
|
|
'Group',
|
2016-02-12 00:15:35 +01:00
|
|
|
'Mediafile',
|
|
|
|
function ($http, gettextCatalog, Editor, Group, Mediafile) {
|
2015-11-27 23:09:38 +01:00
|
|
|
return {
|
2016-01-10 13:47:59 +01:00
|
|
|
// ngDialog for user form
|
|
|
|
getDialog: function (user) {
|
2016-02-24 09:42:28 +01:00
|
|
|
var resolve;
|
2016-01-10 13:47:59 +01:00
|
|
|
if (user) {
|
2016-02-24 09:42:28 +01:00
|
|
|
resolve = {
|
2016-01-10 13:47:59 +01:00
|
|
|
user: function(User) {return User.find(user.id);}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
template: 'static/templates/users/user-form.html',
|
|
|
|
controller: (user) ? 'UserUpdateCtrl' : 'UserCreateCtrl',
|
|
|
|
className: 'ngdialog-theme-default wide-form',
|
|
|
|
closeByEscape: false,
|
|
|
|
closeByDocument: false,
|
|
|
|
resolve: (resolve) ? resolve : null
|
2016-02-24 09:42:28 +01:00
|
|
|
};
|
2016-01-10 13:47:59 +01:00
|
|
|
},
|
|
|
|
// angular-formly fields for user form
|
2016-01-21 22:34:18 +01:00
|
|
|
getFormFields: function (hideOnCreateForm) {
|
2016-02-12 00:15:35 +01:00
|
|
|
var images = Mediafile.getAllImages();
|
2015-11-27 23:09:38 +01:00
|
|
|
return [
|
2016-01-21 22:34:18 +01:00
|
|
|
{
|
|
|
|
key: 'username',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
|
|
|
label: gettextCatalog.getString('Username')
|
|
|
|
},
|
|
|
|
hide: hideOnCreateForm
|
|
|
|
},
|
2015-11-27 23:09:38 +01:00
|
|
|
{
|
|
|
|
key: 'title',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2015-11-30 23:52:42 +01:00
|
|
|
label: gettextCatalog.getString('Title'),
|
2016-01-09 13:32:56 +01:00
|
|
|
description: gettextCatalog.getString('Will be shown before the name.')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'first_name',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2015-11-30 23:52:42 +01:00
|
|
|
label: gettextCatalog.getString('First name')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'last_name',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2015-11-30 23:52:42 +01:00
|
|
|
label: gettextCatalog.getString('Last name')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'structure_level',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2016-01-09 13:32:56 +01:00
|
|
|
label: gettextCatalog.getString('Structure level'),
|
|
|
|
description: gettextCatalog.getString('Will be shown after the name.')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
2016-08-03 16:30:04 +02:00
|
|
|
{ key: 'number',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
|
|
|
label:gettextCatalog.getString('Participant number')
|
|
|
|
}
|
|
|
|
},
|
2015-11-27 23:09:38 +01:00
|
|
|
{
|
2016-04-14 21:29:28 +02:00
|
|
|
key: 'groups_id',
|
2016-03-08 22:55:43 +01:00
|
|
|
type: 'select-multiple',
|
2015-11-27 23:09:38 +01:00
|
|
|
templateOptions: {
|
2015-11-30 23:52:42 +01:00
|
|
|
label: gettextCatalog.getString('Groups'),
|
2015-11-27 23:09:38 +01:00
|
|
|
options: Group.getAll(),
|
2016-03-19 13:06:36 +01:00
|
|
|
ngOptions: 'option.id as option.name | translate for option in to.options | ' +
|
2016-03-08 22:55:43 +01:00
|
|
|
'filter: {id: "!1"} | filter: {id: "!2"}',
|
2015-12-11 20:04:05 +01:00
|
|
|
placeholder: gettextCatalog.getString('Select or search a group ...')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'default_password',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2015-11-30 23:52:42 +01:00
|
|
|
label: gettextCatalog.getString('Default password'),
|
2016-02-23 23:51:42 +01:00
|
|
|
description: '',
|
2015-12-10 15:03:18 +01:00
|
|
|
addonRight: { text: 'Reset', class: 'fa fa-undo', onClick:
|
|
|
|
function (options, scope) {
|
2016-01-10 13:47:59 +01:00
|
|
|
$http.post(
|
|
|
|
'/rest/users/user/' + scope.model.id + '/reset_password/',
|
|
|
|
{'password': scope.model.default_password})
|
2016-02-23 23:51:42 +01:00
|
|
|
.then(function() {
|
|
|
|
options.templateOptions.description =
|
|
|
|
gettextCatalog.getString('Password successfully resetted to:') +
|
|
|
|
' ' + scope.model.default_password;
|
|
|
|
});
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'comment',
|
|
|
|
type: 'input',
|
|
|
|
templateOptions: {
|
2016-01-09 13:32:56 +01:00
|
|
|
label: gettextCatalog.getString('Comment'),
|
|
|
|
description: gettextCatalog.getString('Only for notes.')
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'about_me',
|
2016-02-12 00:15:35 +01:00
|
|
|
type: 'editor',
|
2015-11-27 23:09:38 +01:00
|
|
|
templateOptions: {
|
2016-01-09 13:32:56 +01:00
|
|
|
label: gettextCatalog.getString('About me'),
|
2015-11-27 23:09:38 +01:00
|
|
|
},
|
2016-02-12 00:15:35 +01:00
|
|
|
data: {
|
|
|
|
tinymceOption: Editor.getOptions(images)
|
|
|
|
}
|
2015-11-27 23:09:38 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'is_present',
|
|
|
|
type: 'checkbox',
|
|
|
|
templateOptions: {
|
2016-01-09 13:32:56 +01:00
|
|
|
label: gettextCatalog.getString('Is present'),
|
|
|
|
description: gettextCatalog.getString('Designates whether this user is in the room or not.')
|
2016-01-18 16:29:15 +01:00
|
|
|
},
|
|
|
|
defaultValue: true
|
2015-11-27 23:09:38 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'is_active',
|
|
|
|
type: 'checkbox',
|
|
|
|
templateOptions: {
|
2016-01-09 13:32:56 +01:00
|
|
|
label: gettextCatalog.getString('Is active'),
|
|
|
|
description: gettextCatalog.getString(
|
2016-01-09 16:24:37 +01:00
|
|
|
'Designates whether this user should be treated as ' +
|
2016-01-09 13:32:56 +01:00
|
|
|
'active. Unselect this instead of deleting the account.')
|
2016-01-18 16:29:15 +01:00
|
|
|
},
|
|
|
|
defaultValue: true
|
2016-06-30 13:06:23 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'is_committee',
|
|
|
|
type: 'checkbox',
|
|
|
|
templateOptions: {
|
|
|
|
label: gettextCatalog.getString('Is a committee'),
|
|
|
|
description: gettextCatalog.getString(
|
|
|
|
'Designates whether this user should be treated as a committee.')
|
|
|
|
},
|
|
|
|
defaultValue: false
|
2015-11-27 23:09:38 +01:00
|
|
|
}];
|
|
|
|
}
|
2016-02-24 09:42:28 +01:00
|
|
|
};
|
2015-11-27 23:09:38 +01:00
|
|
|
}
|
|
|
|
])
|
|
|
|
|
2015-10-15 17:27:59 +02:00
|
|
|
.controller('UserListCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
2015-11-27 23:09:38 +01:00
|
|
|
'ngDialog',
|
2016-01-10 13:47:59 +01:00
|
|
|
'UserForm',
|
2015-10-15 17:27:59 +02:00
|
|
|
'User',
|
|
|
|
'Group',
|
2016-01-10 13:47:59 +01:00
|
|
|
function($scope, $state, ngDialog, UserForm, User, Group) {
|
2015-10-15 17:27:59 +02:00
|
|
|
User.bindAll({}, $scope, 'users');
|
2016-01-18 20:51:44 +01:00
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
2015-12-11 21:36:09 +01:00
|
|
|
$scope.alert = {};
|
2016-03-18 11:00:31 +01:00
|
|
|
$scope.groupFilter = undefined;
|
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
|
|
|
|
2016-02-02 20:54:03 +01:00
|
|
|
// pagination
|
|
|
|
$scope.currentPage = 1;
|
|
|
|
$scope.itemsPerPage = 100;
|
|
|
|
$scope.limitBegin = 0;
|
|
|
|
$scope.pageChanged = function() {
|
|
|
|
$scope.limitBegin = ($scope.currentPage - 1) * $scope.itemsPerPage;
|
|
|
|
};
|
|
|
|
|
2016-01-10 13:47:59 +01:00
|
|
|
// open new/edit dialog
|
|
|
|
$scope.openDialog = function (user) {
|
|
|
|
ngDialog.open(UserForm.getDialog(user));
|
2015-10-15 17:27:59 +02:00
|
|
|
};
|
|
|
|
// save changed user
|
2015-11-27 23:09:38 +01:00
|
|
|
$scope.save = function (user) {
|
2015-12-11 21:36:09 +01:00
|
|
|
User.save(user).then(
|
2015-11-27 23:09:38 +01:00
|
|
|
function(success) {
|
|
|
|
//user.quickEdit = false;
|
|
|
|
$scope.alert.show = false;
|
|
|
|
},
|
|
|
|
function(error){
|
|
|
|
var message = '';
|
|
|
|
for (var e in error.data) {
|
|
|
|
message += e + ': ' + error.data[e] + ' ';
|
|
|
|
}
|
|
|
|
$scope.alert = { type: 'danger', msg: message, show: true };
|
|
|
|
});
|
2015-10-15 17:27:59 +02:00
|
|
|
};
|
2016-02-23 23:16:13 +01:00
|
|
|
// *** select mode functions ***
|
|
|
|
$scope.isSelectMode = false;
|
2015-10-15 17:27:59 +02:00
|
|
|
// check all checkboxes
|
|
|
|
$scope.checkAll = function () {
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
user.selected = $scope.selectedAll;
|
|
|
|
});
|
|
|
|
};
|
2016-02-23 23:16:13 +01:00
|
|
|
// uncheck all checkboxes if isSelectMode is closed
|
2015-10-15 17:27:59 +02:00
|
|
|
$scope.uncheckAll = function () {
|
2016-02-23 23:16:13 +01:00
|
|
|
if (!$scope.isSelectMode) {
|
2015-10-15 17:27:59 +02:00
|
|
|
$scope.selectedAll = false;
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
user.selected = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2015-11-27 23:09:38 +01:00
|
|
|
// delete all selected users
|
|
|
|
$scope.deleteMultiple = function () {
|
2015-10-15 17:27:59 +02:00
|
|
|
angular.forEach($scope.users, function (user) {
|
2016-02-23 23:16:13 +01:00
|
|
|
if (user.selected) {
|
2015-10-15 17:27:59 +02:00
|
|
|
User.destroy(user.id);
|
2016-02-23 23:16:13 +01:00
|
|
|
}
|
2015-10-15 17:27:59 +02:00
|
|
|
});
|
2016-02-23 23:16:13 +01:00
|
|
|
$scope.isSelectMode = false;
|
2015-10-15 17:27:59 +02:00
|
|
|
$scope.uncheckAll();
|
|
|
|
};
|
2015-11-27 23:09:38 +01:00
|
|
|
// delete single user
|
|
|
|
$scope.delete = function (user) {
|
|
|
|
User.destroy(user.id);
|
|
|
|
};
|
2016-02-23 23:16:13 +01:00
|
|
|
// add group for selected users
|
|
|
|
$scope.addGroupMultiple = function (group) {
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
if (user.selected) {
|
2016-04-17 22:42:56 +02:00
|
|
|
user.groups_id.push(group);
|
2016-02-23 23:16:13 +01:00
|
|
|
User.save(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.isSelectMode = false;
|
|
|
|
$scope.uncheckAll();
|
|
|
|
};
|
|
|
|
// remove group for selected users
|
|
|
|
$scope.removeGroupMultiple = function (group) {
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
if (user.selected) {
|
2016-04-17 22:42:56 +02:00
|
|
|
var groupIndex = user.groups_id.indexOf(parseInt(group));
|
2016-02-23 23:16:13 +01:00
|
|
|
if (groupIndex > -1) {
|
2016-04-17 22:42:56 +02:00
|
|
|
user.groups_id.splice(groupIndex, 1);
|
2016-02-23 23:16:13 +01:00
|
|
|
User.save(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.isSelectMode = false;
|
|
|
|
$scope.uncheckAll();
|
|
|
|
};
|
2015-10-15 17:27:59 +02:00
|
|
|
}
|
|
|
|
])
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('UserDetailCtrl', [
|
|
|
|
'$scope',
|
2016-01-10 13:47:59 +01:00
|
|
|
'ngDialog',
|
|
|
|
'UserForm',
|
2015-11-06 15:44:27 +01:00
|
|
|
'User',
|
|
|
|
'user',
|
|
|
|
'Group',
|
2016-01-10 13:47:59 +01:00
|
|
|
function($scope, ngDialog, UserForm, User, user, Group) {
|
2015-11-06 15:44:27 +01:00
|
|
|
User.bindOne(user.id, $scope, 'user');
|
2016-01-18 20:51:44 +01:00
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
2016-01-10 13:47:59 +01:00
|
|
|
|
|
|
|
// open edit dialog
|
|
|
|
$scope.openDialog = function (user) {
|
|
|
|
ngDialog.open(UserForm.getDialog(user));
|
|
|
|
};
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
])
|
2015-02-12 22:42:54 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('UserCreateCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'User',
|
2016-01-10 13:47:59 +01:00
|
|
|
'UserForm',
|
2015-11-06 15:44:27 +01:00
|
|
|
'Group',
|
2016-01-10 13:47:59 +01:00
|
|
|
function($scope, $state, User, UserForm, Group) {
|
2015-11-06 15:44:27 +01:00
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
2016-01-18 16:29:15 +01:00
|
|
|
$scope.alert = {};
|
2015-11-27 23:09:38 +01:00
|
|
|
// get all form fields
|
2016-01-21 22:34:18 +01:00
|
|
|
$scope.formFields = UserForm.getFormFields(true);
|
2015-11-27 23:09:38 +01:00
|
|
|
|
|
|
|
// save user
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.save = function (user) {
|
2016-04-17 22:42:56 +02:00
|
|
|
if (!user.groups_id) {
|
|
|
|
user.groups_id = [];
|
2015-09-04 18:26:48 +02:00
|
|
|
}
|
2015-06-24 15:04:40 +02:00
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
2015-11-27 23:09:38 +01:00
|
|
|
$scope.closeThisDialog();
|
2016-01-18 16:29:15 +01:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
var message = '';
|
|
|
|
for (var e in error.data) {
|
|
|
|
message += e + ': ' + error.data[e] + ' ';
|
|
|
|
}
|
|
|
|
$scope.alert = {type: 'danger', msg: message, show: true};
|
2015-06-24 15:04:40 +02:00
|
|
|
}
|
|
|
|
);
|
2015-11-06 15:44:27 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
.controller('UserUpdateCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
2015-11-18 09:50:49 +01:00
|
|
|
'$http',
|
2015-11-06 15:44:27 +01:00
|
|
|
'User',
|
2016-01-10 13:47:59 +01:00
|
|
|
'UserForm',
|
2015-11-06 15:44:27 +01:00
|
|
|
'Group',
|
2015-11-27 23:09:38 +01:00
|
|
|
'user',
|
2016-01-10 13:47:59 +01:00
|
|
|
function($scope, $state, $http, User, UserForm, Group, user) {
|
2015-11-06 15:44:27 +01:00
|
|
|
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
2016-01-14 22:10:44 +01:00
|
|
|
$scope.alert = {};
|
|
|
|
// set initial values for form model by create deep copy of user object
|
|
|
|
// so list/detail view is not updated while editing
|
|
|
|
$scope.model = angular.copy(user);
|
|
|
|
|
2015-11-27 23:09:38 +01:00
|
|
|
// get all form fields
|
2016-01-10 13:47:59 +01:00
|
|
|
$scope.formFields = UserForm.getFormFields();
|
2015-11-27 23:09:38 +01:00
|
|
|
|
|
|
|
// save user
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.save = function (user) {
|
2016-04-17 22:42:56 +02:00
|
|
|
if (!user.groups_id) {
|
|
|
|
user.groups_id = [];
|
2015-10-15 17:27:59 +02:00
|
|
|
}
|
2016-01-14 22:10:44 +01:00
|
|
|
// inject the changed user (copy) object back into DS store
|
|
|
|
User.inject(user);
|
|
|
|
// save change user object on server
|
2015-11-06 15:44:27 +01:00
|
|
|
User.save(user).then(
|
2016-01-14 22:10:44 +01:00
|
|
|
function (success) {
|
2015-11-27 23:09:38 +01:00
|
|
|
$scope.closeThisDialog();
|
2016-01-14 22:10:44 +01:00
|
|
|
},
|
|
|
|
function (error) {
|
|
|
|
// save error: revert all changes by restore
|
|
|
|
// (refresh) original user object from server
|
|
|
|
User.refresh(user);
|
|
|
|
var message = '';
|
|
|
|
for (var e in error.data) {
|
|
|
|
message += e + ': ' + error.data[e] + ' ';
|
|
|
|
}
|
|
|
|
$scope.alert = {type: 'danger', msg: message, show: true};
|
2015-03-09 15:40:54 +01:00
|
|
|
}
|
|
|
|
);
|
2015-11-06 15:44:27 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2015-06-24 15:04:40 +02:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('UserProfileCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
2016-02-12 00:15:35 +01:00
|
|
|
'Editor',
|
2015-11-06 15:44:27 +01:00
|
|
|
'User',
|
|
|
|
'user',
|
2016-02-12 00:15:35 +01:00
|
|
|
function($scope, $state, Editor, User, user) {
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.user = user; // autoupdate is not activated
|
2016-02-12 00:15:35 +01:00
|
|
|
$scope.tinymceOption = Editor.getOptions();
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.save = function (user) {
|
2016-01-10 10:52:44 +01:00
|
|
|
User.save(user, { method: 'PATCH' }).then(
|
2015-11-06 15:44:27 +01:00
|
|
|
function(success) {
|
|
|
|
$state.go('users.user.list');
|
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
$scope.formError = error;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('UserPasswordCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'$http',
|
|
|
|
'user',
|
|
|
|
function($scope, $state, $http, user) {
|
|
|
|
$scope.user = user; // autoupdate is not activated
|
|
|
|
$scope.save = function (user) {
|
|
|
|
if ($scope.newPassword != $scope.newPassword2) {
|
|
|
|
$scope.newPassword = $scope.newPassword2 = '';
|
|
|
|
$scope.formError = 'Password confirmation does not match.';
|
|
|
|
} else {
|
|
|
|
$http.post(
|
|
|
|
'/users/setpassword/',
|
|
|
|
{'old_password': $scope.oldPassword, 'new_password': $scope.newPassword}
|
|
|
|
).then(
|
2015-12-11 16:28:56 +01:00
|
|
|
function (response) {
|
2015-11-06 15:44:27 +01:00
|
|
|
// Success.
|
|
|
|
$state.go('users.user.list');
|
|
|
|
},
|
2015-12-11 16:28:56 +01:00
|
|
|
function (response) {
|
2015-11-06 15:44:27 +01:00
|
|
|
// Error, e. g. wrong old password.
|
|
|
|
$scope.oldPassword = $scope.newPassword = $scope.newPassword2 = '';
|
2015-12-11 16:28:56 +01:00
|
|
|
$scope.formError = response.data.detail;
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('UserImportCtrl', [
|
|
|
|
'$scope',
|
2015-12-11 21:36:09 +01:00
|
|
|
'gettext',
|
2015-11-06 15:44:27 +01:00
|
|
|
'User',
|
2015-12-11 21:36:09 +01:00
|
|
|
'Group',
|
|
|
|
function($scope, gettext, User, Group) {
|
2015-11-06 15:44:27 +01:00
|
|
|
// import from textarea
|
|
|
|
$scope.importByLine = function () {
|
2015-12-11 21:36:09 +01:00
|
|
|
$scope.usernames = $scope.userlist[0].split("\n");
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.importcounter = 0;
|
2015-12-11 21:36:09 +01:00
|
|
|
$scope.usernames.forEach(function(name) {
|
2015-11-06 15:44:27 +01: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,
|
2016-04-14 21:29:28 +02:00
|
|
|
groups_id: []
|
2015-11-06 15:44:27 +01:00
|
|
|
};
|
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
|
|
|
$scope.importcounter++;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-12-11 21:36:09 +01:00
|
|
|
// *** csv import ***
|
|
|
|
// set initial data for csv import
|
2016-02-24 09:42:28 +01:00
|
|
|
$scope.users = [];
|
2015-12-11 21:36:09 +01:00
|
|
|
$scope.separator = ',';
|
|
|
|
$scope.encoding = 'UTF-8';
|
|
|
|
$scope.encodingOptions = ['UTF-8', 'ISO-8859-1'];
|
2016-06-02 13:01:12 +02:00
|
|
|
$scope.accept = '.csv, .txt';
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.csv = {
|
|
|
|
content: null,
|
|
|
|
header: true,
|
2015-12-11 21:36:09 +01:00
|
|
|
headerVisible: false,
|
|
|
|
separator: $scope.separator,
|
|
|
|
separatorVisible: false,
|
|
|
|
encoding: $scope.encoding,
|
|
|
|
encodingVisible: false,
|
2016-06-02 13:01:12 +02:00
|
|
|
accept: $scope.accept,
|
2015-11-06 15:44:27 +01:00
|
|
|
result: null
|
|
|
|
};
|
2015-12-11 21:36:09 +01:00
|
|
|
// set csv file encoding
|
|
|
|
$scope.setEncoding = function () {
|
|
|
|
$scope.csv.encoding = $scope.encoding;
|
|
|
|
};
|
|
|
|
// set csv file encoding
|
|
|
|
$scope.setSeparator = function () {
|
|
|
|
$scope.csv.separator = $scope.separator;
|
|
|
|
};
|
2016-02-02 20:54:03 +01:00
|
|
|
// pagination
|
|
|
|
$scope.currentPage = 1;
|
|
|
|
$scope.itemsPerPage = 100;
|
|
|
|
$scope.limitBegin = 0;
|
|
|
|
$scope.pageChanged = function() {
|
|
|
|
$scope.limitBegin = ($scope.currentPage - 1) * $scope.itemsPerPage;
|
|
|
|
};
|
2015-12-11 21:36:09 +01:00
|
|
|
// detect if csv file is loaded
|
|
|
|
$scope.$watch('csv.result', function () {
|
|
|
|
$scope.users = [];
|
|
|
|
var quotionRe = /^"(.*)"$/;
|
|
|
|
angular.forEach($scope.csv.result, function (user) {
|
|
|
|
// title
|
|
|
|
if (user.title) {
|
|
|
|
user.title = user.title.replace(quotionRe, '$1');
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
2015-12-11 21:36:09 +01:00
|
|
|
// first name
|
|
|
|
if (user.first_name) {
|
|
|
|
user.first_name = user.first_name.replace(quotionRe, '$1');
|
|
|
|
}
|
|
|
|
// last name
|
|
|
|
if (user.last_name) {
|
|
|
|
user.last_name = user.last_name.replace(quotionRe, '$1');
|
|
|
|
}
|
|
|
|
if (!user.first_name && !user.last_name) {
|
|
|
|
user.importerror = true;
|
|
|
|
user.name_error = gettext('Error: First or last name is required.');
|
|
|
|
}
|
|
|
|
// structure level
|
|
|
|
if (user.structure_level) {
|
|
|
|
user.structure_level = user.structure_level.replace(quotionRe, '$1');
|
|
|
|
}
|
2016-08-03 16:30:04 +02:00
|
|
|
// number
|
|
|
|
if (user.number) {
|
|
|
|
user.number = user.number.replace(quotionRe, '$1');
|
|
|
|
}
|
2015-12-11 21:36:09 +01:00
|
|
|
// groups
|
|
|
|
if (user.groups) {
|
|
|
|
var csvGroups = user.groups.replace(quotionRe, '$1').split(",");
|
2016-04-14 21:29:28 +02:00
|
|
|
user.groups_id = [];
|
2015-12-11 21:36:09 +01:00
|
|
|
user.groupnames = [];
|
2016-02-24 09:42:28 +01:00
|
|
|
if (csvGroups !== '') {
|
2015-12-11 21:36:09 +01:00
|
|
|
// All group objects are already loaded via the resolve statement from ui-router.
|
|
|
|
var allGroups = Group.getAll();
|
|
|
|
csvGroups.forEach(function(csvGroup) {
|
|
|
|
allGroups.forEach(function (allGroup) {
|
|
|
|
if (csvGroup == allGroup.id) {
|
2016-04-14 21:29:28 +02:00
|
|
|
user.groups_id.push(allGroup.id);
|
2015-12-11 21:36:09 +01:00
|
|
|
user.groupnames.push(allGroup.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
2015-12-11 21:36:09 +01:00
|
|
|
} else {
|
2016-04-14 21:29:28 +02:00
|
|
|
user.groups_id = [];
|
2015-12-11 21:36:09 +01:00
|
|
|
}
|
|
|
|
// comment
|
|
|
|
if (user.comment) {
|
|
|
|
user.comment = user.comment.replace(quotionRe, '$1');
|
|
|
|
}
|
|
|
|
// is active
|
|
|
|
if (user.is_active) {
|
|
|
|
user.is_active = user.is_active.replace(quotionRe, '$1');
|
|
|
|
if (user.is_active == '1') {
|
|
|
|
user.is_active = true;
|
|
|
|
} else {
|
|
|
|
user.is_active = false;
|
|
|
|
}
|
2016-02-17 21:11:36 +01:00
|
|
|
} else {
|
|
|
|
user.is_active = false;
|
2015-12-11 21:36:09 +01:00
|
|
|
}
|
2016-07-27 14:54:18 +02:00
|
|
|
// is committee
|
|
|
|
if (user.is_committee) {
|
|
|
|
user.is_committee = user.is_committee.replace(quotionRe, '$1');
|
|
|
|
if (user.is_committee == '1') {
|
|
|
|
user.is_committee = true;
|
|
|
|
} else {
|
|
|
|
user.is_committee = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user.is_committee = false;
|
|
|
|
}
|
2015-12-11 21:36:09 +01:00
|
|
|
$scope.users.push(user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// import from csv file
|
|
|
|
$scope.import = function () {
|
|
|
|
$scope.csvImporting = true;
|
|
|
|
angular.forEach($scope.users, function (user) {
|
|
|
|
if (!user.importerror) {
|
|
|
|
User.create(user).then(
|
|
|
|
function(success) {
|
|
|
|
user.imported = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.csvimported = true;
|
|
|
|
};
|
|
|
|
$scope.clear = function () {
|
|
|
|
$scope.csv.result = null;
|
|
|
|
};
|
2015-12-30 21:56:03 +01:00
|
|
|
// download CSV example file
|
|
|
|
$scope.downloadCSVExample = function () {
|
|
|
|
var element = document.getElementById('downloadLink');
|
|
|
|
var csvRows = [
|
|
|
|
// column header line
|
2016-08-03 16:30:04 +02:00
|
|
|
['title', 'first_name', 'last_name', 'structure_level', 'number', 'groups', 'comment', 'is_active', 'is_committee'],
|
2015-12-30 21:56:03 +01:00
|
|
|
// example entries
|
2016-08-03 16:30:04 +02:00
|
|
|
['Dr.', 'Max', 'Mustermann', 'Berlin','1234567890', '"3,4"', 'xyz', '1', ''],
|
|
|
|
['', 'John', 'Doe', 'Washington','75/99/8-2', '3', 'abc', '1', ''],
|
|
|
|
['', 'Fred', 'Bloggs', 'London', '', '', '', '', ''],
|
|
|
|
['', '', 'Executive Board', '', '', '5', '', '', '1'],
|
2015-12-30 21:56:03 +01:00
|
|
|
|
|
|
|
];
|
|
|
|
var csvString = csvRows.join("%0A");
|
|
|
|
element.href = 'data:text/csv;charset=utf-8,' + csvString;
|
|
|
|
element.download = 'users-example.csv';
|
|
|
|
element.target = '_blank';
|
2016-02-24 09:42:28 +01:00
|
|
|
};
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
])
|
2015-02-08 22:37:55 +01:00
|
|
|
|
2015-11-06 15:44:27 +01:00
|
|
|
.controller('GroupListCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'Group',
|
|
|
|
function($scope, Group) {
|
|
|
|
Group.bindAll({}, $scope, 'groups');
|
|
|
|
|
|
|
|
// delete selected group
|
|
|
|
$scope.delete = function (group) {
|
|
|
|
Group.destroy(group.id);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
.controller('GroupCreateCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'Group',
|
|
|
|
'permissions',
|
|
|
|
function($scope, $state, Group, permissions) {
|
|
|
|
// get all permissions
|
2016-01-27 13:41:19 +01:00
|
|
|
$scope.permissions = permissions;
|
2015-11-06 15:44:27 +01:00
|
|
|
$scope.group = {};
|
|
|
|
$scope.save = function (group) {
|
2016-03-05 20:45:57 +01:00
|
|
|
if (!group.permissions) {
|
|
|
|
group.permissions = [];
|
|
|
|
}
|
2015-11-06 15:44:27 +01:00
|
|
|
Group.create(group).then(
|
|
|
|
function(success) {
|
|
|
|
$state.go('users.group.list');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
.controller('GroupUpdateCtrl', [
|
|
|
|
'$scope',
|
|
|
|
'$state',
|
|
|
|
'Group',
|
|
|
|
'permissions',
|
|
|
|
'group',
|
|
|
|
function($scope, $state, Group, permissions, group) {
|
|
|
|
// get all permissions
|
2016-01-27 13:41:19 +01:00
|
|
|
$scope.permissions = permissions;
|
2015-11-06 15:44:27 +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', [
|
|
|
|
'$scope',
|
|
|
|
'Group',
|
|
|
|
'group',
|
2016-02-24 20:50:32 +01:00
|
|
|
'permissions',
|
|
|
|
function($scope, Group, group, permissions) {
|
2015-11-06 15:44:27 +01:00
|
|
|
Group.bindOne(group.id, $scope, 'group');
|
2016-02-24 20:50:32 +01:00
|
|
|
$scope.groupPermissionNames = [];
|
|
|
|
// get display names of group permissions
|
|
|
|
// from an object array with all available permissions [{display_name, value}]
|
|
|
|
angular.forEach(group.permissions, function(permValue) {
|
|
|
|
angular.forEach(permissions, function(p) {
|
|
|
|
if (p.value == permValue) {
|
|
|
|
$scope.groupPermissionNames.push(p.display_name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
.controller('userMenu', [
|
|
|
|
'$scope',
|
|
|
|
'$http',
|
|
|
|
'DS',
|
|
|
|
'User',
|
|
|
|
'operator',
|
2015-11-21 20:14:19 +01:00
|
|
|
'ngDialog',
|
|
|
|
function($scope, $http, DS, User, operator, ngDialog) {
|
2015-12-11 16:28:56 +01:00
|
|
|
$scope.logout = function () {
|
|
|
|
$http.post('/users/logout/').then(function (response) {
|
2015-11-06 15:44:27 +01:00
|
|
|
operator.setUser(null);
|
2016-02-17 17:47:22 +01:00
|
|
|
window.location.reload();
|
2015-11-06 15:44:27 +01:00
|
|
|
});
|
|
|
|
};
|
2015-11-21 20:14:19 +01:00
|
|
|
}
|
|
|
|
])
|
|
|
|
|
|
|
|
.controller('LoginFormCtrl', [
|
2016-01-21 21:13:24 +01:00
|
|
|
'$rootScope',
|
2015-11-21 20:14:19 +01:00
|
|
|
'$scope',
|
|
|
|
'$http',
|
2015-12-10 08:35:56 +01:00
|
|
|
'$stateParams',
|
2015-11-21 20:14:19 +01:00
|
|
|
'operator',
|
2016-01-27 13:41:19 +01:00
|
|
|
function ($rootScope, $scope, $http, $stateParams, operator ) {
|
2015-11-21 20:14:19 +01:00
|
|
|
$scope.alerts = [];
|
|
|
|
|
2016-01-09 14:22:32 +01:00
|
|
|
// get login info-text from server
|
|
|
|
$http.get('/users/login/').success(function(data) {
|
|
|
|
if(data.info_text) {
|
|
|
|
$scope.alerts.push({
|
|
|
|
type: 'success',
|
|
|
|
msg: data.info_text
|
|
|
|
});
|
|
|
|
}
|
2016-02-24 09:42:28 +01:00
|
|
|
});
|
2015-11-21 20:14:19 +01:00
|
|
|
// close alert function
|
|
|
|
$scope.closeAlert = function(index) {
|
|
|
|
$scope.alerts.splice(index, 1);
|
|
|
|
};
|
|
|
|
// check if guest login is allowed
|
2016-01-21 21:13:24 +01:00
|
|
|
$scope.guestAllowed = $rootScope.guest_enabled;
|
2015-11-21 20:14:19 +01:00
|
|
|
// login
|
|
|
|
$scope.login = function () {
|
2016-01-10 00:38:59 +01:00
|
|
|
$scope.alerts = [];
|
2015-11-21 20:14:19 +01:00
|
|
|
$http.post(
|
|
|
|
'/users/login/',
|
|
|
|
{'username': $scope.username, 'password': $scope.password}
|
2015-12-11 16:28:56 +01:00
|
|
|
).then(
|
|
|
|
function (response) {
|
|
|
|
// Success: User logged in.
|
|
|
|
operator.setUser(response.data.user_id);
|
2015-11-21 20:14:19 +01:00
|
|
|
$scope.closeThisDialog();
|
2016-02-17 17:47:22 +01:00
|
|
|
setTimeout(function(){
|
|
|
|
window.location.replace('/');
|
|
|
|
}, 1000);
|
2015-12-11 16:28:56 +01:00
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
// Error: Username or password is not correct.
|
2015-11-21 20:14:19 +01:00
|
|
|
$scope.alerts.push({
|
|
|
|
type: 'danger',
|
2015-12-11 16:28:56 +01:00
|
|
|
msg: response.data.detail
|
2015-11-21 20:14:19 +01:00
|
|
|
});
|
|
|
|
}
|
2015-12-11 16:28:56 +01:00
|
|
|
);
|
2015-11-21 20:14:19 +01:00
|
|
|
};
|
|
|
|
// guest login
|
|
|
|
$scope.guestLogin = function () {
|
|
|
|
$scope.closeThisDialog();
|
|
|
|
};
|
2015-11-06 15:44:27 +01:00
|
|
|
}
|
2016-01-27 13:41:19 +01:00
|
|
|
])
|
|
|
|
|
2016-06-28 10:05:52 +02:00
|
|
|
// Mark all users strings for translation in JavaScript.
|
2016-01-27 13:41:19 +01:00
|
|
|
.config([
|
|
|
|
'gettext',
|
|
|
|
function (gettext) {
|
2016-06-28 10:05:52 +02:00
|
|
|
// permission strings (see models.py of each Django app)
|
2016-01-27 13:41:19 +01:00
|
|
|
// agenda
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see agenda');
|
|
|
|
gettext('Can manage agenda');
|
|
|
|
gettext('Can see hidden items and time scheduling of agenda');
|
|
|
|
gettext('Can put oneself on the list of speakers');
|
2016-01-27 13:41:19 +01:00
|
|
|
// assignments
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see elections');
|
|
|
|
gettext('Can nominate another participant');
|
|
|
|
gettext('Can nominate oneself');
|
|
|
|
gettext('Can manage elections');
|
2016-01-27 13:41:19 +01:00
|
|
|
// core
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see the projector');
|
|
|
|
gettext('Can manage the projector');
|
|
|
|
gettext('Can see the front page');
|
|
|
|
gettext('Can manage tags');
|
|
|
|
gettext('Can manage configuration');
|
|
|
|
gettext('Can use the chat');
|
2016-01-27 13:41:19 +01:00
|
|
|
// mediafiles
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see the list of files');
|
|
|
|
gettext('Can upload files');
|
|
|
|
gettext('Can manage files');
|
2016-01-27 13:41:19 +01:00
|
|
|
// motions
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see motions');
|
|
|
|
gettext('Can create motions');
|
|
|
|
gettext('Can support motions');
|
|
|
|
gettext('Can manage motions');
|
2016-01-27 13:41:19 +01:00
|
|
|
// users
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can see names of users');
|
2016-03-18 11:00:31 +01:00
|
|
|
gettext('Can see extra data of users (e.g. present and comment)');
|
2016-02-24 09:42:28 +01:00
|
|
|
gettext('Can manage users');
|
2016-06-28 10:05:52 +02:00
|
|
|
|
|
|
|
// config strings in users/config_variables.py
|
2016-06-09 16:12:13 +02:00
|
|
|
gettext('[Place for your welcome and help text.]');
|
|
|
|
gettext('Sort users by first name');
|
|
|
|
gettext('Disable for sorting by last name');
|
2016-06-28 10:05:52 +02:00
|
|
|
gettext('Participants');
|
2016-06-09 16:12:13 +02:00
|
|
|
gettext('Sorting');
|
2016-06-28 10:05:52 +02:00
|
|
|
gettext('Welcome to OpenSlides');
|
2016-06-09 16:12:13 +02:00
|
|
|
gettext('Title for access data and welcome PDF');
|
|
|
|
gettext('PDF');
|
|
|
|
gettext('Help text for access data and welcome PDF');
|
|
|
|
gettext('System URL');
|
|
|
|
gettext('Used for QRCode in PDF of access data.');
|
|
|
|
gettext('WLAN name (SSID)');
|
|
|
|
gettext('Used for WLAN QRCode in PDF of access data.');
|
|
|
|
gettext('WLAN password');
|
|
|
|
gettext('Used for WLAN QRCode in PDF of access data.');
|
|
|
|
gettext('WLAN encryption');
|
|
|
|
gettext('Used for WLAN QRCode in PDF of access data.');
|
|
|
|
gettext('WEP');
|
|
|
|
gettext('WPA/WPA2');
|
|
|
|
gettext('No encryption');
|
2016-01-27 13:41:19 +01:00
|
|
|
}
|
2015-11-06 15:44:27 +01:00
|
|
|
]);
|
2015-06-17 09:45:00 +02:00
|
|
|
|
2016-01-27 13:41:19 +01:00
|
|
|
|
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);
|
|
|
|
}
|
2015-10-21 22:44:07 +02:00
|
|
|
|
|
|
|
}());
|