From 431a2ab9f7742e6eb9f38a0f29d1b7e43d1e5328 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Mon, 21 Dec 2020 17:57:48 +0100 Subject: [PATCH] Added new Userfield type "Link (with title)" (closes #790) --- changelog/60_3.0.0_2020-12-22.md | 7 ++--- localization/en/userfield_types.po | 3 +++ localization/strings.pot | 6 +++++ localization/userfield_types.pot | 16 ++++++++++++ public/viewjs/components/userfieldsform.js | 29 ++++++++++++++++++++- services/UserfieldsService.php | 1 + views/components/userfields_tbody.blade.php | 13 +++++++++ views/components/userfieldsform.blade.php | 24 +++++++++++++++-- 8 files changed, 93 insertions(+), 6 deletions(-) diff --git a/changelog/60_3.0.0_2020-12-22.md b/changelog/60_3.0.0_2020-12-22.md index 07162703..8cc9a176 100644 --- a/changelog/60_3.0.0_2020-12-22.md +++ b/changelog/60_3.0.0_2020-12-22.md @@ -45,8 +45,8 @@ - On purchase there is now a warning shown, when the due date of the purchased product is earlier than the next due date in stock (enabled by default, can be disabled by a new stock setting (top right corner settings menu)) - The amount to be used for the "quick consume/open buttons" on the stock overview page can now be configured per product (new product option "Quick consume amount", defaults to 1) - This "Quick consume amount" can optionally also be used as the default on the consume page (new stock setting / top right corner settings menu) -- Products can now be duplicated (new button on the products list page, all fields will be preset from the copied product, except the name) -- Products can now be merged (new button on the products list page) +- Products can now be duplicated (new dropdown menu item on the products list page, all fields will be preset from the copied product, except the name) +- Products can now be merged (new dropdown menu item on the products list page) - Useful if you have two products which are basically the same and want to replace all occurrences of one with the other one - When consuming or opening a parent product, which is currently not in stock, any in-stock sub product will now be consumed/opened (like already automatically done when consuming recipes) - Opened stock entries get now consumed first by default when no specific stock entry is used/selected @@ -139,6 +139,8 @@ ### Userfield improvements/fixes - New Userfield type "File" to attach any file, will be rendered as a link to the file in tables (if enabled) (thanks @fipwmaqzufheoxq92ebc) - New Userfield type "Picture" to attach a picture, the picture will be rendered (small) in tables (if enabled) (thanks @fipwmaqzufheoxq92ebc) +- New Userfield type "Link (with title)" - a link with a title (two input fields), so that the title is rendered instead of the link itself +- Users can now also have Userfields - Userfields can now be reordered on the input form (new field "Sort number" per Userfield, fields will be ordered by that number, if any) ### General & other improvements/fixes @@ -157,7 +159,6 @@ - Dialogs are now used everywhere where appropriate instead of jumping between pages (for example when adding/editing shopping list items) - Added a "Clear filter"-button on all pages (with filters) to quickly reset applied filters - Users can now have a picture (will then be shown next to the current user name instead of the generic user icon) - - Users can now also have Userfields - Prefilled number inputs now use sensible decimal places (max. the configured decimals while hiding trailing zeros where appropriate, means if you never use partial amounts for a product, you'll never see decimals for it) - Improved / more precise validation messages for number inputs - Ordering now happens case-insensitive diff --git a/localization/en/userfield_types.po b/localization/en/userfield_types.po index 19da657b..457793bb 100644 --- a/localization/en/userfield_types.po +++ b/localization/en/userfield_types.po @@ -42,6 +42,9 @@ msgstr "Select list (multiple items can be selected)" msgid "link" msgstr "Link" +msgid "link-with-title" +msgstr "Link (with title)" + msgid "file" msgstr "File" diff --git a/localization/strings.pot b/localization/strings.pot index 4a7bf258..408a527d 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2065,3 +2065,9 @@ msgstr "" msgid "Merge" msgstr "" + +msgid "Title" +msgstr "" + +msgid "Link" +msgstr "" diff --git a/localization/userfield_types.pot b/localization/userfield_types.pot index 97ed306e..6c144ed3 100644 --- a/localization/userfield_types.pot +++ b/localization/userfield_types.pot @@ -12,38 +12,54 @@ msgstr "" "Language: en\n" "X-Domain: grocy/userfield_types\n" +# Text (single line) msgid "text-single-line" msgstr "" +# Text (multi line) msgid "text-multi-line" msgstr "" +# Number (integral) msgid "number-integral" msgstr "" +# Number (decimal) msgid "number-decimal" msgstr "" +# Date (without time) msgid "date" msgstr "" +# Date & time msgid "datetime" msgstr "" +# Checkbox msgid "checkbox" msgstr "" +# Select list (a single item can be selected) msgid "preset-list" msgstr "" +# Select list (multiple items can be selected) msgid "preset-checklist" msgstr "" +# Link msgid "link" msgstr "" +# Link (with title) +msgid "link-with-title" +msgstr "" + +# File msgid "file" msgstr "" +# Image msgid "image" msgstr "" diff --git a/public/viewjs/components/userfieldsform.js b/public/viewjs/components/userfieldsform.js index 5b2b8b52..ee18b690 100644 --- a/public/viewjs/components/userfieldsform.js +++ b/public/viewjs/components/userfieldsform.js @@ -110,7 +110,7 @@ Grocy.Components.UserfieldsForm.Load = function() input.val(value.split(",")); $(".selectpicker").selectpicker("render"); } - if (input.attr('type') == "file") + else if (input.attr('type') == "file") { if (value != null && !value.isEmpty()) { @@ -140,6 +140,19 @@ Grocy.Components.UserfieldsForm.Load = function() }); } } + else if (input.attr("data-userfield-type") == "link") + { + if (!value.isEmpty()) + { + var data = JSON.parse(value); + + var formRow = input.parent().parent(); + formRow.find(".userfield-link-title").val(data.title); + formRow.find(".userfield-link-link").val(data.link); + + input.val(value); + } + } else { input.val(value); @@ -152,3 +165,17 @@ Grocy.Components.UserfieldsForm.Load = function() } ); } + +$(".userfield-link").keyup(function(e) +{ + var formRow = $(this).parent().parent(); + var title = formRow.find(".userfield-link-title").val(); + var link = formRow.find(".userfield-link-link").val(); + + var value = { + "title": title, + "link": link + }; + + formRow.find(".userfield-input").val(JSON.stringify(value)); +}); diff --git a/services/UserfieldsService.php b/services/UserfieldsService.php index acdfee45..6e892777 100644 --- a/services/UserfieldsService.php +++ b/services/UserfieldsService.php @@ -12,6 +12,7 @@ class UserfieldsService extends BaseService const USERFIELD_TYPE_IMAGE = 'image'; const USERFIELD_TYPE_INTEGRAL_NUMBER = 'number-integral'; const USERFIELD_TYPE_LINK = 'link'; + const USERFIELD_TYPE_LINK_WITH_TITLE = 'link-with-title'; const USERFIELD_TYPE_PRESET_CHECKLIST = 'preset-checklist'; const USERFIELD_TYPE_PRESET_LIST = 'preset-list'; const USERFIELD_TYPE_SINGLE_LINE_TEXT = 'text-single-line'; diff --git a/views/components/userfields_tbody.blade.php b/views/components/userfields_tbody.blade.php index 1bb3c524..5e9c7f04 100644 --- a/views/components/userfields_tbody.blade.php +++ b/views/components/userfields_tbody.blade.php @@ -13,6 +13,19 @@ @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK) {{ $userfieldObject->value }} + @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK_WITH_TITLE) + @php + $title = ''; + $link = ''; + if(!empty($userfieldObject->value)) + { + $data = json_decode($userfieldObject->value); + $title = $data->title; + $link = $data->link; + } + @endphp + {{ $title }} @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE) {{ base64_decode(explode('_', $userfieldObject->value)[1]) }} diff --git a/views/components/userfieldsform.blade.php b/views/components/userfieldsform.blade.php index 12ebdfa6..bc250c87 100644 --- a/views/components/userfieldsform.blade.php +++ b/views/components/userfieldsform.blade.php @@ -14,7 +14,7 @@ @if($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_SINGLE_LINE_TEXT)
- + @@ -112,11 +112,31 @@
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK)
- +
+ @elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK_WITH_TITLE) +
+ +
+
+ +
+
+ +
+ +
+
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE)