readconfigcommon.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. function readconfig_Version(){
  2. return "1.0.0 - 20200910";
  3. }
  4. function SaveConfigToServer(_basepath){
  5. // leere Zeilen am Ende löschen
  6. var zw = config_split.length - 1;
  7. while (config_split[zw] == "") {
  8. config_split.pop();
  9. }
  10. var config_gesamt = "";
  11. for (var i = 0; i < config_split.length; ++i)
  12. {
  13. config_gesamt = config_gesamt + config_split[i] + "\n";
  14. }
  15. FileDeleteOnServer("/config/config.ini", _basepath);
  16. FileSendContent(config_gesamt, "/config/config.ini", _basepath);
  17. }
  18. function UpdateConfig(zw, _index, _enhance, _basepath){
  19. var namezw = zw["name"];
  20. FileCopyOnServer("/img_tmp/ref_zw.jpg", namezw, _basepath);
  21. var namezw = zw["name"].replace(".jpg", "_org.jpg");
  22. FileCopyOnServer("/img_tmp/ref_zw_org.jpg", namezw, _basepath);
  23. }
  24. function createReader(file) {
  25. var image = new Image();
  26. reader.onload = function(evt) {
  27. var image = new Image();
  28. image.onload = function(evt) {
  29. var width = this.width;
  30. var height = this.height;
  31. alert (width); // will produce something like 198
  32. };
  33. image.src = evt.target.result;
  34. };
  35. reader.readAsDataURL(file);
  36. }
  37. function ZerlegeZeile(input, delimiter = " =\t\r")
  38. {
  39. var Output = Array(0);
  40. // delimiter = " =,\t";
  41. input = trim(input, delimiter);
  42. var pos = findDelimiterPos(input, delimiter);
  43. var token;
  44. while (pos > -1) {
  45. token = input.substr(0, pos);
  46. token = trim(token, delimiter);
  47. Output.push(token);
  48. input = input.substr(pos+1, input.length);
  49. input = trim(input, delimiter);
  50. pos = findDelimiterPos(input, delimiter);
  51. }
  52. Output.push(input);
  53. return Output;
  54. }
  55. function findDelimiterPos(input, delimiter)
  56. {
  57. var pos = -1;
  58. var zw;
  59. var akt_del;
  60. for (var anz = 0; anz < delimiter.length; ++anz)
  61. {
  62. akt_del = delimiter[anz];
  63. zw = input.indexOf(akt_del);
  64. if (zw > -1)
  65. {
  66. if (pos > -1)
  67. {
  68. if (zw < pos)
  69. pos = zw;
  70. }
  71. else
  72. pos = zw;
  73. }
  74. }
  75. return pos;
  76. }
  77. function trim(istring, adddelimiter)
  78. {
  79. while ((istring.length > 0) && (adddelimiter.indexOf(istring[0]) >= 0)){
  80. istring = istring.substr(1, istring.length-1);
  81. }
  82. while ((istring.length > 0) && (adddelimiter.indexOf(istring[istring.length-1]) >= 0)){
  83. istring = istring.substr(0, istring.length-1);
  84. }
  85. return istring;
  86. }
  87. function getConfig()
  88. {
  89. return config_gesamt;
  90. }
  91. function loadConfig(_basepath) {
  92. var xhttp = new XMLHttpRequest();
  93. try {
  94. url = _basepath + '/fileserver/config/config.ini';
  95. xhttp.open("GET", url, false);
  96. xhttp.send();
  97. config_gesamt = xhttp.responseText;
  98. config_gesamt = config_gesamt.replace("InitalRotate", "InitialRotate"); // Korrigiere Schreibfehler in config.ini !!!!!
  99. }
  100. catch (error)
  101. {
  102. // alert("Deleting Config.ini failed");
  103. }
  104. return true;
  105. }
  106. function dataURLtoBlob(dataurl) {
  107. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  108. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  109. while(n--){
  110. u8arr[n] = bstr.charCodeAt(n);
  111. }
  112. return new Blob([u8arr], {type:mime});
  113. }
  114. function FileCopyOnServer(_source, _target, _basepath = ""){
  115. url = _basepath + "/editflow.html?task=copy&in=" + _source + "&out=" + _target;
  116. var xhttp = new XMLHttpRequest();
  117. try {
  118. xhttp.open("GET", url, false);
  119. xhttp.send(); }
  120. catch (error)
  121. {
  122. // alert("Deleting Config.ini failed");
  123. }
  124. }
  125. function FileDeleteOnServer(_filename, _basepath = ""){
  126. var xhttp = new XMLHttpRequest();
  127. var okay = false;
  128. xhttp.onreadystatechange = function() {
  129. if (xhttp.readyState == 4) {
  130. if (xhttp.status == 200) {
  131. okay = true;
  132. } else if (xhttp.status == 0) {
  133. // alert("Server closed the connection on delete abruptly!");
  134. // location.reload()
  135. } else {
  136. // alert(xhttp.status + " Error!\n" + xhttp.responseText);
  137. // location.reload()
  138. }
  139. }
  140. };
  141. try {
  142. var url = _basepath + "/delete" + _filename;
  143. xhttp.open("POST", url, false);
  144. xhttp.send();
  145. }
  146. catch (error)
  147. {
  148. // alert("Deleting Config.ini failed");
  149. }
  150. return okay;
  151. }
  152. function FileSendContent(_content, _filename, _basepath = ""){
  153. var xhttp = new XMLHttpRequest();
  154. var okay = false;
  155. xhttp.onreadystatechange = function() {
  156. if (xhttp.readyState == 4) {
  157. if (xhttp.status == 200) {
  158. okay = true;
  159. } else if (xhttp.status == 0) {
  160. alert("Server closed the connection abruptly!");
  161. } else {
  162. alert(xhttp.status + " Error!\n" + xhttp.responseText);
  163. }
  164. }
  165. };
  166. try {
  167. upload_path = _basepath + "/upload" + _filename;
  168. xhttp.open("POST", upload_path, false);
  169. xhttp.send(_content);
  170. }
  171. catch (error)
  172. {
  173. // alert("Deleting Config.ini failed");
  174. }
  175. return okay;
  176. }
  177. function SaveCanvasToImage(_canvas, _filename, _delete = true, _basepath = ""){
  178. var JPEG_QUALITY=0.8;
  179. var dataUrl = _canvas.toDataURL('image/jpeg', JPEG_QUALITY);
  180. var rtn = dataURLtoBlob(dataUrl);
  181. if (_delete) {
  182. FileDeleteOnServer(_filename, _basepath);
  183. }
  184. FileSendContent(rtn, _filename, _basepath);
  185. }
  186. function MakeContrastImageZW(zw, _enhance, _basepath){
  187. _filename = zw["name"].replace("/config/", "/img_tmp/");
  188. url = _basepath + "/editflow.html?task=cutref&in=/config/reference.jpg&out=" + _filename + "&x=" + zw["x"] + "&y=" + zw["y"] + "&dx=" + zw["dx"] + "&dy=" + zw["dy"];
  189. if (_enhance == true){
  190. url = url + "&enhance=true";
  191. }
  192. var xhttp = new XMLHttpRequest();
  193. try {
  194. xhttp.open("GET", url, false);
  195. xhttp.send(); }
  196. catch (error)
  197. {
  198. // alert("Deleting Config.ini failed");
  199. }
  200. }
  201. function MakeRefZW(zw, _basepath){
  202. _filetarget = zw["name"].replace("/config/", "/img_tmp/");
  203. _filetarget = _filetarget.replace(".jpg", "_org.jpg");
  204. url = _basepath + "/editflow.html?task=cutref&in=/config/reference.jpg&out="+_filetarget+"&x=" + zw["x"] + "&y=" + zw["y"] + "&dx=" + zw["dx"] + "&dy=" + zw["dy"];
  205. var xhttp = new XMLHttpRequest();
  206. try {
  207. xhttp.open("GET", url, false);
  208. xhttp.send(); }
  209. catch (error)
  210. {
  211. // alert("Deleting Config.ini failed");
  212. }
  213. _filetarget2 = zw["name"].replace("/config/", "/img_tmp/");
  214. // _filetarget2 = _filetarget2.replace(".jpg", "_org.jpg");
  215. FileCopyOnServer(_filetarget, _filetarget2, _basepath);
  216. }