Added a new userfield type "preset-list" (closes #239)

This commit is contained in:
Bernd Bestel
2019-05-07 21:24:59 +02:00
parent 8504eb9b38
commit 338c6c0a9d
7 changed files with 45 additions and 1 deletions

View File

@@ -1244,3 +1244,9 @@ msgstr[1] ""
msgid "Week costs"
msgstr ""
msgid "Configuration"
msgstr ""
msgid "A predefined list of values, one per line"
msgstr ""

View File

@@ -32,3 +32,6 @@ msgstr ""
msgid "checkbox"
msgstr ""
msgid "preset-list"
msgstr ""

2
migrations/0072.sql Normal file
View File

@@ -0,0 +1,2 @@
ALTER TABLE userfields
ADD config TEXT;

View File

@@ -68,6 +68,22 @@ $('#userfield-form input').keydown(function(event)
}
});
$("#type").on("change", function(e)
{
var value = $(this).val();
if (value === "preset-list")
{
$("#config").parent().removeClass("d-none");
$("#config-hint").text(__t("A predefined list of values, one per line"));
}
else
{
$("#config").parent().addClass("d-none");
$("#config-hint").text("");
}
});
$('#entity').focus();
if (typeof GetUriParam("entity") !== "undefined" && !GetUriParam("entity").isEmpty())
@@ -77,4 +93,5 @@ if (typeof GetUriParam("entity") !== "undefined" && !GetUriParam("entity").isEmp
$('#name').focus();
}
$("#type").trigger("change");
Grocy.FrontendHelpers.ValidateForm('userfield-form');

View File

@@ -11,6 +11,7 @@ class UserfieldsService extends BaseService
const USERFIELD_TYPE_DATE = 'date';
const USERFIELD_TYPE_DATETIME = 'datetime';
const USERFIELD_TYPE_CHECKBOX = 'checkbox';
const USERFIELD_TYPE_PRESET_LIST = 'preset-list';
public function __construct()
{

View File

@@ -74,6 +74,16 @@
<label class="form-check-label" for="{{ $userfield->name }}">{{ $userfield->caption }}</label>
</div>
</div>
@elseif($userfield->type == \Grocy\Services\UserfieldsService::USERFIELD_TYPE_PRESET_LIST)
<div class="form-group">
<label for="{{ $userfield->name }}">{{ $__t('Product group') }}</label>
<select class="form-control userfield-input" data-userfield-name="{{ $userfield->name }}">
<option></option>
@foreach(preg_split('/\r\n|\r|\n/', $userfield->config) as $option)
<option value="{{ $option }}">{{ $option }}</option>
@endforeach
</select>
</div>
@endif
@endforeach

View File

@@ -45,7 +45,7 @@
</div>
<div class="form-group">
<label for="entity">{{ $__t('Type') }}</label>
<label for="type">{{ $__t('Type') }}</label>
<select required class="form-control" id="type" name="type">
<option></option>
@foreach($userfieldTypes as $userfieldType)
@@ -55,6 +55,11 @@
<div class="invalid-feedback">{{ $__t('A type is required') }}</div>
</div>
<div class="form-group d-none">
<label for="config">{{ $__t('Configuration') }} <span id="config-hint" class="small text-muted"></span></label>
<textarea class="form-control" rows="10" id="config" name="config">@if($mode == 'edit'){{ $userfield->config }}@endif</textarea>
</div>
<div class="form-group">
<div class="form-check">
<input type="hidden" name="show_as_column_in_tables" value="0">