OpenSlides/openslides/users/static/js/users/users.js

89 lines
2.4 KiB
JavaScript
Raw Normal View History

angular.module('OpenSlidesApp.users', [])
2015-01-30 11:58:36 +01:00
.config(function($stateProvider) {
$stateProvider
.state('users', {
url: '/user',
abstract: true,
template: "<ui-view/>",
})
.state('users.user', {
abstract: true,
template: "<ui-view/>",
})
.state('users.user.list', {
2015-01-30 11:58:36 +01:00
resolve: {
users: function(User) {
return User.findAll();
}
}
})
.state('users.user.create', {})
.state('users.user.detail', {
2015-01-30 11:58:36 +01:00
resolve: {
user: function(User, $stateParams) {
return User.find($stateParams.id);
2015-01-30 11:58:36 +01:00
}
}
})
.state('users.user.detail.update', {
views: {
'@users.user': {}
2015-01-30 11:58:36 +01:00
}
});
})
2015-01-30 11:58:36 +01:00
.factory('User', function(DS) {
return DS.defineResource({
name: 'users/user',
endpoint: '/rest/users/user/',
methods: {
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;
},
}
});
})
.factory('Group', function(DS) {
return DS.defineResource({
name: 'users/group',
endpoint: '/rest/users/group/'
});
})
.controller('UserListCtrl', function($scope, User, i18n) {
User.bindAll({}, $scope, 'users');
2015-01-30 11:58:36 +01:00
})
.controller('UserDetailCtrl', function($scope, User, user) {
User.bindOne(user.id, $scope, 'user');
2015-01-30 11:58:36 +01:00
})
.controller('UserCreateCtrl', function($scope, User) {
$scope.user = {};
$scope.save = function (user) {
User.create(user);
// TODO: redirect to list-view
};
})
.controller('UserUpdateCtrl', function($scope, User, user) {
2015-01-30 11:58:36 +01:00
$scope.user = user; // do not use Agenda.binOne(...) so autoupdate is not activated
$scope.save = function(user) {
2015-01-30 11:58:36 +01:00
User.save(user);
// TODO: redirect to list-view
};
});