2015-02-08 14:57:02 +01:00
|
|
|
angular.module('OpenSlidesApp.users', [])
|
2015-01-30 11:58:36 +01:00
|
|
|
|
2015-02-08 14:57:02 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2015-02-08 14:57:02 +01:00
|
|
|
.state('users.user.create', {})
|
|
|
|
.state('users.user.detail', {
|
2015-01-30 11:58:36 +01:00
|
|
|
resolve: {
|
2015-02-08 14:57:02 +01:00
|
|
|
user: function(User, $stateParams) {
|
|
|
|
return User.find($stateParams.id);
|
2015-01-30 11:58:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2015-02-08 14:57:02 +01:00
|
|
|
.state('users.user.detail.update', {
|
|
|
|
views: {
|
|
|
|
'@users.user': {}
|
2015-01-30 11:58:36 +01:00
|
|
|
}
|
|
|
|
});
|
2015-02-08 14:57:02 +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) {
|
2015-02-13 23:23:48 +01:00
|
|
|
User.bindAll({}, $scope, 'users');
|
2015-01-30 11:58:36 +01:00
|
|
|
})
|
|
|
|
|
2015-02-08 14:57:02 +01:00
|
|
|
.controller('UserDetailCtrl', function($scope, User, user) {
|
2015-02-13 23:23:48 +01:00
|
|
|
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
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2015-02-08 14:57:02 +01:00
|
|
|
.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
|
2015-02-08 14:57:02 +01:00
|
|
|
$scope.save = function(user) {
|
2015-01-30 11:58:36 +01:00
|
|
|
User.save(user);
|
|
|
|
// TODO: redirect to list-view
|
|
|
|
};
|
|
|
|
});
|