Files
grocy/public/viewjs/taskcategoryform.js

97 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-09-23 09:22:54 +02:00
$('#save-task-category-button').on('click', function(e)
{
e.preventDefault();
if (!Grocy.FrontendHelpers.ValidateForm("task-category-form", true))
{
return;
}
if ($(".combobox-menu-visible").length)
{
return;
}
var jsonData = $('#task-category-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("task-category-form");
2018-09-23 09:22:54 +02:00
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/task_categories', jsonData,
2018-09-23 09:22:54 +02:00
function(result)
{
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');
}
});
2018-09-23 09:22:54 +02:00
},
function(xhr)
{
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
{
Grocy.Api.Put('objects/task_categories/' + Grocy.EditObjectId, jsonData,
2018-09-23 09:22:54 +02:00
function(result)
{
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');
}
});
2018-09-23 09:22:54 +02:00
},
function(xhr)
{
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
{
event.preventDefault();
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();
}
}
});
Grocy.Components.UserfieldsForm.Load();
setTimeout(function()
{
$('#name').focus();
}, 200);
2018-09-23 09:22:54 +02:00
Grocy.FrontendHelpers.ValidateForm('task-category-form');