imageSlicer.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. $.each(assignmentstation, function(i, station) {
  396. $.each(result, function(i, item) {
  397. var obj = new Object();
  398. obj.img = data.url[counter];
  399. obj.station = station;
  400. $.extend( item, emptyassignments );
  401. obj.parts = item;
  402. obj.assignmentText = txt;
  403. console.log(obj);
  404. //use storage function from assignment.js
  405. submitAssignment(obj);
  406. });
  407. });
  408. ++counter;
  409. });
  410. }
  411. },
  412. error: function(xhr, status, error){
  413. console.error(xhr);
  414. }
  415. });
  416. }
  417. }
  418. function overlayOnDupliImages(data) {
  419. document.getElementById("overlayNotClickable").style.display = "block";
  420. var clone = document.importNode(document.querySelector('#SlicerDupliOverlay').content,true);
  421. $.each( data, function(i, item){
  422. var clone2 = document.importNode(document.querySelector('#SlicerDupliImageRow').content,true);
  423. $('[data-class=oldimg]',clone2).attr("src", item["old"] + '?rand=' + Math.random());
  424. $('[data-class=newimg]',clone2).attr("src", item["new"] + '?rand=' + Math.random());
  425. $('[data-class=changebutton]',clone2).attr("onclick", "javascript:changeimg(\"" + item["old"] + "\", \"" + item["new"] +"\", this )");
  426. $('[data-class=ImgList]',clone).append(clone2);
  427. });
  428. $('#overlaycontentsizeNotClickable').append(clone)
  429. }
  430. function changeimg(oldimg, newimg, buttonelement) {
  431. $.get( "imageOverride.php?overridden=" + oldimg + "&new=" + newimg , function( data ) {
  432. //hide button
  433. $(buttonelement).hide(200);
  434. });
  435. }
  436. function showJson(){
  437. copy2Clipboard(JSON.stringify(createJson()))
  438. }
  439. function overrideRect(){
  440. if (confirm('Please be carefull when overriding, are you sure?')) {
  441. var curjson = createJson();
  442. $.getJSON( "../server/json/Rectangle.json", function( data ) {
  443. //Override Rects
  444. $.each(data.Configs, function(i, item) {
  445. if(curjson.name == item.name){
  446. //data.Configs[i].rects = curjson.rects;
  447. item.rects = curjson.rects;
  448. console.log("Overriding")
  449. }
  450. });
  451. submitJson("Rectangle.json", JSON.stringify(data));
  452. });
  453. }
  454. }
  455. function copy2Clipboard(datalink) {
  456. const el = document.createElement('textarea');
  457. el.value = datalink;
  458. document.body.appendChild(el);
  459. el.select();
  460. document.execCommand('copy');
  461. document.body.removeChild(el);
  462. }
  463. function clearFormFull(){
  464. clearForm();
  465. $('#slicerpatterninput').val("");
  466. }
  467. function clearForm(){
  468. $('#FormPattern2').find("select").prop("selectedIndex",0);
  469. }
  470. function fillFormName(value){
  471. $("#slicerpatterninput").val(value);
  472. fillslicerpattern();
  473. }
  474. function fillpatternForm(e) {
  475. var code = (e.keyCode ? e.keyCode : e.which);
  476. if (code == 13) { //Enter keycode
  477. fillslicerpattern();
  478. }
  479. };
  480. function fillslicerpattern(){
  481. clearForm();
  482. jQuery.ajax({
  483. url: "TransformProductCode.php?ProductCode=" + $("#slicerpatterninput").val(),
  484. success: function (data) {
  485. $.each( data, function(i, item){
  486. $("#FormPattern2_Form_" + i).val(item);
  487. });
  488. },
  489. async: false
  490. });
  491. }
  492. function getAllFolders(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
  493. $('#selectfolders').find('option').remove()
  494. $('#selectfolders').append("<option></option>")
  495. $.ajax({
  496. type: "GET",
  497. url: urlUniversalStorage + "server/allfolders/" + folder,
  498. async: false,
  499. dataType: "json",
  500. success: function(data) {
  501. $.each( data, function( key, value ) {
  502. $('#selectfolders').append("<option>" + value.slice(0,-1) +"</option>")
  503. });
  504. }
  505. });
  506. }
  507. function getAllFiles(folder = ""){ //Get DB 2 HTML //has to be synchronus in order to update before loading the rest
  508. $.ajax({
  509. type: "GET",
  510. url: urlUniversalStorage + "server/images/" + folder,
  511. dataType: "json",
  512. success: function(data) {
  513. $.each( data, function( key, value ) {
  514. console.log(value);
  515. console.log(urlUniversalStorage + "storage/" + folder + "/" + value);
  516. $("#sliceImg").attr("src", urlUniversalStorage + "storage/" + folder + "/" + value)
  517. fillFormName(value);
  518. submitSlices(true);
  519. /*
  520. $("#slicerpatterninput").val(value);
  521. fillslicerpattern();
  522. */
  523. });
  524. }
  525. });
  526. }
  527. function togglenext(currelement){
  528. currelement.next().slideToggle();
  529. }
  530. function refreshassignments(){
  531. console.log("Refreshing")
  532. $(".singleRect").each(function() {
  533. var main = $(this);
  534. $(this).find(".RectangleAssignment div").each(function() {
  535. var curabk = $(this).attr('name');
  536. var next = false;
  537. main.find(".patternPart3 .patternPart3Input:checked ").each(function() {
  538. if($(this).attr('name') == curabk){
  539. next = true;
  540. }
  541. });
  542. if(next){
  543. $(this).find(".RectanglesAssignmentDefaultValue").first().text($("#FormPattern2_Form_" + curabk).find(":selected").text())
  544. }
  545. else{
  546. $(this).find(".RectanglesAssignmentDefaultValue").first().text("")
  547. }
  548. });
  549. });
  550. }
  551. $(document).ready(function() {
  552. createPatternForm();
  553. updateSlicerPatternForm();
  554. loadStationsForm();
  555. getAllFolders();
  556. //press enter to fill out patternform
  557. $("#slicerpatterninput").bind("keypress", {}, fillpatternForm);
  558. /*
  559. $("#sliceImg").bind('load', function() {
  560. resizeAllRect();
  561. });*/
  562. /*
  563. $("#sliceImg").on('load', function () {
  564. resizeAllRect();
  565. });
  566. */
  567. /*
  568. $('#sliceImg').on('load',function(){
  569. resizeAllRect();
  570. });
  571. */
  572. $.getJSON( "../server/json/SlicerConfig.json", function( data ) {
  573. if(!data["SlicerRectForm"]){
  574. $("#addRectanglesGroup").hide();
  575. $("#imgRectangles").hide();
  576. $("#Json2ClipboardGroup").hide();
  577. }
  578. });
  579. $(document).on('submit', '#sliceform', function() { //prevent page reload on form submit
  580. return false;
  581. });
  582. $("#showJson").click(function() {
  583. showJson();
  584. });
  585. $("#overrideRect").click(function() {
  586. overrideRect();
  587. });
  588. $("#multiCut").click(function() {
  589. getAllFiles($('#selectfolders').val());
  590. });
  591. $('#pattern2').text("");
  592. var clone = document.importNode(document.querySelector('#patternClone').content,true);
  593. $('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
  594. $("#pattern2").append(clone);
  595. //handle zoom event in order to fix rectangle position
  596. window.addEventListener("resize", resizeAllRect, false);
  597. });