Merge pull request #1862 from emanuelschuetze/injectUser
Modify user in form dialog without updating list/detail view.
This commit is contained in:
commit
3ed5b2bb1b
@ -519,8 +519,11 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
'user',
|
||||
function($scope, $state, $http, User, UserForm, Group, user) {
|
||||
Group.bindAll({where: {id: {'>': 2}}}, $scope, 'groups');
|
||||
// set initial values for form model
|
||||
$scope.model = user;
|
||||
$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);
|
||||
|
||||
// get all form fields
|
||||
$scope.formFields = UserForm.getFormFields();
|
||||
|
||||
@ -529,9 +532,22 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
||||
if (!user.groups) {
|
||||
user.groups = [];
|
||||
}
|
||||
// inject the changed user (copy) object back into DS store
|
||||
User.inject(user);
|
||||
// save change user object on server
|
||||
User.save(user).then(
|
||||
function (success) {
|
||||
$scope.closeThisDialog();
|
||||
},
|
||||
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};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@ -1,6 +1,10 @@
|
||||
<h1 ng-if="model.id" translate>Edit participant</h1>
|
||||
<h1 ng-if="!model.id" translate>New participant</h1>
|
||||
|
||||
<alert ng-show="alert.show" type="{{ alert.type }}" ng-click="alert={}" close="alert={}">
|
||||
{{ alert.msg }}
|
||||
</alert>
|
||||
|
||||
<form name="userForm" ng-submit="save(model)">
|
||||
<formly-form model="model" fields="formFields">
|
||||
<button type="submit" ng-disabled="userForm.$invalid" class="btn btn-primary" translate>
|
||||
|
Loading…
Reference in New Issue
Block a user