mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Added a new userfield type "preset-list" (closes #239)
This commit is contained in:
@@ -1244,3 +1244,9 @@ msgstr[1] ""
|
||||
|
||||
msgid "Week costs"
|
||||
msgstr ""
|
||||
|
||||
msgid "Configuration"
|
||||
msgstr ""
|
||||
|
||||
msgid "A predefined list of values, one per line"
|
||||
msgstr ""
|
||||
|
@@ -32,3 +32,6 @@ msgstr ""
|
||||
|
||||
msgid "checkbox"
|
||||
msgstr ""
|
||||
|
||||
msgid "preset-list"
|
||||
msgstr ""
|
||||
|
2
migrations/0072.sql
Normal file
2
migrations/0072.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE userfields
|
||||
ADD config TEXT;
|
@@ -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');
|
||||
|
@@ -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()
|
||||
{
|
||||
|
@@ -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
|
||||
|
@@ -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">
|
||||
|
Reference in New Issue
Block a user