Simplified "checkboxUncheckedValue" handling

This commit is contained in:
Bernd Bestel 2020-11-11 17:34:37 +01:00
parent 9949f30c2b
commit 9c81fc890b
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
19 changed files with 21 additions and 78 deletions

View File

@ -664,6 +664,9 @@ $.extend(true, $.fn.dataTable.defaults, {
} }
}); });
// serializeJSON defaults
$.serializeJSON.defaultOptions.checkboxUncheckedValue = "0";
$(Grocy.UserPermissions).each(function(index, item) $(Grocy.UserPermissions).each(function(index, item)
{ {
if (item.has_permission == 0) if (item.has_permission == 0)

View File

@ -2,7 +2,7 @@
{ {
e.preventDefault(); e.preventDefault();
var jsonData = $('#chore-form').serializeJSON({ checkboxUncheckedValue: "0" }); var jsonData = $('#chore-form').serializeJSON();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_CHORES_ASSIGNMENTS) if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_CHORES_ASSIGNMENTS)
{ {
jsonData.assignment_config = $("#assignment_config").val().join(","); jsonData.assignment_config = $("#assignment_config").val().join(",");

View File

@ -31,23 +31,26 @@ Grocy.Components.UserfieldsForm.Save = function(success, error)
else if (input.attr("type") == "file") else if (input.attr("type") == "file")
{ {
var old_file = input.data('old-file') var old_file = input.data('old-file')
if (old_file) { if (old_file)
{
Grocy.Api.Delete('files/userfiles/' + old_file, null, null, Grocy.Api.Delete('files/userfiles/' + old_file, null, null,
function (xhr) { function(xhr)
{
Grocy.FrontendHelpers.ShowGenericError('Could not delete file', xhr); Grocy.FrontendHelpers.ShowGenericError('Could not delete file', xhr);
}); });
jsonData[fieldName] = ""; jsonData[fieldName] = "";
} }
if (input[0].files.length > 0){ if (input[0].files.length > 0)
{
// Files service requires an extension // Files service requires an extension
var fileName = RandomString() + '.' + input[0].files[0].name.split('.').reverse()[0]; var fileName = RandomString() + '.' + input[0].files[0].name.split('.').reverse()[0];
jsonData[fieldName] = btoa(fileName) + '_' + btoa(input[0].files[0].name); jsonData[fieldName] = btoa(fileName) + '_' + btoa(input[0].files[0].name);
Grocy.Api.UploadFile(input[0].files[0], 'userfiles', fileName, Grocy.Api.UploadFile(input[0].files[0], 'userfiles', fileName,
function (result) function(result)
{ {
}, },
function (xhr) function(xhr)
{ {
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
} }
@ -111,7 +114,8 @@ Grocy.Components.UserfieldsForm.Load = function()
} }
if (input.attr('type') == "file") if (input.attr('type') == "file")
{ {
if (value != null && !value.isEmpty()) { if (value != null && !value.isEmpty())
{
var file_name = atob(value.split('_')[1]); var file_name = atob(value.split('_')[1]);
var file_src = value.split('_')[0]; var file_src = value.split('_')[0];
input.hide(); input.hide();
@ -123,7 +127,8 @@ Grocy.Components.UserfieldsForm.Load = function()
file_info.find('img.userfield-current-file') file_info.find('img.userfield-current-file')
.attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250')) .attr('src', U('/files/userfiles/' + value + '?force_serve_as=picture&best_fit_width=250&best_fit_height=250'))
file_info.find('button.userfield-file-delete').click( file_info.find('button.userfield-file-delete').click(
function () { function()
{
file_info.addClass('d-none'); file_info.addClass('d-none');
input.data('old-file', file_src); input.data('old-file', file_src);
input.show(); input.show();

View File

@ -65,7 +65,7 @@ $('.save-product-button').on('click', function(e)
{ {
e.preventDefault(); e.preventDefault();
var jsonData = $('#product-form').serializeJSON({ checkboxUncheckedValue: "0" }); var jsonData = $('#product-form').serializeJSON();
var parentProductId = jsonData.product_id; var parentProductId = jsonData.product_id;
delete jsonData.product_id; delete jsonData.product_id;
jsonData.parent_product_id = parentProductId; jsonData.parent_product_id = parentProductId;

View File

@ -4,7 +4,7 @@ $('#save-recipe-pos-button').on('click', function(e)
{ {
e.preventDefault(); e.preventDefault();
var jsonData = $('#recipe-pos-form').serializeJSON({ checkboxUncheckedValue: "0" }); var jsonData = $('#recipe-pos-form').serializeJSON();
jsonData.recipe_id = Grocy.EditObjectParentId; jsonData.recipe_id = Grocy.EditObjectParentId;
delete jsonData.display_amount; delete jsonData.display_amount;

View File

@ -205,9 +205,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="track_date_only"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$chore->track_date_only == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="track_date_only" name="track_date_only" value="1"> $chore->track_date_only == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="track_date_only" name="track_date_only" value="1">
@ -222,9 +219,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="rollover"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$chore->rollover == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="rollover" name="rollover" value="1"> $chore->rollover == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="rollover" name="rollover" value="1">
@ -240,9 +234,6 @@
@if(GROCY_FEATURE_FLAG_STOCK) @if(GROCY_FEATURE_FLAG_STOCK)
<div class="form-group mt-4 mb-1"> <div class="form-group mt-4 mb-1">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="consume_product_on_execution"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$chore->consume_product_on_execution == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="consume_product_on_execution" name="consume_product_on_execution" value="1"> $chore->consume_product_on_execution == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="consume_product_on_execution" name="consume_product_on_execution" value="1">

View File

@ -69,9 +69,6 @@
@if(isset($shortcutValue) && isset($shortcutLabel)) @if(isset($shortcutValue) && isset($shortcutLabel))
<div class="form-group mt-n2 mb-0"> <div class="form-group mt-n2 mb-0">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="datetimepicker-shortcut"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="datetimepicker-shortcut" id="datetimepicker-shortcut"

View File

@ -67,9 +67,6 @@
<div class=" <div class="
custom-control custom-control
custom-checkbox"> custom-checkbox">
<input type="hidden"
name="datetimepicker2-shortcut"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="datetimepicker2-shortcut" id="datetimepicker2-shortcut"

View File

@ -77,12 +77,13 @@
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_CHECKBOX) @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_CHECKBOX)
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input class="form-check-input userfield-input custom-control-input" <input class="form-check-input custom-control-input userfield-input"
type="checkbox" type="checkbox"
id="userfield-{{ $userfield->name }}"
data-userfield-name="{{ $userfield->name }}" data-userfield-name="{{ $userfield->name }}"
value="1"> value="1">
<label class="form-check-label custom-control-label" <label class="form-check-label custom-control-label"
for="{{ $userfield->name }}">{{ $userfield->caption }}</label> for="userfield-{{ $userfield->name }}">{{ $userfield->caption }}</label>
</div> </div>
</div> </div>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_PRESET_LIST) @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_PRESET_LIST)

View File

@ -60,9 +60,6 @@
<div id="consume-exact-amount-group" <div id="consume-exact-amount-group"
class="form-group d-none"> class="form-group d-none">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="consume-exact-amount"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="consume-exact-amount" id="consume-exact-amount"
@ -98,9 +95,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="use_specific_stock_entry"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="use_specific_stock_entry" id="use_specific_stock_entry"
@ -123,9 +117,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="spoiled"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="spoiled" id="spoiled"

View File

@ -54,9 +54,6 @@
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING) @if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING)
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="is_freezer"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$location->is_freezer == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="is_freezer" name="is_freezer" value="1"> $location->is_freezer == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="is_freezer" name="is_freezer" value="1">

View File

@ -64,9 +64,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="active"
value="1">
<input @if($mode=='create' <input @if($mode=='create'
) )
checked checked
@ -154,9 +151,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="cumulate_min_stock_amount_of_sub_products"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$product->cumulate_min_stock_amount_of_sub_products == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="cumulate_min_stock_amount_of_sub_products" name="cumulate_min_stock_amount_of_sub_products" value="1"> $product->cumulate_min_stock_amount_of_sub_products == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="cumulate_min_stock_amount_of_sub_products" name="cumulate_min_stock_amount_of_sub_products" value="1">
@ -261,9 +255,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="allow_partial_units_in_stock"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$product->allow_partial_units_in_stock == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="allow_partial_units_in_stock" name="allow_partial_units_in_stock" value="1"> $product->allow_partial_units_in_stock == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="allow_partial_units_in_stock" name="allow_partial_units_in_stock" value="1">
@ -274,9 +265,6 @@
<div class="form-group mb-1"> <div class="form-group mb-1">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="enable_tare_weight_handling"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$product->enable_tare_weight_handling == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="enable_tare_weight_handling" name="enable_tare_weight_handling" value="1"> $product->enable_tare_weight_handling == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="enable_tare_weight_handling" name="enable_tare_weight_handling" value="1">
@ -306,9 +294,6 @@
@if(GROCY_FEATURE_FLAG_RECIPES) @if(GROCY_FEATURE_FLAG_RECIPES)
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="not_check_stock_fulfillment_for_recipes"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$product->not_check_stock_fulfillment_for_recipes == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_stock_fulfillment_for_recipes" name="not_check_stock_fulfillment_for_recipes" value="1"> $product->not_check_stock_fulfillment_for_recipes == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_stock_fulfillment_for_recipes" name="not_check_stock_fulfillment_for_recipes" value="1">

View File

@ -96,9 +96,6 @@
<div class="form-group @if($mode == 'edit') d-none @endif"> <div class="form-group @if($mode == 'edit') d-none @endif">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="create_inverse:skip"
value="0">
<input checked <input checked
class="form-check-input custom-control-input" class="form-check-input custom-control-input"
type="checkbox" type="checkbox"

View File

@ -74,9 +74,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="not_check_shoppinglist"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$recipe->not_check_shoppinglist == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_shoppinglist" name="not_check_shoppinglist" value="1"> $recipe->not_check_shoppinglist == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_shoppinglist" name="not_check_shoppinglist" value="1">

View File

@ -48,9 +48,6 @@
<div class="form-group mb-1"> <div class="form-group mb-1">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="only_check_single_unit_in_stock"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$recipePos->only_check_single_unit_in_stock == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="only_check_single_unit_in_stock" name="only_check_single_unit_in_stock" value="1"> $recipePos->only_check_single_unit_in_stock == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="only_check_single_unit_in_stock" name="only_check_single_unit_in_stock" value="1">
@ -80,9 +77,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="not_check_stock_fulfillment"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
($recipePos->not_check_stock_fulfillment == 1 || FindObjectInArrayByPropertyValue($products, 'id', $recipePos->product_id)->not_check_stock_fulfillment_for_recipes == 1)) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_stock_fulfillment" name="not_check_stock_fulfillment" value="1"> ($recipePos->not_check_stock_fulfillment == 1 || FindObjectInArrayByPropertyValue($products, 'id', $recipePos->product_id)->not_check_stock_fulfillment_for_recipes == 1)) checked @endif class="form-check-input custom-control-input" type="checkbox" id="not_check_stock_fulfillment" name="not_check_stock_fulfillment" value="1">

View File

@ -124,9 +124,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="open"
value="1">
<input @if($stockEntry->open == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="open" name="open" value="1"> <input @if($stockEntry->open == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="open" name="open" value="1">
<label class="form-check-label custom-control-label" <label class="form-check-label custom-control-label"
for="open">{{ $__t('Opened') }}</label> for="open">{{ $__t('Opened') }}</label>

View File

@ -49,9 +49,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="use_specific_stock_entry"
value="0">
<input class="form-check-input custom-control-input" <input class="form-check-input custom-control-input"
type="checkbox" type="checkbox"
id="use_specific_stock_entry" id="use_specific_stock_entry"

View File

@ -69,9 +69,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="show_in_sidebar_menu"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$userentity->show_in_sidebar_menu == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="show_in_sidebar_menu" name="show_in_sidebar_menu" value="1"> $userentity->show_in_sidebar_menu == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="show_in_sidebar_menu" name="show_in_sidebar_menu" value="1">

View File

@ -98,9 +98,6 @@
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
<input type="hidden"
name="show_as_column_in_tables"
value="0">
<input @if($mode=='edit' <input @if($mode=='edit'
&& &&
$userfield->show_as_column_in_tables == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="show_as_column_in_tables" name="show_as_column_in_tables" value="1"> $userfield->show_as_column_in_tables == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="show_as_column_in_tables" name="show_as_column_in_tables" value="1">