Files
BeWoPlaner/BeWoPlanerMobil/Scripts/textbausteine.js

110 lines
3.6 KiB
JavaScript

function loadTextbausteineForServiceCategory(serviceCategoryOid) {
makeAjaxCall("GET", loadTextbausteineForCategoryUrl, loadTextbausteineForCategoryOnSuccess, { pServiceCategoryOid: serviceCategoryOid }, null);
}
function loadTextbausteineForCategoryOnSuccess(json) {
if (json === null) {
return;
}
buildTextModuleTree(json);
}
var collapsibleHtml2;
var textModules = new Array();
var allTextModules = new Array();
function buildTextModuleTree(jsonString) {
try {
if (jsonString.length === 0) {
return;
}
textModules = $.parseJSON(jsonString);
$("#kollabierbar2").empty();
collapsibleHtml2 = "";
$.each(textModules, function (index) {
buildTreeRecursively(textModules[index]);
});
$("#kollabierbar2").append(collapsibleHtml2);
} catch (exception) {
console.log("Fehler(BuildCollapsibleSet2): " + exception.message);
}
}
function buildTreeRecursively(textmodule) {
allTextModules[textmodule.Oid] = textmodule;
if (textmodule.IsParent) {
collapsibleHtml2 += '<input onclick="toggleOnclick(this);" type="button" class="toggle-btn" value="' + textmodule.Name + '" style="font-weight: bold;" />';
collapsibleHtml2 += '<div style="display: none; margin-right: 0; padding-right: 0;" class="kollabierbar">';
} else {
collapsibleHtml2 += '<div style="display: block; padding-top: .1em;"><input type="button" style="width: 100%; text-align: left;" onclick="setTextModule(' + textmodule.Oid + ')" value="' + textmodule.Name + '" /></div>';
}
$.each(textmodule.Children,
function (index) {
buildTreeRecursively(textmodule.Children[index]);
}
);
if (textmodule.IsParent) {
collapsibleHtml2 += "</div>";
}
}
function setTextModule(moduleOid) {
if (window.focusedDokuTextarea === null) {
if ($("#trnormalDoku").css("display") !== "none") {
window.focusedDokuTextarea = $("#notiz_textbox");
} else {
window.focusedDokuTextarea = $("#notiz_textbox1");
}
}
window.focusedDokuTextarea.val(window.focusedDokuTextarea.val() + allTextModules[moduleOid].Text);
hideTextModulePopup();
}
function setTextbaustein() {
var selectedTextbausteinOid = $("#textbausteine_select").find(":selected").val();
if (selectedTextbausteinOid > 0) {
makeAjaxCall("GET", loadCompleteTextbausteinByOidUrl, loadTextbausteinContentOnSuccess, { pTextbausteinOid: selectedTextbausteinOid }, null);
}
}
function loadTextbausteinContentOnSuccess(textbausteintext) {
if (focusedDokuTextarea !== null) {
var cursorPosition = focusedDokuTextarea.prop("selectionStart");
var v = focusedDokuTextarea.val();
var textBefore = v.substring(0, cursorPosition);
var textAfter = v.substring(cursorPosition, v.length);
focusedDokuTextarea.val(textBefore + textbausteintext + textAfter);
} else {
console.log("focusedDokuTextarea ist null!");
}
}
function showTextModulesPopup() {
showElement($("#kollabierbar2"));
showElement($("#textModulePopupDivContainer"));
$("#textModulePopupDivContainer").css("height", $("body").css("height"));
showElement($("#textModulePopupDiv"));
var destination = $("#textModulesTr").offset();
var outerHeight = $("#textModulePopupDiv").outerHeight();
$("#textModulePopupDiv").css({ top: destination.top - outerHeight });
}
function hideTextModulePopup() {
$("#textModulePopupDivContainer").hide();
$("#textModulePopupDiv").hide();
$("#kollabierbar2").hide();
}