Added new Userfield type "Link (with title)" (closes #790)

This commit is contained in:
Bernd Bestel 2020-12-21 17:57:48 +01:00
parent e97fccd03a
commit 431a2ab9f7
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
8 changed files with 93 additions and 6 deletions

View File

@ -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

View File

@ -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"

View File

@ -2065,3 +2065,9 @@ msgstr ""
msgid "Merge"
msgstr ""
msgid "Title"
msgstr ""
msgid "Link"
msgstr ""

View File

@ -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 ""

View File

@ -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));
});

View File

@ -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';

View File

@ -13,6 +13,19 @@
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK)
<a href="{{ $userfieldObject->value }}"
target="_blank">{{ $userfieldObject->value }}</a>
@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
<a href="{{ $link }}"
target="_blank">{{ $title }}</a>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE)
<a href="{{ $U('/files/userfiles/'. $userfieldObject->value) }}"
target="_blank">{{ base64_decode(explode('_', $userfieldObject->value)[1]) }}</a>

View File

@ -14,7 +14,7 @@
@if($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_SINGLE_LINE_TEXT)
<div class="form-group">
<label for="name">{{ $userfield->caption }}</label>
<label>{{ $userfield->caption }}</label>
<input type="text"
class="form-control userfield-input"
data-userfield-name="{{ $userfield->name }}">
@ -112,11 +112,31 @@
</div>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK)
<div class="form-group">
<label for="name">{{ $userfield->caption }}</label>
<label>{{ $userfield->caption }}</label>
<input type="link"
class="form-control userfield-input"
data-userfield-name="{{ $userfield->name }}">
</div>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_LINK_WITH_TITLE)
<div class="form-group">
<label class="d-block">{{ $userfield->caption }}</label>
<div class="form-row">
<div class="col-4">
<input type="text"
class="form-control userfield-link userfield-link-title"
placeholder="{{ $__t('Title') }}">
</div>
<div class="col-8">
<input type="link"
class="form-control userfield-link userfield-link-link"
placeholder="{{ $__t('Link') }}">
</div>
<input data-userfield-type="link"
type="hidden"
class="userfield-input"
data-userfield-name="{{ $userfield->name }}">
</div>
</div>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_FILE)
<div class="form-group">
<label>{{ $userfield->caption }}</label>