imageSlicer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. rectID = 0;
  2. colors = ["#edd400","#73d216","#cc0000","#f57900","#3465a4","#c17d11","#75507b","#fce94f","#8ae234","#ef2929","#fcaf3e","#729fcf","#eeeeec","#e9b96e","#ad7fa8","#888a85","#c4a000","#4e9a06","#a40000","#ce5c00","#204a87","#babdb6","#8f5902","#5c3566","#2e3436"].map(i => i + "70"); //Tango Colors with opacity
  3. function addRectangle(){
  4. addRectangle1("", 0,0,1000,100)
  5. }
  6. function scalefactor(){
  7. return $('#sliceImg').innerWidth() / $('#sliceImg').prop('naturalWidth');
  8. }
  9. function refitRect(id){
  10. $('#Rect' + id).css('transform', 'scale(' + scalefactor() + ')');
  11. }
  12. function resizeAllRect() {
  13. console.log("resizing");
  14. for (var i = 0; i < rectID; i++) {
  15. refitRect(i);
  16. $('#Rect' + i).css("top", $('#Rect' + i).attr("y") * scalefactor() + "px");
  17. $('#Rect' + i).css("left", $('#Rect' + i).attr("x") * scalefactor() + "px");
  18. }
  19. }
  20. function changeRectPosition(id, style, amount){
  21. $('#Rect' + id).css(style, amount + "px");
  22. refitRect(id);
  23. }
  24. function addRectangle1(id,x,y,w,h,pattern,idtext,assignmentsstation,assignments){
  25. //Show input fields
  26. var clone = document.importNode(document.querySelector('#RectanglesSetup').content,true);
  27. var localID = rectID
  28. if(id != "")
  29. localID = id;
  30. $('[data-class=RectID]',clone).text("" + localID);
  31. $('[data-class=mainDiv]',clone).hover(function(){
  32. $('#Rect' + localID).css("background", colors[localID % colors.length]);
  33. $('#FormRect' + localID).css("background", colors[localID % colors.length]);
  34. },
  35. function(){
  36. $('#Rect' + localID).css("background", "none");
  37. $('#FormRect' + localID).css("background", "none");
  38. });
  39. $('[data-class=mainDiv]',clone).attr('id', 'FormRect' + localID);
  40. $('[data-class=x]',clone).val(x);
  41. $('[data-class=x]',clone).on('input', function(e) {
  42. changeRectPosition(localID, "left", this.value * scalefactor() );
  43. });
  44. $('[data-class=y',clone).val(y);
  45. $('[data-class=y]',clone).on('input', function(e) {
  46. changeRectPosition(localID, "top", this.value * scalefactor());
  47. });
  48. $('[data-class=w',clone).val(w);
  49. $('[data-class=w]',clone).on('input', function(e) {
  50. changeRectPosition(localID, "width", this.value );
  51. });
  52. $('[data-class=h',clone).val(h);
  53. $('[data-class=h]',clone).on('input', function(e) {
  54. changeRectPosition(localID, "height", this.value );
  55. });
  56. //allow to disable rectangle
  57. $('[data-class=setinactive]',clone).change(function() {
  58. $(this).parent().parent().parent().toggleClass("singleRect");
  59. });
  60. $('[data-class=removeRect]',clone).on('click', function(e) {
  61. $(this).parent().parent().parent().remove();
  62. });
  63. //Alle Abkürzungen einfügen und prüfen ob im pattern angegeben
  64. abk.forEach(function(item){
  65. var clonepattern = document.importNode(document.querySelector('#RectanglePattern').content,true);
  66. $('[data-class=abk]',clonepattern).text(item);
  67. $('[data-class=input]',clonepattern).prop('name', item);
  68. if(typeof pattern !== 'undefined' && pattern[item]){
  69. $('[data-class=input]',clonepattern).prop('checked', true);
  70. }
  71. $('[data-class=input]',clonepattern).change(refreshassignments);
  72. $('[data-class=RectanglePattern',clone).append(clonepattern);
  73. });
  74. var clonepatternidtext = document.importNode(document.querySelector('#RectanglePatternText').content,true);
  75. if(typeof idtext !== 'undefined'){
  76. $('[data-class=input]',clonepatternidtext).val(idtext);
  77. }
  78. $('[data-class=RectanglePattern',clone).append(clonepatternidtext);
  79. //add Assignment Station
  80. var clonepattern = document.importNode(document.querySelector('#RectanglesAssignment').content,true);
  81. $('[data-class=Assignment]',clonepattern).attr("name", "Station");
  82. $('[data-class=AssignmentAbk]',clonepattern).text("Station");
  83. //Stationen einfügen
  84. $.ajax({
  85. type: "GET",
  86. url: "../server/",
  87. dataType: "xml",
  88. success: function(xml) {
  89. $(xml).find('station').each(function(index){
  90. //console.log($(this).attr('id'));
  91. $('[data-class=AssignmentOptionen]',clonepattern).append('<option value="' + $(this).attr('id') +'">' + $(this).attr('id') +'</option>');
  92. });
  93. },
  94. async: false
  95. });
  96. //station hinzufügen/löschen
  97. $('[data-class=AssignmentAdd]',clonepattern).on('click', function(e) {
  98. var clonepatternvalue = document.importNode(document.querySelector('#RectanglesAssignmentValue').content,true);
  99. $('[data-class=AssignmentText]',clonepatternvalue).text(e.target.previousElementSibling.value);
  100. //löschen
  101. $('[data-class=AssignmentDelete]',clonepatternvalue).on('click', function(e) {
  102. e.target.parentNode.remove();
  103. });
  104. e.target.nextElementSibling.append(clonepatternvalue)
  105. });
  106. //Station Ausfüllen
  107. if(typeof assignmentsstation !== 'undefined' && assignmentsstation){
  108. $.each(assignmentsstation, function(i, item){
  109. var clonepatternvalue = document.importNode(document.querySelector('#RectanglesAssignmentValue').content,true);
  110. $('[data-class=AssignmentText]',clonepatternvalue).text(item);
  111. //löschen
  112. $('[data-class=AssignmentDelete]',clonepatternvalue).on('click', function(e) {
  113. e.target.parentNode.remove();
  114. });
  115. $('[data-class=AllAssignments]',clonepattern).append(clonepatternvalue)
  116. });
  117. }
  118. $('[data-class=RectangleAssignmentStation]',clone).append(clonepattern);
  119. //add assignments
  120. $.each( fullpattern["pattern"], function(i, item){
  121. var clonepattern = document.importNode(document.querySelector('#RectanglesAssignment').content,true);
  122. $('[data-class=Assignment]',clonepattern).attr("name", item["abk"]);
  123. $('[data-class=AssignmentAbk]',clonepattern).text(item["abk"]);
  124. $.each( item["types"], function(i, item){
  125. if(item != "")
  126. $('[data-class=AssignmentOptionen]',clonepattern).append('<option value="' + item +'">' + item +'</option>');
  127. });
  128. //einfügen
  129. $('[data-class=AssignmentAdd]',clonepattern).on('click', function(e) {
  130. var clonepatternvalue = document.importNode(document.querySelector('#RectanglesAssignmentValue').content,true);
  131. $('[data-class=AssignmentText]',clonepatternvalue).text(e.target.previousElementSibling.value);
  132. //löschen
  133. $('[data-class=AssignmentDelete]',clonepatternvalue).on('click', function(e) {
  134. e.target.parentNode.remove();
  135. });
  136. e.target.nextElementSibling.append(clonepatternvalue)
  137. });
  138. //Default Assignment nur bei angekreuzten pattern ausfüllen
  139. if(typeof pattern !== 'undefined' && pattern[item["abk"]]){
  140. $('[data-class=AssignmentDefaultValue]',clonepattern).text($("#FormPattern2_Form_" + item["abk"]).find(":selected").text());
  141. }
  142. //Assignment Ausfüllen
  143. if(typeof assignments !== 'undefined' && assignments[item["abk"]]){
  144. $.each(assignments[item["abk"]], function(i, item){
  145. var clonepatternvalue = document.importNode(document.querySelector('#RectanglesAssignmentValue').content,true);
  146. $('[data-class=AssignmentText]',clonepatternvalue).text(item);
  147. //löschen
  148. $('[data-class=AssignmentDelete]',clonepatternvalue).on('click', function(e) {
  149. e.target.parentNode.remove();
  150. });
  151. $('[data-class=AllAssignments]',clonepattern).append(clonepatternvalue)
  152. });
  153. }
  154. $('[data-class=RectangleAssignment]',clone).append(clonepattern);
  155. });
  156. $('#imgRectangles').append(clone);
  157. //add rectangle to image
  158. var clone = document.importNode(document.querySelector('#RectanglesImage').content,true);
  159. $('[data-class=RectID]',clone).attr("id","Rect" + localID);
  160. $('[data-class=RectID]',clone).attr("y",y);
  161. //Write text into img. such that this text shall equal the text on the slides
  162. var recttext = "";
  163. abk.forEach(function(item){
  164. if(typeof pattern !== 'undefined' && pattern[item]){
  165. recttext += item;
  166. }
  167. });
  168. if(typeof idtext !== 'undefined' && idtext != ""){
  169. recttext += "ID:" + idtext;
  170. }
  171. $('[data-class=RectID]',clone).text(recttext);
  172. $('[data-class=RectID]',clone).css("top", y * scalefactor() + "px");
  173. $('[data-class=RectID]',clone).css("left", x * scalefactor() + "px");
  174. $('[data-class=RectID]',clone).css("width", w + "px");
  175. $('[data-class=RectID]',clone).css("height", h + "px");
  176. $('[data-class=RectID]',clone).hover(function(){
  177. $('#FormRect' + localID).css("background", colors[localID % colors.length]);
  178. $('#Rect' + localID).css("background", colors[localID % colors.length]);
  179. $('#detailcolumn2').scrollTop( 0 );
  180. $('#detailcolumn2').scrollTop($('#FormRect' + localID).position().top - 50 );
  181. },
  182. function(){
  183. $("#detailcolumn2").stop();
  184. $('#FormRect' + localID).css("background", "none");
  185. $('#Rect' + localID).css("background", "none");
  186. });
  187. $('#imgrect').append(clone);
  188. refitRect(localID);
  189. ++rectID;
  190. new Sortable(document.getElementById('imgRectangles'),{
  191. handle: '.handle3',
  192. animation: 150
  193. });
  194. }
  195. function updateSlicerPatternForm(){
  196. }
  197. function createRectForm(station){
  198. var imgsrc = $("#sliceImg").attr("src")
  199. rectID = 0;
  200. $('#imgRectangles').text("");
  201. $('#imgrect').html('<img class="image" id="sliceImg" src=' + imgsrc +' alt="Alt text" />');
  202. $.getJSON( "../server/json/Rectangle.json", function( data ) {
  203. $.each( data["Configs"], function(i, item){
  204. if(item["name"] == station){
  205. $.each( item["rects"], function(i, item){
  206. addRectangle1(item["id"],item["X"],item["Y"],item["W"],item["H"],item["pattern"],item["idtext"],item["assignmentsstation"], item["assignments"]);
  207. });
  208. }
  209. });
  210. });
  211. }
  212. function loadStationsForm(){
  213. $.getJSON( "../server/json/Rectangle.json", function( data ) {
  214. $.each( data["Configs"], function(i, item){
  215. $("#loadconfig").append('<option value="' + item["name"] +'">' + item["name"] +'</option>');
  216. });
  217. $("#loadconfig").on('change', function() {
  218. createRectForm(this.value);
  219. });
  220. });
  221. }
  222. function createJson(){
  223. rects = []
  224. $(".singleRect").each(function() {
  225. var pats = {}
  226. $(this).find(".patternPart3").each(function() {
  227. $(this).find('.patternPart3Input:checked').each(function() {
  228. pats[$(this).attr('name')] = true;
  229. });
  230. });
  231. var txt;
  232. $(this).find(".patternPart3Text").each(function() {
  233. txt = $(this).children("input").val();
  234. });
  235. //get All stations
  236. var assignmentstation = assignmentGetAllStatios($(this));
  237. //get all assignments of current Rectangle
  238. var assignments = assignmentGetAllAssignments($(this));
  239. rect = {id: $( this ).find(".RectID").text(), X:$( this ).find('input[data-class="x"]').val(), Y:$( this ).find('input[data-class="y"]').val(), W:$( this ).find('input[data-class="w"]').val(), H:$( this ).find('input[data-class="h"]').val(), pattern: pats, idtext: txt, assignmentsstation: assignmentstation, assignments: assignments};
  240. rects.push(rect);
  241. });
  242. allrects = {name: $("#loadconfig").val(), rects: rects};
  243. return allrects;
  244. }
  245. function createJsonCutting(){
  246. var rects = createJson();
  247. rects.rects.forEach(function(value) {
  248. pattern = value.pattern;
  249. abk.forEach(function(item){
  250. if(typeof $("#FormPattern2_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern2_Form_" + item).val() !== 'undefined'){
  251. if(pattern[item]){
  252. //if rectangle is checked but nothing has been selected
  253. if($("#FormPattern2_Form_" + item).find(":selected").text() == ""){
  254. pattern[item] = "NoSelection";
  255. }
  256. else{
  257. pattern[item] = $("#FormPattern2_Form_" + item).find(":selected").text();
  258. }
  259. }
  260. }
  261. });
  262. });
  263. return rects;
  264. }
  265. function recCombi(data, currindex, result, cur) {
  266. var Keys = Object.keys(data);
  267. var optionKey = Keys[currindex];
  268. var vals = data[optionKey];
  269. for (var i = 0; i < vals.length; i++) {
  270. cur[optionKey] = vals[i];
  271. if (currindex + 1 < Keys.length) {
  272. recCombi(data, currindex + 1, result, cur);
  273. }
  274. else {
  275. var res = JSON.parse(JSON.stringify(cur));
  276. result.push(res);
  277. }
  278. }
  279. return result;
  280. }
  281. //gets assignment station for current rectangle
  282. function assignmentGetAllStatios(cur) {
  283. var assignmentstation = []
  284. cur.find(".RectangleAssignmentStation div").each(function() {
  285. var allass = new Set();
  286. $(this).find(".RectanglesAssignmentValue").each(function() {
  287. allass.add($(this).text());
  288. });
  289. if(allass.size)
  290. assignmentstation = Array.from(allass);
  291. });
  292. return assignmentstation;
  293. }
  294. //gets assignments for current rectangle
  295. function assignmentGetAllAssignments(cur, addDefaultValues = false) {
  296. var assignments = {};
  297. cur.find(".RectangleAssignment div").each(function() {
  298. assname = $(this).attr('name')
  299. var allass = new Set();
  300. if(addDefaultValues && $(this).find(".RectanglesAssignmentDefaultValue").first().text() != ""){
  301. allass.add($(this).find(".RectanglesAssignmentDefaultValue").first().text());
  302. }
  303. $(this).find(".RectanglesAssignmentValue").each(function() {
  304. allass.add($(this).text());
  305. });
  306. if(allass.size){
  307. assignments[assname] = Array.from(allass);
  308. }
  309. });
  310. return assignments;
  311. }
  312. function assignmentGetAllEmptyAssignments(cur){
  313. var assignments = {};
  314. cur.find(".RectangleAssignment div").each(function() {
  315. assname = $(this).attr('name')
  316. var allass = new Set();
  317. if($(this).find(".RectanglesAssignmentDefaultValue").first().text() != ""){
  318. allass.add($(this).find(".RectanglesAssignmentDefaultValue").first().text());
  319. }
  320. $(this).find(".RectanglesAssignmentValue").each(function() {
  321. allass.add($(this).text());
  322. });
  323. if(!allass.size){
  324. assignments[assname] = "";
  325. }
  326. });
  327. return assignments;
  328. }
  329. function submitSlices(skip = false){
  330. //createJsonCutting();
  331. //check if selected options are also selected in drop down menus
  332. var skippall = false;
  333. if(!skip){
  334. var checkedoptions = new Set();
  335. $("#imgRectangles wasRight input[type=checkbox]:checked").each(function(index, data){
  336. checkedoptions.add($(data).attr("name"))
  337. });
  338. var allskips = [];
  339. checkedoptions.forEach(function(item){
  340. if($("#FormPattern2_Form_" + item).find(":selected").text() == ""){
  341. allskips.push(item);
  342. }
  343. });
  344. if (Array.isArray(allskips) && allskips.length) {
  345. if(!confirm("Achtung: [" + allskips + "] nicht ausgefüllt, fortfahren?")){
  346. skippall = true;
  347. }
  348. }
  349. }
  350. if(!skippall){
  351. request = $.ajax({
  352. type: "POST",
  353. url: "imageSlicer.php",
  354. async: false,
  355. data: { url: $("#sliceImg").attr("src"), savelocation: $("#savelocation").val(), alldata: JSON.stringify(createJsonCutting()) },
  356. success: function(data){
  357. if (!data.hasOwnProperty('override')) {
  358. //clearFormFull();
  359. if(!skip){
  360. alert("Saved Images");
  361. }
  362. }
  363. else if(data.hasOwnProperty('error')){
  364. alert("Achtung Fehler: \n" + data.error)
  365. console.log(data);
  366. }
  367. else{
  368. if(!skip){
  369. overlayOnDupliImages(data.override);
  370. }
  371. }
  372. //Create Assignments (first returned url == first rectangle)
  373. if(data.hasOwnProperty('url')){
  374. var counter = 0;
  375. $(".singleRect").each(function() {
  376. var txt = "";
  377. $(this).find(".patternPart3Text").each(function() {
  378. txt = $(this).children("input").val();
  379. });
  380. //get All stations
  381. var assignmentstation = assignmentGetAllStatios($(this));
  382. //get all assignments of current Rectangle
  383. var assignments = assignmentGetAllAssignments($(this), true);
  384. //in case no assignments are found do next rect
  385. //console.log(assignments);
  386. if(Object.keys(assignments).length === 0){
  387. ++counter;
  388. return true;
  389. }
  390. //get all empty assignments of current Rectangle
  391. var emptyassignments = assignmentGetAllEmptyAssignments($(this));
  392. //get all combinations of assignments
  393. var result = recCombi(assignments, 0, [], {});
  394. //Save assignments
  395. //console.log("Save Assignemnts")
  396. $.each(assignmentstation, function(i, station) {
  397. $.each(result, function(i, item) {
  398. //console.log("saving " + i);
  399. var obj = new Object();
  400. obj.img = data.url[counter];
  401. obj.station = station;
  402. $.extend( item, emptyassignments );
  403. obj.parts = item;
  404. obj.assignmentText = txt;
  405. //console.log(obj);
  406. $("#cuttingProgress").text("Saving: " + JSON.stringify(obj))
  407. //use storage function from assignment.js
  408. submitAssignment(obj);
  409. });
  410. });
  411. ++counter;
  412. });
  413. }
  414. },
  415. error: function(xhr, status, error){
  416. console.error(xhr);
  417. }
  418. });
  419. }
  420. }
  421. function overlayOnDupliImages(data) {
  422. document.getElementById("overlayNotClickable").style.display = "block";
  423. var clone = document.importNode(document.querySelector('#SlicerDupliOverlay').content,true);
  424. $.each( data, function(i, item){
  425. var clone2 = document.importNode(document.querySelector('#SlicerDupliImageRow').content,true);
  426. $('[data-class=oldimg]',clone2).attr("src", item["old"] + '?rand=' + Math.random());
  427. $('[data-class=newimg]',clone2).attr("src", item["new"] + '?rand=' + Math.random());
  428. $('[data-class=changebutton]',clone2).attr("onclick", "javascript:changeimg(\"" + item["old"] + "\", \"" + item["new"] +"\", this )");
  429. $('[data-class=ImgList]',clone).append(clone2);
  430. });
  431. $('#overlaycontentsizeNotClickable').append(clone)
  432. }
  433. function changeimg(oldimg, newimg, buttonelement) {
  434. $.get( "imageOverride.php?overridden=" + oldimg + "&new=" + newimg , function( data ) {
  435. //hide button
  436. $(buttonelement).hide(200);
  437. });
  438. }
  439. function showJson(){
  440. copy2Clipboard(JSON.stringify(createJson()))
  441. }
  442. function overrideRect(){
  443. if (confirm('Please be carefull when overriding, are you sure?')) {
  444. var curjson = createJson();
  445. $.getJSON( "../server/json/Rectangle.json", function( data ) {
  446. //Override Rects
  447. $.each(data.Configs, function(i, item) {
  448. if(curjson.name == item.name){
  449. //data.Configs[i].rects = curjson.rects;
  450. item.rects = curjson.rects;
  451. console.log("Overriding")
  452. }
  453. });
  454. submitJson("Rectangle.json", JSON.stringify(data));
  455. });
  456. }
  457. }
  458. function copy2Clipboard(datalink) {
  459. const el = document.createElement('textarea');
  460. el.value = datalink;
  461. document.body.appendChild(el);
  462. el.select();
  463. document.execCommand('copy');
  464. document.body.removeChild(el);
  465. }
  466. function clearFormFull(){
  467. clearForm();
  468. $('#slicerpatterninput').val("");
  469. }
  470. function clearForm(){
  471. $('#FormPattern2').find("select").prop("selectedIndex",0);
  472. }
  473. function fillFormName(value){
  474. $("#slicerpatterninput").val(value);
  475. fillslicerpattern();
  476. }
  477. function fillpatternForm(e) {
  478. var code = (e.keyCode ? e.keyCode : e.which);
  479. if (code == 13) { //Enter keycode
  480. fillslicerpattern();
  481. }
  482. };
  483. function fillslicerpattern(){
  484. clearForm();
  485. jQuery.ajax({
  486. url: "TransformProductCode.php?ProductCode=" + $("#slicerpatterninput").val(),
  487. success: function (data) {
  488. $.each( data, function(i, item){
  489. $("#FormPattern2_Form_" + i).val(item);
  490. });
  491. },
  492. async: false
  493. });
  494. }
  495. function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
  496. $('#selectfolders').find('option').remove()
  497. $('#selectfolders').append("<option></option>")
  498. $.ajax({
  499. type: "GET",
  500. url: urlUniversalStorage + "server/allfolders/" + folder,
  501. async: false,
  502. dataType: "json",
  503. success: function(data) {
  504. $.each( data, function( key, value ) {
  505. $('#selectfolders').append("<option>" + value.slice(0,-1) +"</option>")
  506. });
  507. }
  508. });
  509. }
  510. function getAllFiles(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
  511. $.ajax({
  512. type: "GET",
  513. url: urlUniversalStorage + "server/images/" + folder,
  514. dataType: "json",
  515. success: function(data) {
  516. $.each( data, function( key, value ) {
  517. console.log(value);
  518. console.log(urlUniversalStorage + "storage/" + folder + "/" + value);
  519. $("#sliceImg").attr("src", urlUniversalStorage + "storage/" + folder + "/" + value)
  520. fillFormName(value);
  521. refreshassignments();
  522. submitSlices(true);
  523. /*
  524. $("#slicerpatterninput").val(value);
  525. fillslicerpattern();
  526. */
  527. });
  528. }
  529. });
  530. }
  531. function togglenext(currelement){
  532. currelement.next().slideToggle();
  533. }
  534. function refreshassignments(){
  535. console.log("Refreshing")
  536. $(".singleRect").each(function() {
  537. var main = $(this);
  538. $(this).find(".RectangleAssignment div").each(function() {
  539. var curabk = $(this).attr('name');
  540. var next = false;
  541. main.find(".patternPart3 .patternPart3Input:checked ").each(function() {
  542. if($(this).attr('name') == curabk){
  543. next = true;
  544. }
  545. });
  546. if(next){
  547. $(this).find(".RectanglesAssignmentDefaultValue").first().text($("#FormPattern2_Form_" + curabk).find(":selected").text())
  548. }
  549. else{
  550. $(this).find(".RectanglesAssignmentDefaultValue").first().text("")
  551. }
  552. });
  553. });
  554. }
  555. $(document).ready(function() {
  556. createPatternForm();
  557. updateSlicerPatternForm();
  558. loadStationsForm();
  559. getAllFolders();
  560. //press enter to fill out patternform
  561. $("#slicerpatterninput").bind("keypress", {}, fillpatternForm);
  562. /*
  563. $("#sliceImg").bind('load', function() {
  564. resizeAllRect();
  565. });*/
  566. /*
  567. $("#sliceImg").on('load', function () {
  568. resizeAllRect();
  569. });
  570. */
  571. /*
  572. $('#sliceImg').on('load',function(){
  573. resizeAllRect();
  574. });
  575. */
  576. $.getJSON( "../server/json/SlicerConfig.json", function( data ) {
  577. if(!data["SlicerRectForm"]){
  578. $("#addRectanglesGroup").hide();
  579. $("#imgRectangles").hide();
  580. $("#Json2ClipboardGroup").hide();
  581. }
  582. });
  583. $(document).on('submit', '#sliceform', function() { //prevent page reload on form submit
  584. return false;
  585. });
  586. $("#showJson").click(function() {
  587. showJson();
  588. });
  589. $("#overrideRect").click(function() {
  590. overrideRect();
  591. });
  592. $("#multiCut").click(function() {
  593. getAllFiles($('#selectfolders').val());
  594. });
  595. $('#pattern2').text("");
  596. var clone = document.importNode(document.querySelector('#patternClone').content,true);
  597. $('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
  598. $("#pattern2").append(clone);
  599. //handle zoom event in order to fix rectangle position
  600. window.addEventListener("resize", resizeAllRect, false);
  601. });