2018-09-23 09:22:54 +02:00
|
|
|
|
$('#save-task-category-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2022-03-26 10:34:00 +01:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm("task-category-form", true))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 13:45:14 +01:00
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-24 19:40:50 +01:00
|
|
|
|
var jsonData = $('#task-category-form').serializeJSON();
|
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("task-category-form");
|
|
|
|
|
|
2018-09-23 09:22:54 +02:00
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Post('objects/task_categories', jsonData,
|
2018-09-23 09:22:54 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.EditObjectId = result.created_object_id;
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-08 19:00:12 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/taskcategories');
|
|
|
|
|
}
|
2019-04-22 22:16:35 +02:00
|
|
|
|
});
|
2018-09-23 09:22:54 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("task-category-form");
|
2018-09-23 09:22:54 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Put('objects/task_categories/' + Grocy.EditObjectId, jsonData,
|
2018-09-23 09:22:54 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-08 19:00:12 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/taskcategories');
|
|
|
|
|
}
|
2019-04-22 22:16:35 +02:00
|
|
|
|
});
|
2018-09-23 09:22:54 +02:00
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("task-category-form");
|
2018-09-23 09:22:54 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-30 12:18:16 +02:00
|
|
|
|
$('#task-category-form input').keyup(function(event)
|
2018-09-23 09:22:54 +02:00
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('task-category-form');
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-30 12:18:16 +02:00
|
|
|
|
$('#task-category-form input').keydown(function(event)
|
2018-09-23 09:22:54 +02:00
|
|
|
|
{
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (event.keyCode === 13) // Enter
|
2018-09-23 09:22:54 +02:00
|
|
|
|
{
|
2018-09-29 13:41:56 +02:00
|
|
|
|
event.preventDefault();
|
2019-01-19 00:37:21 -07:00
|
|
|
|
|
2022-03-30 18:00:28 +02:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm('task-category-form'))
|
2018-09-23 09:22:54 +02:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$('#save-task-category-button').click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-22 22:16:35 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2021-11-08 21:59:02 +01:00
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$('#name').focus();
|
2025-01-11 12:06:15 +01:00
|
|
|
|
}, 200);
|
2018-09-23 09:22:54 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('task-category-form');
|