2018-09-22 22:01:32 +02:00
|
|
|
|
$('#save-task-button').on('click', function(e)
|
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2018-09-23 19:26:13 +02:00
|
|
|
|
var jsonData = $('#task-form').serializeJSON();
|
|
|
|
|
jsonData.assigned_to_user_id = jsonData.user_id;
|
|
|
|
|
delete jsonData.user_id;
|
|
|
|
|
jsonData.due_date = Grocy.Components.DateTimePicker.GetValue();
|
|
|
|
|
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy("task-form");
|
|
|
|
|
|
2018-09-22 22:01:32 +02:00
|
|
|
|
if (Grocy.EditMode === 'create')
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Post('objects/tasks', jsonData,
|
2018-09-22 22:01:32 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/tasks');
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("task-form");
|
2018-09-22 22:01:32 +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/tasks/' + Grocy.EditObjectId, jsonData,
|
2018-09-22 22:01:32 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/tasks');
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
2018-11-24 19:40:50 +01:00
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy("task-form");
|
2018-09-22 22:01:32 +02:00
|
|
|
|
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-23 09:22:54 +02:00
|
|
|
|
$('#task-form input').keyup(function(event)
|
2018-09-22 22:01:32 +02:00
|
|
|
|
{
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('task-form');
|
|
|
|
|
});
|
|
|
|
|
|
2018-09-23 09:22:54 +02:00
|
|
|
|
$('#task-form input').keydown(function(event)
|
2018-09-22 22:01:32 +02:00
|
|
|
|
{
|
|
|
|
|
if (event.keyCode === 13) //Enter
|
|
|
|
|
{
|
2018-09-29 13:41:56 +02:00
|
|
|
|
event.preventDefault();
|
2019-01-19 00:37:21 -07:00
|
|
|
|
|
2018-09-22 22:01:32 +02:00
|
|
|
|
if (document.getElementById('task-form').checkValidity() === false) //There is at least one validation error
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$('#save-task-button').click();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#name').focus();
|
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('task-form');
|