var unsaved = false;
function strPackArrInit() {
$('.is-array').each(function(index) {
$(this).prev().append('' +
'');
});
}
function strPackArrAdd(elem) {
elem = elem.parentNode.parentNode.nextElementSibling;
var rows = $(elem).find("tr");
rows.last().after(rows.first().next().clone().removeClass("hidden"));
rows = $(elem).find("tr");
rows.each(function(index) {
index--;
$(this).find("*[name$=']']").each(function(index2) {
if($(this).attr('name') != undefined)
$(this).attr('name', $(this).attr('name').replace('[0]', '[' + index + ']'));
if($(this).attr('id') != undefined)
$(this).attr('id', $(this).attr('id').replace('[0]', '[' + index + ']'));
if($(this).attr('onchange') != undefined)
$(this).attr('onchange', $(this).attr('onchange').replace('[0]', '[' + index + ']'));
});
$(this).find("label[for$=']']").each(function(index2) {
$(this).attr('for', $(this).attr('for').replace('[0]', '[' + index + ']'));
});
});
rows.last().find("input:hidden").val(0);
rows.last().find("select").addClass("selectpicker");
$('.selectpicker').selectpicker('refresh');
}
function strPackArrDel(elem) {
$(elem).parent().parent().remove();
}
function findSubEntries(elem, type, target) {
target = "#" + target.replace("[", "\\[").replace("]", "\\]");
var telem = $(target)[0];
var addText = "neu...";
$(telem.options).each(function(index, elem) {
if($(elem).val() == -1) addText = $(elem).text();
});
if(elem.value != 0) {
$.getJSON("/dynamic/" + type + "/" + $(elem).val(), function(data) {
$(telem).empty();
$(telem).append(new Option("-bitte wählen-", 0));
$.each(data, function(key, value) {
$(telem).append($("", { text: value.text, value: value.value, title: value.title }));
//new Option(value.text, value.value).attr("title", value.title));
});
if($(telem).hasClass("allow-add")) $(telem).append(new Option(addText, -1));
$(telem).selectpicker('refresh');
$(telem).change();
});
} else {
$(telem).empty();
$(telem).append(new Option("-bitte wählen-", 0));
if($(telem).hasClass("allow-add")) $(telem).append(new Option(addText, -1));
$(telem).selectpicker('refresh');
$(telem).change();
}
}
function checkForNew(elem) {
if(elem.value == -1) {
var value = prompt("Bitte geben Sie einen Namen an:", "");
if(value != null && value != "") {
elem.add(new Option(value, value));
elem.value = value;
} else {
elem.value = 0;
}
$(elem).selectpicker('refresh');
}
}
function renewLock(entry, fallback) {
$.getJSON("/lock/" + entry, function(data) {
unsaved = false;
if(!data) document.location.href = fallback;
});
setTimeout(function() {renewLock(entry, fallback)}, 10000);
}
function prefillRows() {
$.each($(".selectEntry"), function(key, value) {
if(value.checked) {
var match = value.id.match(/\[([0-9]+)\]/);
var id = 0;
if(match != null && match.length == 2) id = match[1];
if(id > 0) {
if($("#copyPart").is(":checked")) {
$("#sUnit\\[" + id + "\\]")[0].innerHTML = $("#sUnit\\[-2\\]")[0].innerHTML;
$("#sUnit\\[" + id + "\\]")[0].selectedIndex = $("#sUnit\\[-2\\]")[0].selectedIndex;
$("#sSection\\[" + id + "\\]")[0].innerHTML = $("#sSection\\[-2\\]")[0].innerHTML;
$("#sSection\\[" + id + "\\]")[0].selectedIndex = $("#sSection\\[-2\\]")[0].selectedIndex;
$("#sPart\\[" + id + "\\]")[0].innerHTML = $("#sPart\\[-2\\]")[0].innerHTML;
$("#sPart\\[" + id + "\\]")[0].selectedIndex = $("#sPart\\[-2\\]")[0].selectedIndex;
$("#sSubpart\\[" + id + "\\]")[0].innerHTML = $("#sSubpart\\[-2\\]")[0].innerHTML;
$("#sSubpart\\[" + id + "\\]")[0].selectedIndex = $("#sSubpart\\[-2\\]")[0].selectedIndex;
}
if($("#copyDate").is(":checked")) {
if($("#dates\\[-2\\]")[0].value != "") {
$("#dates\\[" + id + "\\]")[0].value = $("#dates\\[-2\\]")[0].value;
}
}
if($("#copyComment").is(":checked")) {
if($("#comments\\[-2\\]")[0].value != "") {
$("#comments\\[" + id + "\\]")[0].value = $("#comments\\[-2\\]")[0].value;
}
}
}
}
});
$(".selectpicker").selectpicker('refresh');
return false;
}
function checkAll() {
var newState = $('#checkMain')[0].checked;
$.each($('.selectEntry'), function(key, value) {
$(value)[0].checked = newState;
});
}
function openUploadModal(id, type) {
jQuery.event.props.push('dataTransfer');
$("#uploadModal").modal();
var obj = $("#uploadArea");
obj.on("dragenter", function(e) {
e.stopPropagation();
e.preventDefault();
$(this).addClass("dropActive");
});
obj.on("dragleave", function(e) {
e.stopPropagation();
e.preventDefault();
$(this).removeClass("dropActive");
});
obj.on("dragover", function(e) {
e.stopPropagation();
e.preventDefault();
$(this).addClass("dropActive");
});
obj.on("drop", function(e) {
e.stopPropagation();
e.preventDefault();
$(this).removeClass("dropActive");
var files = e.dataTransfer.files;
uploadFiles(files, id, type);
});
$(document).on("dragenter", function(e) {
e.stopPropagation();
e.preventDefault();
});
$(document).on("dragover", function(e) {
e.stopPropagation();
e.preventDefault();
});
$(document).on("drop", function(e) {
e.stopPropagation();
e.preventDefault();
});
}
function setUploadStatus(text, progress) {
progress = Math.round(progress * 100);
if(progress == undefined) {
$("#uploadArea").html(text);
} else {
$("#uploadArea").html(text + "