mirror of
https://github.com/grocy/grocy.git
synced 2025-09-22 20:36:25 +00:00
74 lines
1.3 KiB
JavaScript
74 lines
1.3 KiB
JavaScript
![]() |
$('#save-user-button').on('click', function(e)
|
|||
|
{
|
|||
|
e.preventDefault();
|
|||
|
|
|||
|
if (Grocy.EditMode === 'create')
|
|||
|
{
|
|||
|
Grocy.Api.Post('users/create', $('#user-form').serializeJSON(),
|
|||
|
function(result)
|
|||
|
{
|
|||
|
window.location.href = U('/users');
|
|||
|
},
|
|||
|
function(xhr)
|
|||
|
{
|
|||
|
console.error(xhr);
|
|||
|
}
|
|||
|
);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Grocy.Api.Post('users/edit/' + Grocy.EditObjectId, $('#user-form').serializeJSON(),
|
|||
|
function(result)
|
|||
|
{
|
|||
|
window.location.href = U('/users');
|
|||
|
},
|
|||
|
function(xhr)
|
|||
|
{
|
|||
|
console.error(xhr);
|
|||
|
}
|
|||
|
);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
$('#user-form input').keyup(function (event)
|
|||
|
{
|
|||
|
var element = document.getElementById("password_confirm");
|
|||
|
if ($("#password").val() !== $("#password_confirm").val())
|
|||
|
{
|
|||
|
element.setCustomValidity("error");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
element.setCustomValidity("");
|
|||
|
}
|
|||
|
|
|||
|
Grocy.FrontendHelpers.ValidateForm('user-form');
|
|||
|
});
|
|||
|
|
|||
|
$('#user-form input').keydown(function (event)
|
|||
|
{
|
|||
|
if (event.keyCode === 13) //Enter
|
|||
|
{
|
|||
|
if (document.getElementById('user-form').checkValidity() === false) //There is at least one validation error
|
|||
|
{
|
|||
|
event.preventDefault();
|
|||
|
return false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
$('#save-user-button').click();
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
if (GetUriParam("changepw") === "true")
|
|||
|
{
|
|||
|
$('#password').focus();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
$('#username').focus();
|
|||
|
}
|
|||
|
|
|||
|
Grocy.FrontendHelpers.ValidateForm('user-form');
|