diff --git a/frontend-js/src/main/js/gui/admin/EditUserDialog.js b/frontend-js/src/main/js/gui/admin/EditUserDialog.js index f3658b719beae9a16e4111b3d47b03b752050409..437e1921cbcf2667ca6d3712e5c791140b5818ac 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}