Files
grocy/public/viewjs/taskform.js

118 lines
2.5 KiB
JavaScript
Raw Normal View History

$('.save-task-button').on('click', function(e)
2018-09-22 22:01:32 +02:00
{
e.preventDefault();
if (!Grocy.FrontendHelpers.ValidateForm("task-form", true))
{
return;
}
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();
Grocy.FrontendHelpers.BeginUiBusy("task-form");
2018-09-22 22:01:32 +02:00
if (Grocy.EditMode === 'create')
{
var addAnother = $(e.currentTarget).hasClass("add-another");
Grocy.Api.Post('objects/tasks', jsonData,
2018-09-22 22:01:32 +02:00
function(result)
{
Grocy.EditObjectId = result.created_object_id;
Grocy.Components.UserfieldsForm.Save(function()
{
2020-11-08 15:09:10 +01:00
if (GetUriParam("embedded") !== undefined)
{
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
{
if (addAnother)
{
window.location.href = U('/task/new');
}
else
{
window.location.href = U('/tasks');
}
2020-11-08 15:09:10 +01:00
}
});
2018-09-22 22:01:32 +02:00
},
function(xhr)
{
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
{
Grocy.Api.Put('objects/tasks/' + Grocy.EditObjectId, jsonData,
2018-09-22 22:01:32 +02:00
function(result)
{
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');
}
});
2018-09-22 22:01:32 +02:00
},
function(xhr)
{
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
{
2022-03-30 18:00:28 +02:00
if (event.keyCode === 13) // Enter
2018-09-22 22:01:32 +02:00
{
event.preventDefault();
2022-03-30 18:00:28 +02:00
if (!Grocy.FrontendHelpers.ValidateForm('task-form'))
2018-09-22 22:01:32 +02:00
{
return false;
}
else
{
$('.save-task-button').first().click();
2018-09-22 22:01:32 +02:00
}
}
});
Grocy.Components.UserfieldsForm.Load();
setTimeout(function()
{
$('#name').focus();
}, 200);
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');
2018-09-22 22:01:32 +02:00
Grocy.FrontendHelpers.ValidateForm('task-form');