223 lines
8.9 KiB
JavaScript
223 lines
8.9 KiB
JavaScript
|
|
$(document).ready(function () {
|
||
|
|
// Hole die aktuelle URL
|
||
|
|
var currentUrl = window.location.href;
|
||
|
|
|
||
|
|
// Überprüfen, ob ?action= in der URL vorhanden ist
|
||
|
|
if (currentUrl.indexOf("?action=") !== -1) {
|
||
|
|
// Entferne den Teil ab ?action=, inkl. allem, was danach kommt
|
||
|
|
var newUrl = currentUrl.split("?action=")[0];
|
||
|
|
|
||
|
|
// Aktualisiere die URL ohne Neuladen der Seite
|
||
|
|
window.history.replaceState(null, null, newUrl);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
document.addEventListener("DOMContentLoaded", function () {
|
||
|
|
// Initial load of category data
|
||
|
|
const categorySelect = document.getElementById('input_category');
|
||
|
|
if (categorySelect) {
|
||
|
|
let selectedId = categorySelect.value;
|
||
|
|
removeAjaxContent();
|
||
|
|
|
||
|
|
// Initial AJAX call
|
||
|
|
fetchCategoryData(selectedId);
|
||
|
|
|
||
|
|
// Add change event listener to category select
|
||
|
|
categorySelect.addEventListener('change', function() {
|
||
|
|
selectedId = this.value;
|
||
|
|
removeAjaxContent();
|
||
|
|
fetchCategoryData(selectedId);
|
||
|
|
getCategoryDescription();
|
||
|
|
});
|
||
|
|
|
||
|
|
// Initial description load
|
||
|
|
getCategoryDescription();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Helper function to remove ajax content
|
||
|
|
function removeAjaxContent() {
|
||
|
|
const ajaxContents = document.querySelectorAll('.ajax-content');
|
||
|
|
ajaxContents.forEach(content => content.remove());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Helper function to remove ajax subcontent
|
||
|
|
function removeAjaxSubContent() {
|
||
|
|
const ajaxSubContents = document.querySelectorAll('.ajax-subcontent');
|
||
|
|
ajaxSubContents.forEach(content => content.remove());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Fetch category data via AJAX
|
||
|
|
function fetchCategoryData(categoryId) {
|
||
|
|
$.ajax({
|
||
|
|
url: '/module/ticketcenter/views/ticketcenter/show_ticketcenter_ajax.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { category_id: categoryId },
|
||
|
|
success: function (response) {
|
||
|
|
const categorySelect = document.getElementById('input_category');
|
||
|
|
const parentDiv = categorySelect.parentNode;
|
||
|
|
|
||
|
|
// Insert response after the parent div
|
||
|
|
const ajaxContent = document.createElement('div');
|
||
|
|
ajaxContent.className = 'ajax-content';
|
||
|
|
ajaxContent.innerHTML = response;
|
||
|
|
parentDiv.after(ajaxContent);
|
||
|
|
|
||
|
|
// Add event listener to subcategory select if it exists
|
||
|
|
const subcategorySelect = document.getElementById('input_subcategory');
|
||
|
|
if (subcategorySelect) {
|
||
|
|
subcategorySelect.addEventListener('change', function() {
|
||
|
|
getSubCategoryDescription();
|
||
|
|
getSubSubCategory();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (xhr, status, error) {
|
||
|
|
console.log('Error:', error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getCategoryDescription() {
|
||
|
|
const categorySelect = document.getElementById('input_category');
|
||
|
|
const selectedId = categorySelect.value;
|
||
|
|
|
||
|
|
// Remove existing description if it exists
|
||
|
|
const existingDesc = document.querySelector(".category_desc");
|
||
|
|
if (existingDesc) {
|
||
|
|
existingDesc.remove();
|
||
|
|
}
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: '/module/ticketcenter/views/ticketcenter/show_ticketcenter_category_desc_ajax.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { category_id: selectedId },
|
||
|
|
success: function (response) {
|
||
|
|
const instructionDiv = document.querySelector(".ticket-instruction");
|
||
|
|
if (instructionDiv) {
|
||
|
|
const descDiv = document.createElement('div');
|
||
|
|
descDiv.className = 'category_desc';
|
||
|
|
descDiv.innerHTML = "<h5>Kategoriebeschreibung</h5>" + response;
|
||
|
|
instructionDiv.insertAdjacentElement("afterbegin", descDiv);
|
||
|
|
if (response.trim() === "") {
|
||
|
|
descDiv.style.display = 'none'; // Hide if no description
|
||
|
|
} else {
|
||
|
|
descDiv.style.display = 'block'; // Show if description exists
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (xhr, status, error) {
|
||
|
|
console.log('Error:', error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getSubCategoryDescription() {
|
||
|
|
const subcategorySelect = document.getElementById('input_subcategory');
|
||
|
|
if (!subcategorySelect) return;
|
||
|
|
|
||
|
|
const selectedId = subcategorySelect.value;
|
||
|
|
|
||
|
|
// Remove existing description if it exists
|
||
|
|
const existingDesc = document.querySelector(".subcategory_desc");
|
||
|
|
if (existingDesc) {
|
||
|
|
existingDesc.remove();
|
||
|
|
}
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: '/module/ticketcenter/views/ticketcenter/show_ticketcenter_category_desc_ajax.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { category_id: selectedId },
|
||
|
|
success: function (response) {
|
||
|
|
const instructionDiv = document.querySelector(".ticket-instruction");
|
||
|
|
if (instructionDiv) {
|
||
|
|
const descDiv = document.createElement('div');
|
||
|
|
descDiv.className = 'subcategory_desc';
|
||
|
|
descDiv.style.marginTop = '20px';
|
||
|
|
descDiv.innerHTML = "<h5>Unterkategoriebeschreibung</h5>" + response;
|
||
|
|
instructionDiv.insertAdjacentElement("beforeend", descDiv);
|
||
|
|
if (response.trim() === "") {
|
||
|
|
descDiv.style.display = 'none'; // Hide if no description
|
||
|
|
} else {
|
||
|
|
descDiv.style.display = 'block'; // Show if description exists
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (xhr, status, error) {
|
||
|
|
console.log('Error:', error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getSubSubCategoryDescription() {
|
||
|
|
const subsubcategorySelect = document.getElementById('input_subsubcategory');
|
||
|
|
if (!subsubcategorySelect) return;
|
||
|
|
|
||
|
|
const selectedId = subsubcategorySelect.value;
|
||
|
|
|
||
|
|
// Remove existing description if it exists
|
||
|
|
const existingDesc = document.querySelector(".subsubcategory_desc");
|
||
|
|
if (existingDesc) {
|
||
|
|
existingDesc.remove();
|
||
|
|
}
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: '/module/ticketcenter/views/ticketcenter/show_ticketcenter_category_desc_ajax.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { category_id: selectedId },
|
||
|
|
success: function (response) {
|
||
|
|
const instructionDiv = document.querySelector(".ticket-instruction");
|
||
|
|
if (instructionDiv) {
|
||
|
|
const descDiv = document.createElement('div');
|
||
|
|
descDiv.className = 'subsubcategory_desc';
|
||
|
|
descDiv.style.marginTop = '20px';
|
||
|
|
descDiv.innerHTML = "<h5>Beschreibung</h5>" + response;
|
||
|
|
instructionDiv.insertAdjacentElement("beforeend", descDiv);
|
||
|
|
if (response.trim() === "") {
|
||
|
|
descDiv.style.display = 'none'; // Hide if no description
|
||
|
|
} else {
|
||
|
|
descDiv.style.display = 'block'; // Show if description exists
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (xhr, status, error) {
|
||
|
|
console.log('Error:', error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function getSubSubCategory() {
|
||
|
|
const subcategorySelect = document.getElementById('input_subcategory');
|
||
|
|
if (!subcategorySelect) return;
|
||
|
|
|
||
|
|
const selectedId = subcategorySelect.value;
|
||
|
|
removeAjaxSubContent();
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: '/module/ticketcenter/show_ticketcenter_subcategory_ajax.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { category_id: selectedId },
|
||
|
|
success: function (response) {
|
||
|
|
const parentDiv = subcategorySelect.parentNode;
|
||
|
|
|
||
|
|
// Insert response after the parent div
|
||
|
|
const ajaxSubContent = document.createElement('div');
|
||
|
|
ajaxSubContent.className = 'ajax-subcontent';
|
||
|
|
ajaxSubContent.innerHTML = response;
|
||
|
|
parentDiv.after(ajaxSubContent);
|
||
|
|
|
||
|
|
// Add event listener to subsubcategory select if it exists
|
||
|
|
const subsubcategorySelect = document.getElementById('input_subsubcategory');
|
||
|
|
if (subsubcategorySelect) {
|
||
|
|
subsubcategorySelect.addEventListener('change', function() {
|
||
|
|
getSubSubCategoryDescription();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
error: function (xhr, status, error) {
|
||
|
|
console.log('Error:', error);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|