123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- var reason ="";
- var storage = [];
- function doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y) {
-
- if (l1x > r2x || l2x > r1x)
- return false;
-
- if (l1y > r2y || l2y > r1y)
- return false;
- return true;
- }
- function makeFrame(lx, ly, rx, ry, content = "", id = "", defaultpara = "", showbutton = "", style = "") {
-
-
-
- for (i = 0; i < window.storage.length; i++) {
- if(doOverlap(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry, lx, ly, rx, ry)){
- $(".item" + window.storage[i].lx + "-" + window.storage[i].ly).remove();
-
- window.storage.splice(i,1);
- --i;
- }
- }
- console.log(content);
- if(content != "empty"){
- console.log("drinn");
-
-
- window.storage.push({lx:lx, ly:ly, rx:rx, ry: ry})
-
- const container = document.getElementById("container");
- let cell = document.createElement("div");
- cell.classList.add("grid-item");
- cell.classList.add("item" + lx + "-" + ly);
- spancol= ""
- if(rx-lx+1 > 1){
- spancol = " / span " + (rx-lx+1);
-
- }
-
- spanrow= ""
- if(ry-ly+1 > 1){
- spanrow = " / span " + (ry-ly+1);
- }
-
- jQuery.cssNumber.gridColumnStart = true;
- jQuery.cssNumber.gridColumnEnd = true;
- jQuery.cssNumber.gridRowStart = true;
- jQuery.cssNumber.gridRowEnd = true;
-
- $(cell).css({"grid-column": (lx+1) + spancol, "grid-row": ly+1 + spanrow});
-
- container.appendChild(cell);
-
-
-
- if(content != null && content != ""){
-
- var fullurl = content;
-
- if(defaultpara != "{}"){
- var fullurl = fullurl + "?";
- for (var key in defaultpara) {
- if (defaultpara.hasOwnProperty(key)) {
- fullurl = fullurl + key + "=" + defaultpara[key] + "&";
- }
- }
- }
-
-
-
- fullurl = encodeURI(fullurl);
- $(".item" + lx + "-" + ly).html("<iframe width=100% height=100% name='" + id +"' id='" + id +"' src='" + fullurl + "' title='' frameBorder='0' ></iframe>");
-
- if(showbutton){
- $(".item" + lx + "-" + ly).append('<button class="formbutton" type="button" onclick="sendForm(\'' + '.item' + lx + '-' + ly +'\', \'' + encodeURIComponent(id) + '\', \'' + lx + '\', \'' + ly + '\')">' + showbutton + '</button>')
- }
-
- if(style){
- $(".item" + lx + "-" + ly).find("iframe").on('load', function(){
- $(this).contents().find("head").append($("<link/>",
- { rel: "stylesheet", href: style, type: "text/css" }
- ));
- });
- }
-
-
-
- }
- else{
- $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
- }
- }
-
- }
- function sendForm(menuitem, cpeecallback,lx,ly){
-
-
-
-
- var formdata;
- if (typeof document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed !== 'undefined' && $.isFunction(document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed)) {
- var formdata = document.getElementById(decodeURIComponent(cpeecallback)).contentWindow.buttonPressed();
- }
-
- $.ajax({
- type: "PUT",
- url: decodeURIComponent(cpeecallback),
- contentType: "application/json",
- data: JSON.stringify(formdata),
- success: function (data) {
- }
- });
-
-
-
-
-
-
-
- $(menuitem).remove();
-
- $.ajax({
- type: "Post",
- url: "",
- headers: {"content-id": "deleteframe"},
- data: {lx: lx, ly: ly},
- success: function (data) {
- }
- });
-
- }
- function sendData(dataelement, datavalue){
-
- $.ajax({
- type: "Get",
- url: 'cpeeinstance.url',
- success: function(ret) {
- $.ajax({
- type: "Put",
- url: ret + "/properties/dataelements/" + dataelement,
- data: {value: datavalue},
- success: function (data) {
- alert("Data Sent")
- }
- });
- }
- });
-
- }
- function sendCallback(callbackUrl, jsonToSend){
-
- $.ajax({
- type: "PUT",
- url: callbackUrl,
- contentType: "application/json",
- data: jsonToSend,
- success: function (data) {
-
- }
- });
- }
- function showDocument() {
-
- $.ajax({
- type: "GET",
- url: 'style.url',
- success: function(ret) {
- $('head link.custom').attr('href',ret);
- }
- });
-
- $.ajax({
- type: "GET",
- url: 'info.json',
- success: function(ret) {
- makeGrid(ret.x_amount, ret.y_amount);
-
- document.title = ret.document_name;
- $.ajax({
- type: "GET",
- url: 'frames.json',
- success: function(ret2) {
- for (i of ret2.data) {
- makeFrame(i.lx,i.ly,i.rx,i.ry, i.url, i.callback, i.default, i.showbutton, i.style);
- }
- }
- });
- },
- error: function() {
- reason = '';
- clearDocument();
- }
- });
-
-
-
-
-
- }
- function clearDocument() {
- console.log('rrrr');
- $('#languages').addClass('hidden');
- $('#nope').removeClass('hidden');
- $('#control .added').remove();
- $('#content .added').remove();
- $('#reason').text(reason);
- }
- function reloadAllFrames() {
- location.reload();
- }
- function init() {
- es = new EventSource('sse/');
- es.onopen = function() {
- showDocument();
-
- };
- es.onmessage = function(e) {
- if (e.data == 'new') {
- reason = '';
- showDocument();
- }
- if (e.data == 'reset') {
- reason = '';
- showDocument();
- }
- else{
- if(e.data == "update"){
- alert("update")
- }
- if(e.data != "keepalive" && e.data != "started"){
- try {
-
- var frd = JSON.parse(e.data)
- makeFrame(frd.lx,frd.ly,frd.rx,frd.ry, frd.url, frd.callback, frd.default, frd.showbutton, frd.style);
- }
- catch (e) {
- }
- }
- }
- };
- es.onerror = function() {
- reason = 'Server down.';
- clearDocument();
- setTimeout(init, 10000);
- };
- }
-
- function makeGrid(x, y) {
- const container = document.getElementById("container");
- container.style.setProperty('--grid-rows', y);
- container.style.setProperty('--grid-cols', x);
-
- };
- function sendJson(callback, jsonToSend){
- $.ajax({
- type: "PUT",
- url: callback,
- contentType: "application/json",
- data: JSON.stringify(jsonToSend),
- success: function (data) {
- }
- });
- }
- $(document).ready(function() {
- init();
- });
|