//delete = delets from DB
//remove = removes from HTML
//save = save to DB
//add = changes HTML
//get = get from DB
//new = changes HTML
var pictureWidth = 1280;
var pictureHeight = 720;
function overlayOn(value, special="") {
if(special == "image"){
url = urlUniversalStorage + "ui/?iframe&path=Stationsbilder/Gesamtbilder/Station3"
}
else if(special == "assigment"){
url = urlUniversalStorage + "ui/?iframe&path=Stationsbilder/Einzelbilder/Station3"
}
else{
url = urlUniversalStorage + "ui/?iframe"
}
document.getElementById("overlay").style.display = "block";
var iframe = $('#overlaycontentsize').append("");
iframe.find("#overlaycontent").bind('load',{"ka": value}, function(event){
var ref = this.contentWindow.ref;
//You can think that ref = $(this.contentWindow.test) but thery are different
//they are two diferent references this might be a bug
ref.bind('getUrl',{"xyz": event.data.ka}, function(event, extra1){
var data = event.data
overlayOff();
//fill input with url
if(special == ""){
$(data.xyz).parent().parent().find(".abbreviationInput").val(extra1.url)
}
else if (special == "assigment"){
$(data.xyz).parent().parent().find(".abbreviationInput").val(extra1.url)
getImgText(extra1.url)
}
else if (special == "image"){
clearForm();
//hide current image
var newSrc = extra1.url + "?rand=" + Math.random();
image = new Image();
$("#sliceImg").hide("puff")
//show new image and perform a resize of the rectangle
image.onload = function() {
$("#sliceImg").hide("puff", function() {
$(this).attr("src", newSrc).show("fold");
resizeAllRect();
fillFormName(extra1.url.substring(extra1.url.lastIndexOf('/') + 1).replace(/\.[^/.]+$/, ""));
});
}
image.src = newSrc;
// $("#sliceImg").attr("src",extra1.url + "?rand=" + Math.random() )
// resizeAllRect()
}
});
});
}
function overlayOnImg(data) {
var url = new URL("" + data, document.baseURI).href
document.getElementById("overlay").style.display = "block";
const imageext = ["png", "jpg", "svg"]
const movieext = ["mp4"]
var ext = url.substr(url.lastIndexOf('.') + 1);
if(imageext.includes(ext)){
$('#overlaycontentsize').load(url, function(){
var width = $(this).children("svg").attr("width")
var height = $(this).children("svg").attr("height")
$(this).children("svg").attr("viewBox","0 0 " + width + " " + height);
$(this).children("svg").attr("width",window.innerWidth * 0.7);
$(this).children("svg").attr("height",window.innerHeight *0.7);
});
}
else if(movieext.includes(ext)){
$('#overlaycontentsize').append("");
}
else{
$('#overlaycontentsize').append("");
}
}
function overlayOff() {
document.getElementById("overlay").style.display = "none";
$('#overlaycontentsize').text("");
document.getElementById("overlayNotClickable").style.display = "none";
$('#overlaycontentsizeNotClickable').text("");
}
function saveStation() { //Save 2 DB
if (confirm('Are you really, really, REALLY sure you want to create a New Station?')) {
$.ajax({
type: "POST",
url: "../server/",
success: function(res) {
location.reload();
}
});
}
}
function getStations(stationID , patternID ){ //Get DB 2 HTML
$('#stations').text("");
$.ajax({
type: "GET",
url: "../server/",
dataType: "xml",
success: function(xml) {
$(xml).find('station').each(function(index){
var clone = document.importNode(document.querySelector('#line').content,true);
$('[data-class=station]',clone).text($(this).attr('id'));
$('[data-class=pattern] a',clone).before("[");
$('[data-class=pattern] a',clone).text("Add Pattern");
$('[data-class=pattern] a',clone).after("]");
$('[data-class=pattern] a',clone).attr('href','javascript:newPattern('+ $(this).attr('id') + ');');
$('[data-class=duplicate]',clone).text("");
$('[data-class=delete]',clone).text("");
$('#stations').append(clone);
var curstation=$(this).attr('id');
$(this).find('pattern').each(function(index){
var clonePattern = document.importNode(document.querySelector('#line').content,true);
$('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
$('[data-class=pattern] a',clonePattern).attr('href','javascript:getPattern(' + curstation + ','+ $(this).attr('id') + ');');
$('[data-class=date]',clonePattern).text($.format.date(Date.parse($(this).attr('changed')), 'yyyy/MM/dd HH:mm:ss'));
$('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
$('[data-class=delete] a',clonePattern).attr('href','javascript:deletePattern(' + curstation + ','+ $(this).attr('id') + ');');
if (patternID != null && patternID == $(this).attr('id')){
$('tr',clonePattern).css("background-color","#99cce6");
}
$('#stations').append(clonePattern);
});
});
}
});
}
function newPattern(stationID) { //HTML
getPattern(stationID);
}
function getPattern(stationID, patternID){ //Get DB 2 HTML
getStations(stationID, patternID)
//rest Pattern
abk.forEach(function(item){
$("#FormPattern_Form_" + item).val();
$("#FormPattern_Form_" + item).val($("#FormPattern_Form_" + item + " option:first").val());
});
if (patternID == null){
$('#patternform').attr('onsubmit', "savePattern("+stationID+")");
$('#pattern_ID').text("");
$('#pattern_description').val("");
$('#imageListing').text("");
$('#images').css("display", "none");
$('#remove_pattern').css("display", "none");
$('#error').css("display", "none");
$('#replacements').css("display", "none");
}
else{
$('#patternform').attr('onsubmit', "saveChangedPattern("+stationID+","+ patternID +")");
$('#pattern_ID').text(patternID);
getImages(stationID, patternID);
$('#remove_pattern').css("display", "block");
$('#remove_pattern').attr('onclick', "javascript:deletePattern("+stationID+","+ patternID +")");
getError(stationID, patternID);
getReplaceImages(stationID, patternID);
$.ajax({
type: "GET",
url: "../server/"+stationID+ "/" + patternID,
dataType: "xml",
success: function(xml) {
$(xml).find('parts').children().each(function(index){
/*
$(this).find('pattern').each(function(index){
var clonePattern = document.importNode(document.querySelector('#line').content,true);
$('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
abk.forEach(function(item){
if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
$(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+""+item+">")
}
});
*/
//console.log($(this).prop("tagName"));
//console.log($(this).text());
$("#FormPattern_Form_" + $(this).prop("tagName")).val($(this).text());
/*
var pattern = $(this).attr('value').split(".")
for(var i = 0; i < pattern.length; i++)
{
if(i == 0){
$("#patternInput .patternPartInput").val(pattern[i]);
$("#patternInput .patternPartInput").attr('size', pattern[i].length);
}
else{
var clone = document.importNode(document.querySelector('#patternClone').content,true);
$('[data-class=part]',clone).val(pattern[i]);
$('[data-class=part]',clone).limitkeypress({ rexp: keypressRegex() });
$('[data-class=part]',clone).attr('size', pattern[i].length);
$("#patternInput").append(clone);
}
}
$('#pattern').val($(this).attr('value'));
*/
$('#pattern_description').val($(this).attr('description'));
});
}
});
}
$('#pattern_details').css("display", "block");
$('#pattern_station').text(stationID);
$('#pattern_description').text("");
//Reset Pattern
$('#patternInput').text("");
var clone = document.importNode(document.querySelector('#patternClone').content,true);
$('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
$("#patternInput").append(clone);
}
function keypressRegex(){ //Helper Function
return /^.{1,10}$/;
//return /^[A-Za-z0-9\*]*$/; //Ohne Sonderzeichen
}
function removePatternPart(value) { //HTML
if($( ".patternPart" ).length > 1)
value.parent().remove();
}
function addPatternPart(useLast, curclass) { //HTML
var clone = document.importNode(document.querySelector('#patternClone').content,true);
$('[data-class=part]',clone).val("*");
$('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
if(useLast){
$("#" + curclass).children(".patternPart").last().after(clone);
$("#" + curclass).last().children(".patternPartInput").focus();
}else{
$(':focus').parent().after(clone);
$(':focus').parent().next().children(".patternPartInput").focus();
}
}
function getPatternString(){ //Helper Function
var val = "";
var first = true;
$(".patternPartInput").each(function() {
if(first){
first = false
val += $(this).val()
}
else{
val += "." + $(this).val()
}
});
return val;
}
function savePattern(stationID) { //Save 2 DB
var xmlDocument = $.parseXML("