123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- //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 id='overlaycontent' src='" + url + "' width='1800' height='800'></iframe>");
-
- 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("<video id='overlaycontent' controls> <source src=" + url + " type=\"video/mp4\">Your browser does not support the video tag.</video>");
- }
- else{
- $('#overlaycontentsize').append("<iframe id='overlaycontent' src=" + url + "></iframe>");
- }
-
- }
- 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) {
-
- $('#pattern_description').val($(xml).find('pattern').attr('description'));
- $(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_details').css("display", "block");
- $('#pattern_station').text(stationID);
-
- //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("<pattern><parts></parts></pattern>");
- $(xmlDocument).find("pattern").attr('id','0');
-
-
- // #FormPattern
- 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+">")
- }
- });
-
- $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
- $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
-
- console.log((new XMLSerializer()).serializeToString(xmlDocument));
-
-
- $.ajax({
- type: "POST",
- headers: {"content-id": "pattern"},
- data: (new XMLSerializer()).serializeToString(xmlDocument),
- contentType: "application/xml; charset=utf-8",
- url: "../server/"+stationID,
- success: function(res) {
- //getPattern(stationID, res.id)
- },
- error: function (request, status, error) {
- //alert(request.responseText + status + error);
- }
- });
-
- }
- function saveChangedPattern(stationID, patternID) { //Save 2 DB
- var xmlDocument = $.parseXML("<pattern><parts></parts></pattern>");
- $(xmlDocument).find("pattern").attr('id',$('#pattern_ID').text());
- // #FormPattern
- 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+">")
- }
- });
- $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
- $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
-
- //Save Pattern
- $.ajax({
- type: "PUT",
- headers: {"content-id": "pattern"},
- data: (new XMLSerializer()).serializeToString(xmlDocument),
- contentType: "application/xml; charset=utf-8",
- url: "../server/"+stationID + "/" + patternID,
- //processData: false,
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
-
- //Update Labels
- $(".imageInput").each(function() {
- //Optimization only update if lable changed
- if($(this).val() != $(this).attr("origValue"))
- $.ajax({
- type: "PUT",
- data: { 'label' : $(this).val()},
- headers: {"content-id": "label"},
- url: "../server/"+stationID + "/" + patternID + "/images/" + $(this).parent().find(".imageID").text() +"/" + $('#image_language option:selected').text(),
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- });
-
- //Update Image Ordering
- var order = []
- $(".imageID").each(function() {
- order.push(parseInt($(this).text()))
- });
- $.ajax({
- type: "PUT",
- data: JSON.stringify(order),
- headers: {"content-id": "orderlist"},
- contentType: "application/json",
- url: "../server/"+stationID + "/" + patternID + "/images/reorder/" + $('#image_language option:selected').text(),
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
-
- //Update Error
- var errorList = $.parseXML("<error/>");
- $(".errorInput").each(function() {
- $(errorList).find("error").append("<reason>" +$(this).val()+"</reason>")
- });
-
- $.ajax({
- type: "PUT",
- headers: {"content-id": "error"},
- data: (new XMLSerializer()).serializeToString(errorList),
- contentType: "application/xml; charset=utf-8",
- url: "../server/"+stationID + "/" + patternID + "/error",
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
-
-
- //Update Replacement
- var replaceList = $.parseXML("<replacement/>");
- $(".replaceInput").each(function() {
- //console.log($(this).find('.abbreviation').val())
- //console.log($(this).find('.url').val())
-
- $(replaceList).find("replacement").append("<item>" + "<abbreviation>" + $(this).find('.abbreviation').val() + "</abbreviation>" + "<url>" + $(this).find('.url').val() + "</url>"+"</item>")
-
- });
-
- $.ajax({
- type: "PUT",
- headers: {"content-id": "replacement"},
- data: (new XMLSerializer()).serializeToString(replaceList),
- contentType: "application/xml; charset=utf-8",
- url: "../server/"+stationID + "/" + patternID + "/replacement",
- success: function(res) {
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
-
-
- getPattern(stationID, patternID)
- }
- function deletePattern(stationID, patternID) { //Delete From DB
- if (confirm('Are you really, really, REALLY sure!')) {
- $.ajax({
- type: "DELETE",
- url: "../server/" + stationID + "/" + patternID,
- success: function(res) {
- location.reload();
- }
- });
- }
- }
- function duplicatePattern(stationID, patternID){ //Get DB 2 HTML
- $.ajax({
- type: "PUT",
- headers: {"content-id": "patternID"},
- data: { "patternID":patternID},
- contentType: "application/json",
- url: "../server/"+stationID + "/" + patternID,
- success: function(res) {
- getPattern(stationID, res["id"])
- },
- error: function (request, status, error) {
- alert(request.responseText + status + error);
- }
- });
- }
- function getImages(stationID, patternID){ //Get From DB 2 HTML
- $('#images').css("display", "block");
- $('#imageListing').text("");
- $('#imgUpload').attr("action", "../server/" + stationID + "/" + patternID + "/images");
-
-
-
- $('#addExternalImageUrl').val("");
- $('#addExternalImage').attr("onclick", "addExternalImage(" + stationID + "," + patternID + ")");
-
-
- //Image preview needs pattern
- $.ajax({
- type: "GET",
- url: "../server/"+stationID+ "/" + patternID,
- dataType: "xml",
- success: function(xml) {
- pattern = xml.getElementsByTagName('pattern')[0].getAttribute("value");
-
- //get all images
- $.ajax({
- type: "GET",
- url: "../server/"+stationID+ "/" + patternID + "/images",
- dataType: "xml",
- success: function(xml) {
- var count = 0;
- $(xml).find('image').each(function(index){
-
- curID = $(this).attr('id')
- $(this).find('variant').each(function(){
-
- if($(this).attr('lang') == $('#image_language option:selected').text()){
- ++count;
- var clone = document.importNode(document.querySelector('#imagePreview').content,true);
-
- var imgsrcsingle = "../images/uploads/"+stationID+ "/" + patternID + "/" + curID + "/"+ $(this).attr('lang') + ".svg";
- var imgsrc = imgsrcsingle + "?" + Date.now();
-
- //$('[data-class=image]',clone).append('<img id="theImg" src="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
-
- //$('[data-class=image]',clone).append('<object class="theImg" id="theImg" data="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
-
-
- //managing that internal and external pictures look the same
- $('[data-class=image]',clone).load(imgsrc, function(){
- var width = $(this).children("svg").attr("width")
- var height = $(this).children("svg").attr("height")
-
-
- $(this).children("svg").attr("viewBox","0 0 " + pictureWidth + " " + pictureHeight + "");
- $(this).children("svg").attr("width","200");
- $(this).children("svg").attr("height","100");
- });
-
- $('[data-class=image]',clone).attr("onclick", "overlayOnImg('" + imgsrcsingle + "')" );
-
-
-
-
- //Image Preview
- $('[data-class=showimage]',clone).attr("href", "imageReplacement.php?___image___="+stationID+ "/" + patternID + "/" + curID + "/"+ $(this).attr('lang') + ".svg" +"&ProductCode=" + pattern + "&Station=" + "Station" + stationID);
-
-
-
-
-
-
- //$('[data-class=image]',clone).append('<object class="theImg" id="theImg" data="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
-
-
- //$('[data-class=image]',clone).append('<div style="background-image: url(' + imgsrc+ ')" height="100px" />')
-
- $('[data-class=label]',clone).val($(this).attr('label'));
- $('[data-class=label]',clone).attr("origValue", $(this).attr('label'));
- $('[data-class=imageId]',clone).text(curID);
- $('[data-class=imageId]',clone).attr("class", "imageID")
-
- $('[data-class=options] a',clone).attr('href','javascript:deleteImage(' + stationID + ','+ patternID + ',' + curID + ',"' + $(this).attr('lang') + '");');
- $('#imageListing').append(clone);
- }
- });
- });
- $('#image_count').text(count);
-
-
-
- /*
- $(".image").each(function() {
- alert("mhm");
-
-
-
- $(this).children().attr("viewBox","0 0 " + "300" + " 300");
-
- });
- */
-
- }
- });
- }
- });
-
- new Sortable(document.getElementById('imageListing'),{
- handle: '.handle',
- animation: 150
- });
-
- new Sortable(document.getElementById('replaceImages'),{
- handle: '.handle2',
- animation: 150
- });
- }
- function addExternalImage(stationID, patternID){
-
-
- var extImage = $.parseXML("<externalImage/>");
- $(extImage).find("externalImage").append("<url>" + $('#addExternalImageUrl').val() +"</url>");
- $(extImage).find("externalImage").append("<lang>" + $('#image_language option:selected').text() + "</lang>");
- console.log(extImage);
-
- $.ajax({
- type: "POST",
- headers: {"content-id": "externalImage"},
- data: (new XMLSerializer()).serializeToString(extImage),
- contentType: "application/xml; charset=utf-8",
- url: "../server/" + stationID + "/" + patternID + "/images",
- success: function(res) {
- getPattern(stationID, patternID)
- }
- });
-
-
- }
- function deleteImage(stationID, patternID, imageID, lang) { //Delete From DB
- $.ajax({
- type: "DELETE",
- url: "../server/" + stationID + "/" + patternID + "/images/" + imageID + "/" + lang,
- success: function(res) {
- getPattern(stationID, patternID)
- }
- });
- }
- function addError() { //HTML
- //Will be added from DB on save
- var clone = document.importNode(document.querySelector('#errorCode').content,true);
- $('#errorCodes').append(clone);
- }
- function getError(stationID, patternID){ //Get From DB 2 HTML
- $('#error').css("display", "block");
- $('#errorCodes').text("");
- $.ajax({
- type: "GET",
- url: "../server/"+stationID+ "/" + patternID + "/error",
- dataType: "xml",
- success: function(xml) {
- $(xml).find('reason').each(function(index){
- var clone = document.importNode(document.querySelector('#errorCode').content,true);
- $('[data-class=errorInput]',clone).val($(this).text());
- $('#errorCodes').append(clone);
- });
- }
- });
- }
- function removeError(value) { //HTML
- //Will be removed from DB on save
- value.parent().parent().parent().remove();
- }
- function addBlankReplacement() { //HTML
- //Will be added from DB on save
- var clone = document.importNode(document.querySelector('#imageReplacements').content,true);
- $('#replaceImages').append(clone);
- }
- function getReplaceImages(stationID, patternID){ //Get From DB 2 HTML
- $('#replacements').css("display", "block");
- $('#replaceImages').text("");
- $.ajax({
- type: "GET",
- url: "../server/"+stationID+ "/" + patternID + "/replacement",
- dataType: "xml",
- success: function(xml) {
- $(xml).find('item').each(function(index){
- var clone = document.importNode(document.querySelector('#imageReplacements').content,true);
- $('[data-class=abbreviation]',clone).val($(this).find('abbreviation').text());
- $('[data-class=url]',clone).val($(this).find('url').text());
- $('#replaceImages').append(clone);
- });
- }
- });
- }
- function removeReplacement(value) { //HTML
- //Will be removed from DB on save
- value.parent().parent().parent().remove();
- }
- //Go to next PatternInput on . or space keydown
- $(window).keydown(function(e) {
- if ((e.which === 32 || e.which === 190) && $(':focus').attr('class') === "patternPartInput") {
- e.preventDefault();
- addPatternPart(false);
- }
- });
- $(document).ready(function() {
- getStations(); //Get all Stations
- $("#image_language" ).change(function() {
- getImages($('#pattern_station').text(), $('#pattern_ID').text())
- });
- $(document).on('submit', '#patternform', function() { //prevent page reload on form submit
- return false;
- });
- $('.patternPartInput').limitkeypress({rexp: keypressRegex()});
- });
|