dragndrop-code.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of 5 Cube.
  5. *
  6. * 5 Cube 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. * 5 Cube 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 5 Cube. 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. function onDragStart(tthis, e) {
  27. //e.preventDefault();
  28. tthisorder = parseInt($(tthis).attr("order"));
  29. //objName = document.getElementById("objName").value;
  30. //alert(objName);
  31. jsonData = serialize( cubes[tthisorder-1] );
  32. //alert(jsonData);
  33. e.dataTransfer.setData('text/plain', jsonData);
  34. document.body.style.cursor="move";
  35. }
  36. function onDragOver(e) {
  37. e.preventDefault();
  38. const id = e.dataTransfer.getData('text/plain');
  39. document.body.style.cursor="pointer";
  40. }
  41. function onDragOverOff(e) {
  42. e.preventDefault();
  43. document.body.style.cursor="not-allowed";
  44. }
  45. function onDrop(e) {
  46. e.preventDefault();
  47. mys=e.dataTransfer.getData('text/plain');
  48. //alert(mys);
  49. newcube = deserialize(mys);
  50. bfound=false;
  51. for (i=0;i<totcubes;i++) {
  52. if (cubes[i].getguid() === newcube.getguid()) {
  53. bfound=i;
  54. break;
  55. }
  56. }
  57. if (bfound===false) {
  58. n=totcubes+1;
  59. cubes[n-1] = newcube;
  60. cubes[n-1].name = businessType + "#" + n;
  61. if (n<10) {
  62. newFormalName = "cube" + "00" + n;
  63. } else if (n<100) {
  64. newFormalName = "cube" + "0" + n;
  65. } else {
  66. newFormalName = "cube" + n;
  67. }
  68. cubes[n-1].formalName = newFormalName;
  69. $("#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>");
  70. $("#cube"+n+"name").html(cubes[n-1].getname());
  71. totcubes=n;
  72. } else {
  73. if (cubes[i].getpassword() === newcube.getpassword()) {
  74. pwd2 = prompt("password confirmation:");
  75. pwd2en = encryptSha2(pwd2);
  76. if (cubes[i].getpassword() != pwd2en) {
  77. $("#cubeList").html("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Permission denied.");
  78. return;
  79. }
  80. } else {
  81. $("#cubeList").html("<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Permission denied.");
  82. return;
  83. }
  84. n=bfound+1;
  85. cubes[n-1] = newcube;
  86. cubes[n-1].name = businessType + "#" + n;
  87. if (n<10) {
  88. newFormalName = "cube" + "00" + n;
  89. } else if (n<100) {
  90. newFormalName = "cube" + "0" + n;
  91. } else {
  92. newFormalName = "cube" + n;
  93. }
  94. cubes[n-1].formalName = newFormalName;
  95. //$("#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>");
  96. $("#cube"+n+"name").html(cubes[n-1].getname());
  97. }
  98. cubes[n-1].savedata();
  99. document.body.style.cursor="normal";
  100. }
  101. function onDropOff(e) {
  102. e.preventDefault();
  103. document.body.style.cursor="not-allowed";
  104. e.stopPropagation();
  105. }
  106. function onMouseOver() {
  107. document.body.style.cursor="pointer";
  108. }