mirror of
https://github.com/grocy/grocy.git
synced 2025-08-15 10:14:39 +00:00
Implement custom entities / objects (closes #242)
This commit is contained in:
47
public/viewjs/userobjectform.js
Normal file
47
public/viewjs/userobjectform.js
Normal file
@@ -0,0 +1,47 @@
|
||||
$('#save-userobject-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonData = {};
|
||||
jsonData.userentity_id = Grocy.EditObjectParentId;
|
||||
console.log(jsonData);
|
||||
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()
|
||||
{
|
||||
window.location.href = U('/userobjects/' + Grocy.EditObjectParentName);
|
||||
});
|
||||
},
|
||||
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()
|
||||
{
|
||||
window.location.href = U('/userobjects/' + Grocy.EditObjectParentName);
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("userobject-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
Reference in New Issue
Block a user