dragndrop-code.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of MacSwap.
  5. *
  6. * MacSwap is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * MacSwap is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with MacSwap. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * dragndrop-code.js
  20. *
  21. * Drg-n-drop Code for home.php.
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2021, 2024, 5 Mode
  25. */
  26. gguid = "";
  27. function onDragStart(tthis, e) {
  28. //e.preventDefault();
  29. tthisorder = parseInt($(tthis).attr("order"));
  30. //objName = document.getElementById("objName").value;
  31. //alert(objName);
  32. jsonData = serialize( cubes[tthisorder-1] ) + window.name;
  33. //alert(jsonData);
  34. e.dataTransfer.setData('text/plain', jsonData);
  35. document.body.style.cursor="move";
  36. }
  37. function onDragOver(e) {
  38. e.preventDefault();
  39. const id = e.dataTransfer.getData('text/plain');
  40. document.body.style.cursor="pointer";
  41. }
  42. function onDragOverOff(e) {
  43. e.preventDefault();
  44. document.body.style.cursor="not-allowed";
  45. }
  46. function onDrop(tthis, e) {
  47. e.preventDefault();
  48. mys=e.dataTransfer.getData('text/plain');
  49. gguid=mys.substr(mys.length-64);
  50. mys=mys.substr(0,mys.length-64);
  51. //alert(mys);
  52. newcube = deserialize(mys);
  53. g = $(tthis).attr("guid");
  54. if (g === gguid) {
  55. alert("Operation not allowed in same window!");
  56. return;
  57. }
  58. o = parseInt($(tthis).attr("order"));
  59. n = parseInt($(tthis).attr("size")) + 1;
  60. bfound=false;
  61. for (i=0;i<(n-1);i++) {
  62. if (offers[o-1][i]) {
  63. if (offers[o-1][i].getguid() === newcube.getguid()) {
  64. bfound=i;
  65. break;
  66. }
  67. } else {
  68. break;
  69. }
  70. }
  71. if (bfound===false) {
  72. //n=totcubes+1;
  73. n = parseInt($(tthis).attr("size")) + 1;
  74. offers[o-1][n-1] = newcube;
  75. offers[o-1][n-1].name = "Offer" + "#" + n;
  76. if (o<10) {
  77. newFormalName = "burger" + "00" + o;
  78. } else if (n<100) {
  79. newFormalName = "burger" + "0" + o;
  80. } else {
  81. newFormalName = "burger" + o;
  82. }
  83. if (n<10) {
  84. newFormalName += "-o-" + "00" + n;
  85. } else if (n<100) {
  86. newFormalName += "-o-" + "0" + n;
  87. } else {
  88. newFormalName += "-o-" + n;
  89. }
  90. offers[o-1][n-1].formalName = newFormalName;
  91. //$("#cubeList").html($("#cubeList").html()+"<div id='cubelc" + n + "' style='width:99%;overflow-x: scroll;'><div id='cubel" + n + "' style='width:3800px;height:300px;border: 1px solid green;'><div id='cube" + n + "' class='cube' style='background:url(/res/1burgerg_" + rnd(1,3) + ".png);background-size:cover;border: 1px solid red;' order='" + n + "' onclick='selCube(this);openDetail(this);' draggable='true' ondragstart='onDragStart(this, event);' onmouseover='onMouseOver();'><div id='cube" + n + "name' class='cubename'>cube#" + n + "</div></div></div></div>");
  92. //$("#cubeList").html($("#cubeList").html()+"<div id='cube" + n + "' class='cube' order='" + n + "' onclick='selCube(this)' draggable='true' ondragstart='onDragStart(this, event);' onmouseover='onMouseOver();'><div id='cube" + n + "name' class='cubename'>cube#" + n + "</div></div>");
  93. $(tthis).html($(tthis).html()+"<div id='" + newFormalName + "' class='cube' style='background:url(/res/1burgerg_" + parseInt(rnd(1,3)) + ".png);background-size:cover;border:0px solid red;' cubeorder='" + o + "' order='" + n + "' onclick='selOfferCube(this);openOfferDetail(this);' draggable='true' ondragstart='onDropOff(event);' onmouseover='onMouseOver();'><div id='cube" + o + "offer" + n + "name' class='cubename'>offer#" + n + "</div></div>");
  94. //$("#cube"+n+"name").html(cubes[n-1].getname());
  95. $(tthis).attr("size", n);
  96. } else {
  97. if (offers[o-1][i].getpassword() === newcube.getpassword()) {
  98. pwd2 = prompt("password confirmation:");
  99. if (offers[o-1][i].getpassword() != pwd2) {
  100. $("#cubeList").html("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Permission denied.");
  101. return;
  102. }
  103. } else {
  104. $("#cubeList").html("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Permission denied.");
  105. return;
  106. }
  107. n=bfound+1;
  108. offers[o-1][n-1] = newcube;
  109. offers[o-1][n-1].name = "Offer" + "#" + n;
  110. if (o<10) {
  111. newFormalName = "burger" + "00" + o;
  112. } else if (n<100) {
  113. newFormalName = "burger" + "0" + o;
  114. } else {
  115. newFormalName = "burger" + o;
  116. }
  117. if (n<10) {
  118. newFormalName += "-o-" + "00" + n;
  119. } else if (n<100) {
  120. newFormalName += "-o-" + "0" + n;
  121. } else {
  122. newFormalName += "-o-" + n;
  123. }
  124. offers[o-1][n-1].formalName = newFormalName;
  125. //$("#cubeList").html($("#cubeList").html()+"<div id='cube" + n + "' class='cube' order='" + n + "' onclick='selCube(this)'><div id='cube" + n + "name' class='cubename'>cube#" + n + "</div></div>");
  126. //$("#cube"+n+"name").html(cubes[n-1].getname());
  127. }
  128. offers[o-1][n-1].savedata();
  129. document.body.style.cursor="normal";
  130. }
  131. function onDropOff(e) {
  132. e.preventDefault();
  133. document.body.style.cursor="not-allowed";
  134. e.stopPropagation();
  135. }
  136. function onMouseOver() {
  137. document.body.style.cursor="pointer";
  138. }