ui2.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. var storage = []; //{col:1, row:1, colamount:1, rowamount: 1}];
  2. function doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y)
  3. {
  4. // If one rectangle is on left side of other
  5. if (l1x > r2x || l2x > r1x)
  6. return false;
  7. // If one rectangle is above other
  8. if (l1y > r2y || l2y > r1y)
  9. return false;
  10. return true;
  11. }
  12. /*
  13. function clearRectangel(l1x, l1y, r1x, r1y){
  14. for(var i = l1x; i <= r1x; ++i)
  15. for(var k = l1y; k <= r1y; ++k){
  16. $(".item" + (i) + "-" + (k)).remove();
  17. //$(".item" + (i) + "-" + (k)).css({"display": "block", "border-style": "none", "border-color": "black", "grid-area": "auto"});
  18. //$(".item" + (i) + "-" + (k)).text("");
  19. }
  20. }
  21. function hideRectangel(l1x, l1y, r1x, r1y){
  22. for(var i = l1x; i <= r1x; ++i)
  23. for(var k = l1y; k <= r1y; ++k)
  24. if(!(i == l1x && k == l1y))
  25. $(".item" + (i) + "-" + (k)).hide(100);
  26. }
  27. */
  28. function makeFrame(lx, ly, rx, ry, content = "", id = "", showbutton=false) {
  29. //check if rects overlap if they do remove old ones
  30. for (i = 0; i < window.storage.length; i++) {
  31. if(doOverlap(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry, lx, ly, rx, ry)){
  32. $(".item" + window.storage[i].lx + "-" + window.storage[i].ly).remove();
  33. //clearRectangel(window.storage[i].lx, window.storage[i].ly, window.storage[i].rx, window.storage[i].ry)
  34. window.storage.splice(i,1);
  35. --i;
  36. }
  37. }
  38. //add new ellement to storage
  39. window.storage.push({lx:lx, ly:ly, rx:rx, ry: ry})
  40. const container = document.getElementById("container");
  41. let cell = document.createElement("div");
  42. cell.classList.add("grid-item");
  43. cell.classList.add("item" + lx + "-" + ly);
  44. spancol= ""
  45. if(rx-lx+1 > 1){
  46. spancol = " / span " + (rx-lx+1);
  47. }
  48. spanrow= ""
  49. if(ry-ly+1 > 1){
  50. spanrow = " / span " + (ry-ly+1);
  51. }
  52. jQuery.cssNumber.gridColumnStart = true;
  53. jQuery.cssNumber.gridColumnEnd = true;
  54. jQuery.cssNumber.gridRowStart = true;
  55. jQuery.cssNumber.gridRowEnd = true;
  56. $(cell).css({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column": (lx+1) + spancol, "grid-row": ly+1 + spanrow});
  57. console.log({"display": "block", "border-style": "solid", "border-color": "blue", "grid-column-start": (lx+1), "grid-column-end": (rx+1), "grid-row-start": ly+1, "grid-row-end": ry+1})
  58. container.appendChild(cell);
  59. //Create new element with width, heigth and content
  60. //$(".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)});
  61. if(content != null && content != ""){
  62. $(".item" + lx + "-" + ly).html("<iframe width=100% height=100% name='" + id +"' src='" + content + "' title=''></iframe>");
  63. if(showbutton && content.startsWith("https://centurio.work/out/forms")){
  64. $(".item" + lx + "-" + ly).append('<button class="formbutton" type="button" onclick="sendForm(\'' + '.item' + lx + '-' + ly +'\', \'' + encodeURIComponent(id) + '\', \'' + lx + '\', \'' + ly + '\')">Send Form</button>')
  65. }
  66. //hideRectangel(lx, ly, rx, ry)
  67. }
  68. else{
  69. $(".item" + lx + "-" + ly).html("No language available.<br> Nicht in der Sprache verfügbar.");
  70. //hideRectangel(lx, ly, rx, ry)
  71. }
  72. };
  73. function getFormData($form){
  74. var unindexed_array = $form.serializeArray();
  75. var indexed_array = {};
  76. $.map(unindexed_array, function(n, i){
  77. indexed_array[n['name']] = n['value'];
  78. });
  79. return indexed_array;
  80. }
  81. function sendForm(menuitem, cpeecallback,lx,ly){
  82. /* old can be used when formi js is active */
  83. $.ajax({
  84. type: "PUT",
  85. url: decodeURIComponent(cpeecallback),
  86. contentType: "application/json",
  87. data: $('iframe[name="' + decodeURIComponent(cpeecallback) + '"]').contents().find("#submission").html(),
  88. success: function (data) {
  89. //close form
  90. $(menuitem).remove();
  91. }
  92. });
  93. //get Iframe then data
  94. /* without formio JS
  95. var $form = $('iframe[name="' + decodeURIComponent(cpeecallback) + '"]').contents().find("#form");
  96. var formdatajson = getFormData($form);
  97. alert(JSON.stringify(formdatajson))
  98. $.ajax({
  99. type: "PUT",
  100. url: decodeURIComponent(cpeecallback),
  101. contentType: "application/json",
  102. data: JSON.stringify(formdatajson),
  103. success: function (data) {
  104. //close form
  105. $(menuitem).remove();
  106. }
  107. });
  108. */
  109. //remove from Server
  110. $.ajax({
  111. type: "Post",
  112. url: "",
  113. headers: {"content-id": "deleteframe"},
  114. data: {lx: lx, ly: ly},
  115. success: function (data) {
  116. }
  117. });
  118. }
  119. /*
  120. document.addEventListener('keyup', (event) => {
  121. if (event.key == 'ArrowUp') {
  122. alert("ArrowUp");
  123. makeFrame(0,0,0,0, "a")
  124. }
  125. if (event.key == 'ArrowDown') {
  126. alert("ArrowDown");
  127. makeFrame(0,0,1,1, "b")
  128. }
  129. if (event.key == 'ArrowLeft') {
  130. alert("ArrowLeft");
  131. makeFrame(1,1,2,2, "c")
  132. }
  133. if (event.key == 'ArrowRight') {
  134. alert(JSON.stringify(window.storage));
  135. }
  136. });
  137. */