From e6cf28cbeb22de6e78b3ec61d2e27d5836a3bf3c Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Thu, 14 Jan 2016 22:10:44 +0100 Subject: [PATCH] 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. --- openslides/users/static/js/users/site.js | 22 ++++++++++++++++--- .../static/templates/users/user-form.html | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/openslides/users/static/js/users/site.js b/openslides/users/static/js/users/site.js index f797ab1c7..aa3b49075 100644 --- a/openslides/users/static/js/users/site.js +++ b/openslides/users/static/js/users/site.js @@ -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}; } ); }; diff --git a/openslides/users/static/templates/users/user-form.html b/openslides/users/static/templates/users/user-form.html index 6fa19a4cf..22116dfb6 100644 --- a/openslides/users/static/templates/users/user-form.html +++ b/openslides/users/static/templates/users/user-form.html @@ -1,6 +1,10 @@

Edit participant

New participant

+ + {{ alert.msg }} + +