Browse Source

Deleting frames now possible when no url is submited

Juergen 'eTM' Mangler 2 years ago
parent
commit
c26fbd5f65
2 changed files with 109 additions and 86 deletions
  1. 41 28
      frames
  2. 68 58
      template/js/ui.js

+ 41 - 28
frames

@@ -93,26 +93,34 @@ class NewFrameSet < Riddl::Implementation
       end
     end
 
-    urls = JSON::parse(@p[7].value);
+    #check if url is set
+    if @p[7].value != ""
+      urls = JSON::parse(@p[7].value);
+      
+      if @p[8].value == ""
+        hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};
+      else
+        hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value,  style: @p[6].value, default: JSON::parse(@p[8].value), callback: @h['CPEE_CALLBACK']};
+      end
 
+      data_hash["data"].push(hash)
+      File.write(path, JSON.dump(data_hash))
 
-    if @p[8].value == ""
-      hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};
-    else
-      hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value,  style: @p[6].value, default: JSON::parse(@p[8].value), callback: @h['CPEE_CALLBACK']};
-    end
+      #only send active url to client
+      infofile = File.join('data',@r.last,'info.json')
+      infojson = JSON::parse(File.read(infofile))
+      hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url']
 
-    data_hash["data"].push(hash)
-    File.write(path, JSON.dump(data_hash))
 
-    #only send active url to client
-    infofile = File.join('data',@r.last,'info.json')
-    infojson = JSON::parse(File.read(infofile))
-    hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url']
+      @a[0].send(JSON.dump(hash))
+    else
+      File.write(path, JSON.dump(data_hash))
+      hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: "empty", showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};
 
-    @a[0].send(JSON.dump(hash))
+      @a[0].send(JSON.dump(hash))
+    end
+    
     nil
-
   end
 end
 
@@ -129,22 +137,27 @@ class NewFrameWait < Riddl::Implementation
       end
     end
 
-    urls = JSON::parse(@p[7].value);
-    if @p[8].value == ""
-      hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};
-    else
-      hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: JSON::parse(@p[8].value), callback: @h['CPEE_CALLBACK']};
-    end
-    data_hash["data"].push(hash)
-    File.write(path, JSON.dump(data_hash))
 
-    #only send active url to client
-    infofile = File.join('data',@r.last,'info.json')
-    infojson = JSON::parse(File.read(infofile))
-    hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url']
 
-    @a[0].send(JSON.dump(hash))
-    nil
+
+      urls = JSON::parse(@p[7].value);
+      if @p[8].value == ""
+        hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};
+      else
+        hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, showbutton: @p[5].value, style: @p[6].value, default: JSON::parse(@p[8].value), callback: @h['CPEE_CALLBACK']};
+      end
+      data_hash["data"].push(hash)
+      File.write(path, JSON.dump(data_hash))
+
+      #only send active url to client
+      infofile = File.join('data',@r.last,'info.json')
+      infojson = JSON::parse(File.read(infofile))
+      hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url']
+
+      @a[0].send(JSON.dump(hash))
+      nil
+    
+    
   end
   def headers
     Riddl::Header.new('CPEE-CALLBACK', 'true')

+ 68 - 58
template/js/ui.js

@@ -14,6 +14,8 @@ function doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y) {
 
 
 function makeFrame(lx, ly, rx, ry, content = "", id = "", defaultpara = "", showbutton = "", style = "") {
+  
+  
   //check if rects overlap if they do remove old ones
   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)){
@@ -23,72 +25,76 @@ function makeFrame(lx, ly, rx, ry, content = "", id = "", defaultpara = "", show
       --i;
     }
   }
-  
-  //add new ellement to storage
-  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);
+  console.log(content);
+  if(content != "empty"){
+  console.log("drinn");
     
-  }
-  
-  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);
-  //Create new element with width, heigth and content
-  //$(".item" + lx + "-" + ly).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1),  "grid-row": ly+1 + " / span " + (ry-ly+1)});
-  
-  if(content != null && content != ""){
-  
-    var fullurl = content;
-    //encode default parameter in URL
-    if(defaultpara != "{}"){
-      var fullurl = fullurl + "?";
-      for (var key in defaultpara) {
-        if (defaultpara.hasOwnProperty(key)) {
-          fullurl = fullurl + key + "=" +  defaultpara[key] + "&";
-         }
-      }
+    //add new ellement to storage
+    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;
     
-    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>')
-    }
+    $(cell).css({"grid-column": (lx+1) + spancol,  "grid-row": ly+1 + spanrow});
     
-    if(style){    
-      $(".item" + lx + "-" + ly).find("iframe").on('load', function(){
-        $(this).contents().find("head").append($("<link/>", 
-          { rel: "stylesheet", href: style, type: "text/css" }
-        ));
-      });      
-    }
+    container.appendChild(cell);
+    //Create new element with width, heigth and content
+    //$(".item" + lx + "-" + ly).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + " / span " + (rx-lx+1),  "grid-row": ly+1 + " / span " + (ry-ly+1)});
     
+    if(content != null && content != ""){
     
-    //hideRectangel(lx, ly, rx, ry)
-  }
-  else{
-    $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
+      var fullurl = content;
+      //encode default parameter in URL
+      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" }
+          ));
+        });      
+      }
+      
+      
+      //hideRectangel(lx, ly, rx, ry)
+    }
+    else{
+      $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
+    }
   }
   
 }
@@ -291,6 +297,10 @@ function clearDocument() {
   $('#reason').text(reason);
 }
 
+function reloadAllFrames() {
+  location.reload();
+}
+
 
 function init() {
   es = new EventSource('sse/');