mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed CurrencyEntityType
This commit is contained in:
parent
8d5427a1c3
commit
672d55624f
5 changed files with 59 additions and 8 deletions
|
@ -26,11 +26,17 @@ import {Controller} from "@hotwired/stimulus";
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
_tomSelect;
|
_tomSelect;
|
||||||
|
|
||||||
|
_emptyMessage;
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
|
|
||||||
|
//Extract empty message from data attribute
|
||||||
|
this._emptyMessage = this.element.getAttribute("data-empty-message") ?? "";
|
||||||
|
|
||||||
let settings = {
|
let settings = {
|
||||||
allowEmptyOption: true,
|
allowEmptyOption: true,
|
||||||
selectOnTab: true,
|
selectOnTab: true,
|
||||||
|
maxOptions: null,
|
||||||
|
|
||||||
searchField: [
|
searchField: [
|
||||||
{field: "text", weight : 2},
|
{field: "text", weight : 2},
|
||||||
|
@ -38,8 +44,8 @@ export default class extends Controller {
|
||||||
],
|
],
|
||||||
|
|
||||||
render: {
|
render: {
|
||||||
item: this.renderItem,
|
item: this.renderItem.bind(this),
|
||||||
option: this.renderOption,
|
option: this.renderOption.bind(this),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,6 +53,19 @@ export default class extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItem(data, escape) {
|
renderItem(data, escape) {
|
||||||
|
//Render empty option as full row
|
||||||
|
if (data.value === "") {
|
||||||
|
if (this._emptyMessage) {
|
||||||
|
return '<div class="tom-select-empty-option"><span class="text-muted"><b>' + escape(this._emptyMessage) + '</b></span></div>';
|
||||||
|
} else {
|
||||||
|
return '<div> </div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.short) {
|
||||||
|
return '<div><b>' + escape(data.short) + '</b></div>';
|
||||||
|
}
|
||||||
|
|
||||||
let name = "";
|
let name = "";
|
||||||
if (data.parent) {
|
if (data.parent) {
|
||||||
name += escape(data.parent) + " → ";
|
name += escape(data.parent) + " → ";
|
||||||
|
@ -59,18 +78,27 @@ export default class extends Controller {
|
||||||
renderOption(data, escape) {
|
renderOption(data, escape) {
|
||||||
//Render empty option as full row
|
//Render empty option as full row
|
||||||
if (data.value === "") {
|
if (data.value === "") {
|
||||||
|
if (this._emptyMessage) {
|
||||||
|
return '<div class="tom-select-empty-option"><span class="text-muted">' + escape(this._emptyMessage) + '</span></div>';
|
||||||
|
} else {
|
||||||
return '<div> </div>';
|
return '<div> </div>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Indent the option according to the level
|
//Indent the option according to the level
|
||||||
const level_html = ' '.repeat(data.level);
|
let level_html = ' '.repeat(data.level);
|
||||||
|
|
||||||
let filter_badge = "";
|
let filter_badge = "";
|
||||||
if (data.filetype_filter) {
|
if (data.filetype_filter) {
|
||||||
filter_badge = '<span class="badge bg-warning float-end"><i class="fa-solid fa-file-circle-exclamation"></i> ' + escape(data.filetype_filter) + '</span>';
|
filter_badge = '<span class="badge bg-warning float-end"><i class="fa-solid fa-file-circle-exclamation"></i> ' + escape(data.filetype_filter) + '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let symbol_badge = "";
|
||||||
|
if (data.symbol) {
|
||||||
|
symbol_badge = '<span class="badge bg-primary ms-2">' + escape(data.symbol) + '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
let parent_badge = "";
|
let parent_badge = "";
|
||||||
if (data.parent) {
|
if (data.parent) {
|
||||||
parent_badge = '<span class="ms-3 badge rounded-pill bg-secondary float-end picker-us"><i class="fa-solid fa-folder-tree"></i> ' + escape(data.parent) + '</span>';
|
parent_badge = '<span class="ms-3 badge rounded-pill bg-secondary float-end picker-us"><i class="fa-solid fa-folder-tree"></i> ' + escape(data.parent) + '</span>';
|
||||||
|
@ -81,7 +109,7 @@ export default class extends Controller {
|
||||||
image = '<img style="max-height: 1.5rem; max-width: 2rem; margin-left: 5px;" src="' + data.image + '"/>';
|
image = '<img style="max-height: 1.5rem; max-width: 2rem; margin-left: 5px;" src="' + data.image + '"/>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<div>' + level_html + escape(data.text) + image + parent_badge + filter_badge + '</div>';
|
return '<div>' + level_html + escape(data.text) + image + symbol_badge + parent_badge + filter_badge + '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,29 @@ class CurrencyEntityType extends StructuralEntityType
|
||||||
$resolver->setDefault('short', false);
|
$resolver->setDefault('short', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function generateChoiceAttr(AbstractStructuralDBElement $choice, $key, $value, $options): array
|
||||||
|
{
|
||||||
|
$tmp = parent::generateChoiceAttr($choice, $key, $value, $options);
|
||||||
|
|
||||||
|
if(!empty($choice->getIsoCode())) {
|
||||||
|
$symbol = Currencies::getSymbol($choice->getIsoCode());
|
||||||
|
} else {
|
||||||
|
$symbol = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($options['short']) {
|
||||||
|
$tmp['data-short'] = $symbol;
|
||||||
|
} else {
|
||||||
|
$tmp['data-short'] = $choice->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp += [
|
||||||
|
'data-symbol' => $symbol,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getChoiceContent(AbstractStructuralDBElement $choice, $key, $value, $options): string
|
protected function getChoiceContent(AbstractStructuralDBElement $choice, $key, $value, $options): string
|
||||||
{
|
{
|
||||||
if(!$choice instanceof Currency) {
|
if(!$choice instanceof Currency) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ class StructuralEntityType extends AbstractType
|
||||||
'data-controller' => $options['controller'],
|
'data-controller' => $options['controller'],
|
||||||
];
|
];
|
||||||
if ($options['empty_message']) {
|
if ($options['empty_message']) {
|
||||||
$tmp['data-empty_message'] = $options['empty_message'];
|
$tmp['data-empty-message'] = $options['empty_message'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
{{ form_widget(form.price) }}
|
{{ form_widget(form.price) }}
|
||||||
{{ form_widget(form.priceCurrency, {'attr': {'class': 'selectpicker', 'data-controller': 'elements--selectpicker'}}) }}
|
{{ form_widget(form.priceCurrency) }}
|
||||||
</div>
|
</div>
|
||||||
{{ form_errors(form.price) }}
|
{{ form_errors(form.price) }}
|
||||||
{{ form_errors(form.priceCurrency) }}
|
{{ form_errors(form.priceCurrency) }}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
{{ form_widget(form.price) }}
|
{{ form_widget(form.price) }}
|
||||||
{{ form_widget(form.currency, {'attr': {'class': 'selectpicker form-control-sm', 'data-controller': 'elements--selectpicker'}}) }}
|
{{ form_widget(form.currency, {'attr': {'class': 'form-control-sm'}}) }}
|
||||||
</div>
|
</div>
|
||||||
{{ form_errors(form.price) }}
|
{{ form_errors(form.price) }}
|
||||||
{{ form_errors(form.currency) }}
|
{{ form_errors(form.currency) }}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue