diff --git a/changelog/52_UNRELEASED_2019-xx-xx.md b/changelog/52_UNRELEASED_2019-xx-xx.md index 6bc19dcd..b745a2fc 100644 --- a/changelog/52_UNRELEASED_2019-xx-xx.md +++ b/changelog/52_UNRELEASED_2019-xx-xx.md @@ -19,6 +19,8 @@ - When tracking an execution from the chores overview page, filter are re-applied afterwards (means when have filtered the page to only show overdue chores and after the execution the chore is not overdue anymore, it will now immediately hide id) - Equipment improvements/fixes - Fixed that the delete button not always deleted the currently selected equipment item +- Userfield improvements + - New userfield type "Select list" for a list of predefined values where a single or also multiple values can then be selected on the entity object - General improvements/fixes - Improved the handling which entry page to use with disabled feature flags (thanks @nielstholenaar) - Fixed that the Userfield type "Preset list" had always the caption "Product group" instead of the configured one (thanks @oncleben31) diff --git a/localization/en/userfield_types.po b/localization/en/userfield_types.po index 80dff244..ffc95ec9 100644 --- a/localization/en/userfield_types.po +++ b/localization/en/userfield_types.po @@ -32,3 +32,9 @@ msgstr "Date & time" msgid "checkbox" msgstr "Checkbox" + +msgid "preset-list" +msgstr "Select list (a single item can be selected)" + +msgid "preset-checklist" +msgstr "Select list (multiple items can be selected)" diff --git a/localization/userfield_types.pot b/localization/userfield_types.pot index 38f2943e..2a7b7e1a 100644 --- a/localization/userfield_types.pot +++ b/localization/userfield_types.pot @@ -35,3 +35,6 @@ msgstr "" msgid "preset-list" msgstr "" + +msgid "preset-checklist" +msgstr "" diff --git a/public/js/extensions.js b/public/js/extensions.js index c67f92be..9b7d2ae0 100644 --- a/public/js/extensions.js +++ b/public/js/extensions.js @@ -112,3 +112,8 @@ FindAllObjectsInArrayByPropertyValue = function(array, propertyName, propertyVal return returnArray; } + +$.fn.hasAttr = function(name) +{ + return this.attr(name) !== undefined; +}; diff --git a/public/viewjs/components/userfieldsform.js b/public/viewjs/components/userfieldsform.js index e6e4ae1e..b6260238 100644 --- a/public/viewjs/components/userfieldsform.js +++ b/public/viewjs/components/userfieldsform.js @@ -14,7 +14,7 @@ Grocy.Components.UserfieldsForm.Save = function(success, error) var jsonData = { }; - $("#userfields-form .userfield-input").each(function() + $("#userfields-form .userfield-input").not("div").each(function() { var input = $(this); var fieldName = input.attr("data-userfield-name"); @@ -28,6 +28,10 @@ Grocy.Components.UserfieldsForm.Save = function(success, error) jsonData[fieldName] = "1"; } } + else if ($(this).hasAttr("multiple")) + { + jsonData[fieldName] = $(this).val().join(","); + } else { jsonData[fieldName] = fieldValue; @@ -70,6 +74,11 @@ Grocy.Components.UserfieldsForm.Load = function() { input.prop("checked", true); } + else if (input.hasAttr("multiple")) + { + input.val(value.split(",")); + $(".selectpicker").selectpicker("render"); + } else { input.val(value); diff --git a/public/viewjs/userfieldform.js b/public/viewjs/userfieldform.js index f7f72913..45022968 100644 --- a/public/viewjs/userfieldform.js +++ b/public/viewjs/userfieldform.js @@ -72,7 +72,7 @@ $("#type").on("change", function(e) { var value = $(this).val(); - if (value === "preset-list") + if (value === "preset-list" || value === "preset-checklist") { $("#config").parent().removeClass("d-none"); $("#config-hint").text(__t("A predefined list of values, one per line")); diff --git a/services/UserfieldsService.php b/services/UserfieldsService.php index 7c8279b9..cb162146 100644 --- a/services/UserfieldsService.php +++ b/services/UserfieldsService.php @@ -12,6 +12,7 @@ class UserfieldsService extends BaseService const USERFIELD_TYPE_DATETIME = 'datetime'; const USERFIELD_TYPE_CHECKBOX = 'checkbox'; const USERFIELD_TYPE_PRESET_LIST = 'preset-list'; + const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist'; public function __construct() { diff --git a/views/choreform.blade.php b/views/choreform.blade.php index 17a3eaaf..9d6277b8 100644 --- a/views/choreform.blade.php +++ b/views/choreform.blade.php @@ -8,15 +8,6 @@ @section('viewJsName', 'choreform') -@push('pageScripts') - - @if(!empty($__t('bootstrap-select_locale') && $__t('bootstrap-select_locale') != 'x'))@endif -@endpush - -@push('pageStyles') - -@endpush - @section('content')
diff --git a/views/components/userfields_tbody.blade.php b/views/components/userfields_tbody.blade.php index 8ec2c728..ae99cdd9 100644 --- a/views/components/userfields_tbody.blade.php +++ b/views/components/userfields_tbody.blade.php @@ -7,9 +7,11 @@ @if($userfieldObject !== null) @if($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_CHECKBOX) - @if($userfieldObject->value == 1)@endif + @if($userfieldObject->value == 1)@endif + @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_PRESET_CHECKLIST) + {!! str_replace(',', '
', $userfieldObject->value) !!} @else - {{ $userfieldObject->value }} + {{ $userfieldObject->value }} @endif @endif diff --git a/views/components/userfieldsform.blade.php b/views/components/userfieldsform.blade.php index 6c8b63a8..50462b9a 100644 --- a/views/components/userfieldsform.blade.php +++ b/views/components/userfieldsform.blade.php @@ -84,6 +84,15 @@ @endforeach
+ @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_PRESET_CHECKLIST) +
+ + +
@endif @endforeach diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 2fb655c8..73d91932 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -35,6 +35,7 @@ + @@ -387,6 +388,8 @@ @if(!empty($__t('summernote_locale') && $__t('summernote_locale') != 'x'))@endif + + @if(!empty($__t('bootstrap-select_locale') && $__t('bootstrap-select_locale') != 'x'))@endif