2022-02-06 18:35:19 +01:00
|
|
|
|
$('.save-task-button').on('click', function(e)
|
2018-09-22 22:01:32 +02:00
|
|
|
|
{
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2022-03-26 10:34:00 +01:00
|
|
|
|
if (!Grocy.FrontendHelpers.ValidateForm("task-form", true))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 13:45:14 +01:00
|
|
|
|
if ($(".combobox-menu-visible").length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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')
|
|
|
|
|
{
|
2022-02-06 18:35:19 +01:00
|
|
|
|
var addAnother = $(e.currentTarget).hasClass("add-another");
|
|
|
|
|
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Post('objects/tasks', jsonData,
|
2018-09-22 22:01:32 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
2019-04-23 09:06:18 +02:00
|
|
|
|
Grocy.EditObjectId = result.created_object_id;
|
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-08 15:09:10 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
2022-02-06 18:35:19 +01:00
|
|
|
|
if (addAnother)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/task/new?embedded');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
2020-11-08 15:09:10 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-06 18:35:19 +01:00
|
|
|
|
if (addAnother)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/task/new');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/tasks');
|
|
|
|
|
}
|
2020-11-08 15:09:10 +01:00
|
|
|
|
}
|
2019-04-23 09:06:18 +02:00
|
|
|
|
});
|
2018-09-22 22:01:32 +02:00
|
|
|
|
},
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-04-23 09:06:18 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Save(function()
|
|
|
|
|
{
|
2020-11-08 15:09:10 +01:00
|
|
|
|
if (GetUriParam("embedded") !== undefined)
|
|
|
|
|
{
|
|
|
|
|
window.parent.postMessage(WindowMessageBag("Reload"), Grocy.BaseUrl);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/tasks');
|
|
|
|
|
}
|
2019-04-23 09:06:18 +02:00
|
|
|
|
});
|
2018-09-22 22:01:32 +02:00
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
|
{
|
2022-02-06 18:35:19 +01:00
|
|
|
|
$('.save-task-button').first().click();
|
2018-09-22 22:01:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-04-23 09:06:18 +02:00
|
|
|
|
Grocy.Components.UserfieldsForm.Load();
|
2021-11-08 21:59:02 +01:00
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$('#name').focus();
|
|
|
|
|
}, 250);
|
2019-03-04 17:43:12 +01:00
|
|
|
|
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');
|
2018-09-22 22:01:32 +02:00
|
|
|
|
Grocy.FrontendHelpers.ValidateForm('task-form');
|