2019-09-18 16:18:15 +02:00
|
|
|
|
$('#save-userobject-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2022-03-26 10:34:00 +01:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm("userobject-form", true))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 13:45:14 +01:00
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 16:18:15 +02:00
|
|
|
|
var jsonData = {};
|
|
|
|
|
jsonData.userentity_id = Grocy.EditObjectParentId;
|
2020-08-29 16:41:27 +02:00
|
|
|
|
|
2019-09-18 16:18:15 +02:00
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("userobject-form");
|
|
|
|
|
|
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
|
|
|
|
Grocy.Api.Post('objects/userobjects', jsonData,
|
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
Grocy.EditObjectId = result.created_object_id;
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-17 21:18:05 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/userobjects/' + Grocy.EditObjectParentName);
|
|
|
|
|
}
|
2019-09-18 16:18:15 +02:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("userobject-form");
|
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Grocy.Api.Put('objects/userobjects/' + Grocy.EditObjectId, jsonData,
|
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-17 21:18:05 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/userobjects/' + Grocy.EditObjectParentName);
|
|
|
|
|
}
|
2019-09-18 16:18:15 +02:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("userobject-form");
|
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2019-09-18 16:31:00 +02:00
|
|
|
|
$("#userfields-form").removeClass("border").removeClass("border-info").removeClass("p-2").find("h2").addClass("d-none");
|