mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +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 {
|
||||
_tomSelect;
|
||||
|
||||
_emptyMessage;
|
||||
|
||||
connect() {
|
||||
|
||||
//Extract empty message from data attribute
|
||||
this._emptyMessage = this.element.getAttribute("data-empty-message") ?? "";
|
||||
|
||||
let settings = {
|
||||
allowEmptyOption: true,
|
||||
selectOnTab: true,
|
||||
maxOptions: null,
|
||||
|
||||
searchField: [
|
||||
{field: "text", weight : 2},
|
||||
|
@ -38,8 +44,8 @@ export default class extends Controller {
|
|||
],
|
||||
|
||||
render: {
|
||||
item: this.renderItem,
|
||||
option: this.renderOption,
|
||||
item: this.renderItem.bind(this),
|
||||
option: this.renderOption.bind(this),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -47,6 +53,19 @@ export default class extends Controller {
|
|||
}
|
||||
|
||||
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 = "";
|
||||
if (data.parent) {
|
||||
name += escape(data.parent) + " → ";
|
||||
|
@ -59,18 +78,27 @@ export default class extends Controller {
|
|||
renderOption(data, escape) {
|
||||
//Render empty option as full row
|
||||
if (data.value === "") {
|
||||
return '<div> </div>';
|
||||
if (this._emptyMessage) {
|
||||
return '<div class="tom-select-empty-option"><span class="text-muted">' + escape(this._emptyMessage) + '</span></div>';
|
||||
} else {
|
||||
return '<div> </div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Indent the option according to the level
|
||||
const level_html = ' '.repeat(data.level);
|
||||
let level_html = ' '.repeat(data.level);
|
||||
|
||||
let filter_badge = "";
|
||||
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>';
|
||||
}
|
||||
|
||||
let symbol_badge = "";
|
||||
if (data.symbol) {
|
||||
symbol_badge = '<span class="badge bg-primary ms-2">' + escape(data.symbol) + '</span>';
|
||||
}
|
||||
|
||||
let parent_badge = "";
|
||||
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>';
|
||||
|
@ -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 + '"/>';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if(!$choice instanceof Currency) {
|
||||
|
|
|
@ -104,7 +104,7 @@ class StructuralEntityType extends AbstractType
|
|||
'data-controller' => $options['controller'],
|
||||
];
|
||||
if ($options['empty_message']) {
|
||||
$tmp['data-empty_message'] = $options['empty_message'];
|
||||
$tmp['data-empty-message'] = $options['empty_message'];
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<div class="col-sm-9">
|
||||
<div class="input-group">
|
||||
{{ form_widget(form.price) }}
|
||||
{{ form_widget(form.priceCurrency, {'attr': {'class': 'selectpicker', 'data-controller': 'elements--selectpicker'}}) }}
|
||||
{{ form_widget(form.priceCurrency) }}
|
||||
</div>
|
||||
{{ form_errors(form.price) }}
|
||||
{{ form_errors(form.priceCurrency) }}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<td>
|
||||
<div class="input-group input-group-sm">
|
||||
{{ 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>
|
||||
{{ form_errors(form.price) }}
|
||||
{{ form_errors(form.currency) }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue