530 lines
17 KiB
JavaScript
530 lines
17 KiB
JavaScript
$(function() {
|
|
// $('.selectpicker').selectpicker();
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
});
|
|
|
|
function update_modal_data_load(e, $ele) {
|
|
var ele = $ele,
|
|
url = ele.data("url"),
|
|
data = { data: ele.data("data"), target: ele.data("target") },
|
|
contentType = "application/x-www-form-urlencoded; charset=UTF-8";
|
|
|
|
console.log(data);
|
|
console.log(url);
|
|
$.ajax({
|
|
url: url,
|
|
data: data,
|
|
type: "POST",
|
|
dataType: "json",
|
|
cache: false,
|
|
contentType: contentType,
|
|
encode: true,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
success: function(data) {
|
|
// do what ever you want here. add content to <div> if it was not 1 .
|
|
$(data.target)
|
|
.find(".modal-content")
|
|
.html(data.response);
|
|
// $('.selectpicker').selectpicker(["refresh"]);
|
|
// $('.input-daterange').datepicker({toggleActive: true,format: 'dd.mm.yyyy'});
|
|
$(data.target).modal("show");
|
|
},
|
|
error: function(xhr, status, errorThrown) {
|
|
console.log(xhr);
|
|
console.log(xhr.responseText);
|
|
console.log(status);
|
|
console.log("Sorry, there was a problem!");
|
|
},
|
|
});
|
|
return false;
|
|
}
|
|
|
|
jQuery(document).ready(function() {
|
|
$(".update_modal_data_load").on("click", function(e) {
|
|
e.preventDefault();
|
|
update_modal_data_load(e, $(this));
|
|
});
|
|
if ($(".datepicker-base").length > 0) {
|
|
$(".datepicker-base").datepicker({
|
|
orientation: "auto right",
|
|
calendarWeeks: true,
|
|
todayBtn: "linked",
|
|
//daysOfWeekDisabled: '1',
|
|
todayHighlight: true,
|
|
multidate: false,
|
|
daysOfWeekHighlighted: "0,6",
|
|
autoclose: true,
|
|
format: "dd.mm.yyyy",
|
|
language: "de",
|
|
clearBtn: true,
|
|
});
|
|
}
|
|
if ($(".datepicker-birthday").length > 0) {
|
|
$(".datepicker-birthday").datepicker({
|
|
todayBtn: "linked",
|
|
// daysOfWeekDisabled: '1',
|
|
multidate: false,
|
|
daysOfWeekHighlighted: "0,6",
|
|
autoclose: true,
|
|
format: "dd.mm.yyyy",
|
|
language: "de",
|
|
clearBtn: true,
|
|
startView: 2,
|
|
});
|
|
}
|
|
if ($(".b-material-datetime-picker").length > 0) {
|
|
$(".b-material-datetime-picker").bootstrapMaterialDatePicker({
|
|
weekStart: 1,
|
|
format: "DD.MM.YYYY HH:mm",
|
|
shortTime: false,
|
|
nowButton: true,
|
|
clearButton: true,
|
|
lang: "de",
|
|
//currentDate: ''
|
|
});
|
|
}
|
|
|
|
$(".form-prevent-multiple-submits").on("submit", function() {
|
|
$(".button-prevent-multiple-submits").attr("disabled", true);
|
|
$(this)
|
|
.find(".spinner")
|
|
.show();
|
|
});
|
|
|
|
// Summernote CustomList Plugin definieren - ZUERST definieren
|
|
// Prüfen, ob Summernote verfügbar ist
|
|
if (typeof $.summernote !== "undefined" && $.summernote.plugins) {
|
|
$.extend($.summernote.plugins, {
|
|
customList: function(context) {
|
|
var self = this;
|
|
var ui = $.summernote.ui;
|
|
|
|
// Button erstellen
|
|
context.memo("button.customList", function() {
|
|
// Button erstellen mit Summernote UI
|
|
var button = ui.button({
|
|
contents: '<i class="fa fa-check-square"></i>',
|
|
tooltip: "Benutzerdefinierte Liste mit Icons",
|
|
container: context.options.container,
|
|
click: function() {
|
|
// --- Logik zum Einfügen der Liste ---
|
|
var listContent = "";
|
|
var range = context.invoke("editor.createRange");
|
|
console.log(range);
|
|
|
|
// Den HTML-Inhalt direkt aus dem Editor holen
|
|
var editorSelection = window.getSelection();
|
|
var selectedHTML = "";
|
|
|
|
if (editorSelection.rangeCount > 0) {
|
|
// Es gibt eine Auswahl
|
|
var selectedRange = editorSelection.getRangeAt(0);
|
|
var selectedContent = selectedRange.cloneContents();
|
|
var tempDiv = document.createElement("div");
|
|
tempDiv.appendChild(selectedContent);
|
|
selectedHTML = tempDiv.innerHTML;
|
|
console.log("Ausgewählter HTML-Inhalt:", selectedHTML);
|
|
}
|
|
|
|
if (selectedHTML) {
|
|
// HTML-Inhalt verarbeiten
|
|
processHTMLContent(selectedHTML);
|
|
} else {
|
|
// Wenn keine Auswahl, versuchen den umgebenden Absatz zu holen
|
|
var selectedNode = range.sc;
|
|
var parentElement = $(selectedNode).closest("p, div");
|
|
|
|
if (parentElement.length > 0) {
|
|
selectedHTML = parentElement.html();
|
|
if (selectedHTML) {
|
|
processHTMLContent(selectedHTML);
|
|
} else {
|
|
insertEmptyList();
|
|
}
|
|
} else {
|
|
insertEmptyList();
|
|
}
|
|
}
|
|
|
|
// Fokus zurück in den Editor
|
|
context.invoke("editor.focus");
|
|
|
|
// Nach dem Einfügen der Liste den Enter-Handler hinzufügen
|
|
setupEnterHandler();
|
|
|
|
// Funktion zum Verarbeiten des HTML-Inhalts
|
|
function processHTMLContent(htmlContent) {
|
|
// HTML in DOM-Element parsen, um es besser verarbeiten zu können
|
|
var tempDiv = document.createElement("div");
|
|
tempDiv.innerHTML = htmlContent;
|
|
|
|
// Text mit HTML-Tags in Zeilen aufteilen
|
|
// Ersetze <br> durch Zeilenumbrüche im DOM
|
|
var brs = tempDiv.querySelectorAll("br");
|
|
for (var i = 0; i < brs.length; i++) {
|
|
brs[i].parentNode.replaceChild(
|
|
document.createTextNode("\n"),
|
|
brs[i]
|
|
);
|
|
}
|
|
|
|
// Jetzt den Text mit Zeilenumbrüchen holen
|
|
var textWithLinebreaks =
|
|
tempDiv.textContent || tempDiv.innerText;
|
|
|
|
// Zeilenumbrüche normalisieren
|
|
var normalizedText = textWithLinebreaks
|
|
.replace(/\r\n/g, "\n")
|
|
.replace(/\r/g, "\n");
|
|
|
|
// Text in Zeilen aufteilen
|
|
var lines = normalizedText.split("\n");
|
|
|
|
// Listenelemente erstellen
|
|
listContent = "";
|
|
lines.forEach(function(line) {
|
|
if (line.trim() !== "") {
|
|
listContent +=
|
|
'<li><i class="fa fa-check text-primary"></i> ' +
|
|
line.trim() +
|
|
"</li>";
|
|
}
|
|
});
|
|
|
|
if (listContent) {
|
|
// Vor dem Einfügen der Liste den ausgewählten Text löschen
|
|
if (range) {
|
|
context.invoke("editor.deleteRange", range);
|
|
}
|
|
|
|
// Liste einfügen
|
|
var listHtml =
|
|
'<ul class="list-unstyled list-icons">' +
|
|
listContent +
|
|
"</ul>";
|
|
context.invoke("editor.pasteHTML", listHtml);
|
|
} else {
|
|
// Fallback: Leere Liste einfügen
|
|
insertEmptyList();
|
|
}
|
|
}
|
|
|
|
// Funktion zum Einfügen einer leeren Liste
|
|
function insertEmptyList() {
|
|
var listHtml =
|
|
'<ul class="list-unstyled list-icons"><li><i class="fa fa-check text-primary"></i> Neue Liste</li></ul>';
|
|
context.invoke("editor.pasteHTML", listHtml);
|
|
}
|
|
},
|
|
});
|
|
|
|
return button.render();
|
|
});
|
|
|
|
// Funktion zum Einrichten des Enter-Handlers
|
|
function setupEnterHandler() {
|
|
// Wir verwenden setTimeout, um sicherzustellen, dass die Liste bereits im DOM ist
|
|
setTimeout(function() {
|
|
var $editor = $(context.layoutInfo.editor);
|
|
var $editable = $(context.layoutInfo.editable);
|
|
|
|
// Event-Handler für die Enter-Taste innerhalb der Liste
|
|
$editable
|
|
.off("keydown.customList")
|
|
.on("keydown.customList", function(e) {
|
|
if (e.keyCode === 13) {
|
|
// Enter-Taste
|
|
var range = context.invoke("editor.createRange");
|
|
var $currentNode = $(range.sc);
|
|
|
|
// Prüfen, ob wir uns in einer Liste befinden
|
|
var $listItem = $currentNode.closest(
|
|
"ul.list-unstyled.list-icons > li"
|
|
);
|
|
|
|
if ($listItem.length > 0) {
|
|
e.preventDefault();
|
|
|
|
// Neuen Listenpunkt erstellen
|
|
var newItem =
|
|
'<li><i class="fa fa-check text-primary"></i> </li>';
|
|
|
|
// Position bestimmen - nach dem aktuellen Listenpunkt einfügen
|
|
$listItem.after(newItem);
|
|
|
|
// Cursor in den neuen Listenpunkt setzen
|
|
var $newItem = $listItem.next("li");
|
|
var textNode = $newItem.contents().filter(function() {
|
|
return this.nodeType === 3; // Text-Node
|
|
})[0];
|
|
|
|
if (textNode) {
|
|
var newRange = document.createRange();
|
|
newRange.setStart(textNode, 1); // Nach dem Leerzeichen positionieren
|
|
newRange.collapse(true);
|
|
|
|
var selection = window.getSelection();
|
|
selection.removeAllRanges();
|
|
selection.addRange(newRange);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
}, 100);
|
|
}
|
|
|
|
// Plugin-Initialisierung
|
|
self.initialize = function() {
|
|
// Nichts zu tun bei der Initialisierung
|
|
console.log("CustomList Plugin initialisiert");
|
|
};
|
|
|
|
// Plugin-Zerstörung (Cleanup)
|
|
self.destroy = function() {
|
|
// Event-Handler entfernen
|
|
$(context.layoutInfo.editable).off("keydown.customList");
|
|
};
|
|
},
|
|
});
|
|
}
|
|
|
|
// Prüfen, ob Summernote bereits in der Blade-Datei initialisiert wurde
|
|
// Wir prüfen, ob die Summernote-Instanz bereits existiert, indem wir nach der data-summernote Eigenschaft suchen
|
|
if (
|
|
typeof $.summernote !== "undefined" &&
|
|
$(".summernote").length > 0 &&
|
|
!$(".summernote").data("summernote")
|
|
) {
|
|
// DANACH die Editoren initialisieren, nur wenn sie nicht bereits initialisiert wurden
|
|
$(".summernote").summernote({
|
|
height: 140,
|
|
lang: "de-DE",
|
|
container: "body",
|
|
styleTags: ["p", "blockquote", "pre", "h1", "h2", "h3", "h4", "h5", "h6"],
|
|
prettifyHtml: false,
|
|
toolbar: [
|
|
// [groupName, [list of button]]
|
|
["style", ["style"]],
|
|
["style", ["bold", "italic", "underline", "clear"]],
|
|
["fontsize", ["fontsize"]],
|
|
["color", ["color"]],
|
|
["para", ["ul", "ol", "paragraph"]],
|
|
["insert", ["customList", "link", "picture", "video"]],
|
|
["height", ["height"]],
|
|
["view", ["fullscreen", "codeview", "help"]],
|
|
],
|
|
|
|
cleaner: {
|
|
action: "both", // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
|
|
newline: "<br>", // Summernote's default is to use '<p><br></p>'
|
|
notStyle: "position:absolute;top:0;left:0;right:0", // Position of Notification
|
|
icon: '<i class="note-icon">[Your Button]</i>',
|
|
keepHtml: true, // Keep all Html formats
|
|
keepOnlyTags: [
|
|
"<p>",
|
|
"<br>",
|
|
"<ul>",
|
|
"<li>",
|
|
"<b>",
|
|
"<strong>",
|
|
"<i>",
|
|
"<a>",
|
|
"<span>",
|
|
"<div>",
|
|
], // If keepHtml is true, remove all tags except these
|
|
keepClasses: true, // Keep Classes
|
|
badTags: [
|
|
"style",
|
|
"script",
|
|
"applet",
|
|
"embed",
|
|
"noframes",
|
|
"noscript",
|
|
"html",
|
|
], // Remove full tags with contents
|
|
badAttributes: ["style", "start"], // Remove attributes from remaining tags
|
|
limitChars: false, // 0/false|# 0/false disables option
|
|
limitDisplay: "both", // text|html|both
|
|
limitStop: false, // true/false
|
|
},
|
|
});
|
|
}
|
|
|
|
// Gleiche Prüfung für summernote-small
|
|
if (
|
|
typeof $.summernote !== "undefined" &&
|
|
$(".summernote-small").length > 0 &&
|
|
!$(".summernote-small").data("summernote")
|
|
) {
|
|
$(".summernote-small").summernote({
|
|
height: 140,
|
|
lang: "de-DE",
|
|
container: "body",
|
|
styleTags: ["p", "blockquote", "pre", "h1", "h2", "h3", "h4", "h5", "h6"],
|
|
prettifyHtml: false,
|
|
toolbar: [
|
|
// [groupName, [list of button]]
|
|
["style", ["style"]],
|
|
["style", ["bold", "italic", "underline", "clear"]],
|
|
["fontsize", ["fontsize"]],
|
|
["color", ["color"]],
|
|
["para", ["ul", "ol", "paragraph"]],
|
|
["insert", ["customList"]],
|
|
["height", ["height"]],
|
|
["view", ["fullscreen", "codeview"]],
|
|
],
|
|
cleaner: {
|
|
action: "both", // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
|
|
newline: "<br>", // Summernote's default is to use '<p><br></p>'
|
|
notStyle: "position:absolute;top:0;left:0;right:0", // Position of Notification
|
|
icon: '<i class="note-icon">[Your Button]</i>',
|
|
keepHtml: true, // Keep all Html formats
|
|
keepOnlyTags: [
|
|
"<p>",
|
|
"<br>",
|
|
"<ul>",
|
|
"<li>",
|
|
"<b>",
|
|
"<strong>",
|
|
"<i>",
|
|
"<a>",
|
|
"<span>",
|
|
"<div>",
|
|
], // If keepHtml is true, remove all tags except these
|
|
keepClasses: true, // Keep Classes
|
|
badTags: [
|
|
"style",
|
|
"script",
|
|
"applet",
|
|
"embed",
|
|
"noframes",
|
|
"noscript",
|
|
"html",
|
|
], // Remove full tags with contents
|
|
badAttributes: ["style", "start"], // Remove attributes from remaining tags
|
|
limitChars: false, // 0/false|# 0/false disables option
|
|
limitDisplay: "both", // text|html|both
|
|
limitStop: false, // true/false
|
|
},
|
|
});
|
|
}
|
|
|
|
$(".note-status-output").hide();
|
|
});
|
|
|
|
function _scrollTo(to, offset) {
|
|
$("html,body").animate({ scrollTop: $(to).offset().top - offset }, 800);
|
|
}
|
|
function ajax_object_action(event, object, callback) {
|
|
// event.preventDefault();
|
|
var data = {};
|
|
$.each(object.data(), function(index, value) {
|
|
if (typeof value !== "object") {
|
|
data[index] = value;
|
|
}
|
|
});
|
|
var url = data["url"];
|
|
// console.log(data);
|
|
// console.log(url);
|
|
$.ajax({
|
|
url: url,
|
|
data: data,
|
|
type: "POST",
|
|
dataType: "json",
|
|
cache: false,
|
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
|
encode: true,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
success: function(data) {
|
|
//console.log(data);
|
|
//data will send data to callback function
|
|
callback(data);
|
|
},
|
|
error: function(xhr, status, errorThrown) {
|
|
console.log(xhr);
|
|
console.log(xhr.responseText);
|
|
console.log(status);
|
|
console.log(errorThrown);
|
|
console.log("Sorry, there was a problem!");
|
|
},
|
|
});
|
|
return false;
|
|
}
|
|
$(function() {
|
|
$("#modals-load-content").on("show.bs.modal", function(event) {
|
|
var button = $(event.relatedTarget);
|
|
if (!button.data("id")) {
|
|
return;
|
|
}
|
|
var data = {};
|
|
$.each(button.data(), function(index, value) {
|
|
if (index !== "bs.tooltip") {
|
|
data[index] = value;
|
|
}
|
|
});
|
|
console.log(data);
|
|
|
|
loadModalInner(this, data);
|
|
});
|
|
|
|
function initModalInner() {
|
|
$('[data-toggle="reloadModal"]')
|
|
.off()
|
|
.on("click", function(event) {
|
|
event.preventDefault();
|
|
button = $(this);
|
|
var data = {};
|
|
$.each(button.data(), function(index, value) {
|
|
if (index !== "bs.tooltip") {
|
|
data[index] = value;
|
|
}
|
|
});
|
|
//console.log(data);
|
|
loadModalInner(this, data);
|
|
});
|
|
}
|
|
function loadModalInner(self, data) {
|
|
var url = data.route,
|
|
contentType = "application/x-www-form-urlencoded; charset=UTF-8";
|
|
$.ajax({
|
|
url: url,
|
|
data: data,
|
|
type: "POST",
|
|
dataType: "json",
|
|
cache: false,
|
|
contentType: contentType,
|
|
encode: true,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
success: function(data) {
|
|
console.log(data);
|
|
if (data.response.modal) {
|
|
$(data.response.target)
|
|
.find(".modal-dialog")
|
|
.addClass(data.response.modal);
|
|
}
|
|
$(data.response.target)
|
|
.find(".modal-dialog")
|
|
.html(data.html);
|
|
$(data.response.target)
|
|
.find(".selectpicker")
|
|
.selectpicker("refresh");
|
|
initModalInner();
|
|
},
|
|
error: function(xhr, status, errorThrown) {
|
|
console.log(xhr);
|
|
console.log(xhr.responseText);
|
|
console.log(errorThrown);
|
|
console.log("Sorry, there was a problem!");
|
|
},
|
|
});
|
|
return false;
|
|
}
|
|
});
|