Puts backend errors into own error field

This commit is contained in:
chaptergy
2021-05-10 19:58:28 +02:00
parent 62a708b416
commit 899b487daa
2 changed files with 22 additions and 10 deletions

View File

@ -9,21 +9,23 @@ module.exports = Mn.View.extend({
className: 'modal-dialog',
ui: {
form: 'form',
buttons: '.modal-footer button',
cancel: 'button.cancel',
save: 'button.save',
error: '.secret-error'
form: 'form',
buttons: '.modal-footer button',
cancel: 'button.cancel',
save: 'button.save',
newSecretError: '.new-secret-error',
generalError: '#error-info',
},
events: {
'click @ui.save': function (e) {
e.preventDefault();
this.ui.error.hide();
this.ui.newSecretError.hide();
this.ui.generalError.hide();
let form = this.ui.form.serializeJSON();
if (form.new_password1 !== form.new_password2) {
this.ui.error.text('Passwords do not match!').show();
this.ui.newSecretError.text('Passwords do not match!').show();
return;
}
@ -40,7 +42,11 @@ module.exports = Mn.View.extend({
App.Controller.showUsers();
})
.catch(err => {
this.ui.error.text(err.message).show();
// Change error message to make it a little clearer
if (err.message === 'Invalid password') {
err.message = 'Current password is invalid';
}
this.ui.generalError.text(err.message).show();
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
});
}
@ -54,5 +60,10 @@ module.exports = Mn.View.extend({
return {
isSelf: this.isSelf.bind(this)
};
}
},
onRender: function () {
this.ui.newSecretError.hide();
this.ui.generalError.hide();
},
});