Modify user in form dialog without updating list/detail view.

Create deep copy of user object before modify user in form dialog.
So list/detail view is not updated while editing.
Before saving inject the changed user (copy) object back into DS
store. Refresh user from DB is save request fails.
This commit is contained in:
Emanuel Schuetze 2016-01-14 22:10:44 +01:00
parent ffe80e8da3
commit e6cf28cbeb
2 changed files with 23 additions and 3 deletions

View File

@ -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) {
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};
}
);
};

View File

@ -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>