From 2f0cabf07251f12c6573eae7aedd4e7a63795c2d Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 23 Apr 2019 16:46:37 +0200 Subject: [PATCH] user details are saved on change --- .../src/main/js/gui/admin/EditUserDialog.js | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/frontend-js/src/main/js/gui/admin/EditUserDialog.js b/frontend-js/src/main/js/gui/admin/EditUserDialog.js index f3658b719b..437e1921cb 100644 --- a/frontend-js/src/main/js/gui/admin/EditUserDialog.js +++ b/frontend-js/src/main/js/gui/admin/EditUserDialog.js @@ -16,7 +16,7 @@ var guiUtils = new (require('../leftPanel/GuiUtils'))(); /** * - * @param params + * @param {Object} params * @param {HTMLElement} params.element * @param {User} params.user * @param {Configuration} params.configuration @@ -166,6 +166,42 @@ EditUserDialog.prototype.createGeneralTabContent = function () { menuRow.appendChild(saveUserButton); menuRow.appendChild(cancelButton); + if (!self.getIsNewUser()) { + $(".minerva-menu-row", result).hide(); + } + + $(result).on('change', '[name="userName"]', function () { + if (!self.getIsNewUser()) { + self.getUser().setName($(this).val()); + return self.updateUser(); + } + }); + + $(result).on('change', '[name="userSurname"]', function () { + if (!self.getIsNewUser()) { + self.getUser().setSurname($(this).val()); + return self.updateUser(); + } + }); + + $(result).on('change', '[name="userEmail"]', function () { + if (!self.getIsNewUser()) { + self.getUser().setEmail($(this).val()); + return self.updateUser(); + } + }); + + $(result).on('change', '[name^="userPassword"]', function () { + if (!self.getIsNewUser()) { + if (self.getPassword() !== self.getPassword2()) { + $('[name^="userPassword"]', self.getElement()).css("background-color", "red"); + } else { + $('[name^="userPassword"]', self.getElement()).css("background-color", ""); + self.getUser().setPassword($(this).val()); + return self.updateUser(); + } + } + }); return result; }; @@ -592,21 +628,30 @@ EditUserDialog.prototype.onSaveClicked = function () { user.setEmail(self.getEmail()); user.setName(self.getName()); user.setSurname(self.getSurname()); - if (self.getIsNewUser()) { - return self.getServerConnector().addUser(user).catch(function (error) { - if (error instanceof ObjectExistsError) { - return Promise.reject(new ValidationError("User with given login already exists")); - } - return Promise.reject(error); - }); - } else { - return self.getServerConnector().updateUser(user); - } + return self.getServerConnector().addUser(user).catch(function (error) { + if (error instanceof ObjectExistsError) { + return Promise.reject(new ValidationError("User with given login already exists")); + } + return Promise.reject(error); + }); }).then(function () { return self.callListeners("onSave", user); }); }; + +/** + * + * @returns {Promise} + */ +EditUserDialog.prototype.updateUser = function () { + var self = this; + GuiConnector.showProcessing(); + return self.getServerConnector().updateUser(self.getUser()).then(function (user) { + return self.callListeners("onSave", user); + }).catch(GuiConnector.alert).finally(GuiConnector.hideProcessing); +}; + /** * * @returns {Promise} -- GitLab