mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-14 14:19:33 +00:00
Merge ebb8a2b48b into 3f6a6cc767
This commit is contained in:
commit
30840ac8b2
136 changed files with 23994 additions and 112 deletions
70
assets/controllers/elements/assembly_select_controller.js
Normal file
70
assets/controllers/elements/assembly_select_controller.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import {Controller} from "@hotwired/stimulus";
|
||||
|
||||
import "tom-select/dist/css/tom-select.bootstrap5.css";
|
||||
import '../../css/components/tom-select_extensions.css';
|
||||
import TomSelect from "tom-select";
|
||||
import {marked} from "marked";
|
||||
|
||||
export default class extends Controller {
|
||||
_tomSelect;
|
||||
|
||||
connect() {
|
||||
|
||||
let settings = {
|
||||
allowEmptyOption: true,
|
||||
plugins: ['dropdown_input', 'clear_button'],
|
||||
searchField: ["name", "description", "category", "footprint"],
|
||||
valueField: "id",
|
||||
labelField: "name",
|
||||
preload: "focus",
|
||||
render: {
|
||||
item: (data, escape) => {
|
||||
return '<span>' + (data.image ? "<img style='height: 1.5rem; margin-right: 5px;' ' src='" + data.image + "'/>" : "") + escape(data.name) + '</span>';
|
||||
},
|
||||
option: (data, escape) => {
|
||||
if(data.text) {
|
||||
return '<span>' + escape(data.text) + '</span>';
|
||||
}
|
||||
|
||||
let tmp = '<div class="row m-0">' +
|
||||
"<div class='col-2 p-0 d-flex align-items-center' style='max-width: 80px;'>" +
|
||||
(data.image ? "<img class='typeahead-image' src='" + data.image + "'/>" : "") +
|
||||
"</div>" +
|
||||
"<div class='col-10'>" +
|
||||
'<h6 class="m-0">' + escape(data.name) + '</h6>' +
|
||||
(data.description ? '<p class="m-0">' + marked.parseInline(data.description) + '</p>' : "") +
|
||||
(data.category ? '<p class="m-0"><span class="fa-solid fa-tags fa-fw"></span> ' + escape(data.category) : "");
|
||||
|
||||
return tmp + '</p>' +
|
||||
'</div></div>';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if (this.element.dataset.autocomplete) {
|
||||
const base_url = this.element.dataset.autocomplete;
|
||||
settings.valueField = "id";
|
||||
settings.load = (query, callback) => {
|
||||
const url = base_url.replace('__QUERY__', encodeURIComponent(query));
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(json => {callback(json);})
|
||||
.catch(() => {
|
||||
callback()
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
this._tomSelect = new TomSelect(this.element, settings);
|
||||
//this._tomSelect.clearOptions();
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
super.disconnect();
|
||||
//Destroy the TomSelect instance
|
||||
this._tomSelect.destroy();
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ export default class extends Controller {
|
|||
|
||||
let settings = {
|
||||
allowEmptyOption: true,
|
||||
plugins: ['dropdown_input'],
|
||||
plugins: ['dropdown_input', 'clear_button'],
|
||||
searchField: ["name", "description", "category", "footprint"],
|
||||
valueField: "id",
|
||||
labelField: "name",
|
||||
|
|
|
|||
62
assets/controllers/elements/toggle_visibility_controller.js
Normal file
62
assets/controllers/elements/toggle_visibility_controller.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { Controller } from "@hotwired/stimulus";
|
||||
|
||||
export default class extends Controller {
|
||||
|
||||
static values = {
|
||||
classes: Array
|
||||
};
|
||||
|
||||
connect() {
|
||||
this.displayCheckbox = this.element.querySelector("#display");
|
||||
this.displaySelect = this.element.querySelector("select#display");
|
||||
|
||||
if (this.displayCheckbox) {
|
||||
this.toggleContainers(this.displayCheckbox.checked);
|
||||
|
||||
this.displayCheckbox.addEventListener("change", (event) => {
|
||||
this.toggleContainers(event.target.checked);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.displaySelect) {
|
||||
this.toggleContainers(this.hasDisplaySelectValue());
|
||||
|
||||
this.displaySelect.addEventListener("change", () => {
|
||||
this.toggleContainers(this.hasDisplaySelectValue());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a value was selected in the selectbox
|
||||
* @returns {boolean} True when a value has not been selected that is not empty
|
||||
*/
|
||||
hasDisplaySelectValue() {
|
||||
return this.displaySelect && this.displaySelect.value !== "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides specified containers if the state is active (checkbox checked or select with value).
|
||||
*
|
||||
* @param {boolean} isActive - True when the checkbox is activated or the selectbox has a value.
|
||||
*/
|
||||
toggleContainers(isActive) {
|
||||
if (!Array.isArray(this.classesValue) || this.classesValue.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.classesValue.forEach((cssClass) => {
|
||||
const elements = document.querySelectorAll(`.${cssClass}`);
|
||||
|
||||
if (!elements.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
elements.forEach((element) => {
|
||||
element.style.display = isActive ? "none" : "";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ export default class extends Controller {
|
|||
|
||||
connect() {
|
||||
//Add event listener to the checkbox
|
||||
this.getCheckbox().addEventListener('change', this.toggleInputLimits.bind(this));
|
||||
this.getCheckbox()?.addEventListener('change', this.toggleInputLimits.bind(this));
|
||||
}
|
||||
|
||||
toggleInputLimits() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue