mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Finalize user-defined-fields (closes #176)
This commit is contained in:
@@ -7,7 +7,7 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
|
||||
$("#userfields-form .userfield-input").each(function()
|
||||
{
|
||||
var input = $(this);
|
||||
var fieldName = input.attr("id");
|
||||
var fieldName = input.attr("data-userfield-name");
|
||||
var fieldValue = input.val();
|
||||
|
||||
if (input.attr("type") == "checkbox")
|
||||
@@ -49,7 +49,7 @@ Grocy.Components.UserfieldsForm.Load = function()
|
||||
{
|
||||
$.each(result, function(key, value)
|
||||
{
|
||||
var input = $("#" + key + ".userfield-input");
|
||||
var input = $(".userfield-input[data-userfield-name='" + key + "']");
|
||||
|
||||
if (input.attr("type") == "checkbox" && value == 1)
|
||||
{
|
||||
|
@@ -21,24 +21,28 @@
|
||||
Grocy.Api.Post('objects/equipment', jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
Grocy.EditObjectId = result.created_object_id;
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/equipment');
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("equipment-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/equipment');
|
||||
}
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
{
|
||||
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||
function (result)
|
||||
{
|
||||
window.location.href = U('/equipment');
|
||||
},
|
||||
function (xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("equipment-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/equipment');
|
||||
}
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -67,24 +71,27 @@
|
||||
Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/equipment');;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("equipment-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/equipment');;
|
||||
}
|
||||
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
|
||||
{
|
||||
Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/equipment');;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("equipment-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/equipment');;
|
||||
}
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -133,5 +140,6 @@ $('#description').summernote({
|
||||
|
||||
ResizeResponsiveEmbeds();
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
||||
$('#name').focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('equipment-form');
|
||||
|
@@ -31,24 +31,27 @@
|
||||
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteRecipePictureOnSave)
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
Grocy.Api.UploadFile($("#recipe-picture")[0].files[0], 'recipepictures', jsonData.picture_file_name,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/recipes?recipe=' + Grocy.EditObjectId);
|
||||
},
|
||||
function (xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("recipe-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/recipes?recipe=' + Grocy.EditObjectId);
|
||||
}
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteRecipePictureOnSave)
|
||||
{
|
||||
Grocy.Api.UploadFile($("#recipe-picture")[0].files[0], 'recipepictures', jsonData.picture_file_name,
|
||||
function (result)
|
||||
{
|
||||
window.location.href = U('/recipes?recipe=' + Grocy.EditObjectId);
|
||||
},
|
||||
function (xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("recipe-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U('/recipes?recipe=' + Grocy.EditObjectId);
|
||||
}
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -345,3 +348,5 @@ $('#description').summernote({
|
||||
minHeight: '300px',
|
||||
lang: L('summernote_locale')
|
||||
});
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
||||
|
@@ -14,7 +14,11 @@
|
||||
Grocy.Api.Post('objects/tasks', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
Grocy.EditObjectId = result.created_object_id;
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -28,7 +32,10 @@
|
||||
Grocy.Api.Put('objects/tasks/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
window.location.href = U('/tasks');
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -61,6 +68,7 @@ $('#task-form input').keydown(function(event)
|
||||
}
|
||||
});
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
||||
$('#name').focus();
|
||||
Grocy.Components.DateTimePicker.GetInputElement().trigger('input');
|
||||
Grocy.FrontendHelpers.ValidateForm('task-form');
|
||||
|
@@ -5,12 +5,18 @@
|
||||
var jsonData = $('#userfield-form').serializeJSON();
|
||||
Grocy.FrontendHelpers.BeginUiBusy("userfield-form");
|
||||
|
||||
var redirectUrl = U("/userfields");
|
||||
if (typeof GetUriParam("entity") !== "undefined" && !GetUriParam("entity").isEmpty())
|
||||
{
|
||||
redirectUrl = U("/userfields?entity=" + GetUriParam("entity"));
|
||||
}
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('objects/userfields', jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/userfields');
|
||||
window.location.href = redirectUrl;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -24,7 +30,7 @@
|
||||
Grocy.Api.Put('objects/userfields/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
window.location.href = U('/userfields');
|
||||
window.location.href = redirectUrl;
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
@@ -64,7 +70,7 @@ $('#userfield-form input').keydown(function(event)
|
||||
|
||||
$('#entity').focus();
|
||||
|
||||
if (typeof GetUriParam("entity") !== "undefined")
|
||||
if (typeof GetUriParam("entity") !== "undefined" && !GetUriParam("entity").isEmpty())
|
||||
{
|
||||
$("#entity").val(GetUriParam("entity"));
|
||||
$("#entity").trigger("change");
|
||||
|
@@ -41,6 +41,7 @@ $("#entity-filter").on("change", function()
|
||||
}
|
||||
|
||||
userfieldsTable.column(1).search(value).draw();
|
||||
$("#new-userfield-button").attr("href", U("/userfield/new?entity=" + value));
|
||||
});
|
||||
|
||||
$(document).on('click', '.userfield-delete-button', function (e)
|
||||
@@ -79,7 +80,7 @@ $(document).on('click', '.userfield-delete-button', function (e)
|
||||
});
|
||||
});
|
||||
|
||||
if (typeof GetUriParam("entity") !== "undefined")
|
||||
if (typeof GetUriParam("entity") !== "undefined" && !GetUriParam("entity").isEmpty())
|
||||
{
|
||||
$("#entity-filter").val(GetUriParam("entity"));
|
||||
$("#entity-filter").trigger("change");
|
||||
|
Reference in New Issue
Block a user