design.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. //delete = delets from DB
  2. //remove = removes from HTML
  3. //save = save to DB
  4. //add = changes HTML
  5. //get = get from DB
  6. //new = changes HTML
  7. var pictureWidth = 1280;
  8. var pictureHeight = 720;
  9. function overlayOn(value, showimage=false) {
  10. if(showimage){
  11. url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe&path=Stationsbilder/Gesamtbilder/Station3"
  12. }
  13. else{
  14. url = "https://centurio.work/customers/evva/universal-storage/ui/?iframe"
  15. }
  16. document.getElementById("overlay").style.display = "block";
  17. var iframe = $('#overlaycontentsize').append("<iframe id='overlaycontent' src='" + url + "' width='1800' height='800'></iframe>");
  18. iframe.find("#overlaycontent").bind('load',{"ka": value}, function(event){
  19. var ref = this.contentWindow.ref;
  20. //You can think that ref = $(this.contentWindow.test) but thery are different
  21. //they are two diferent references this might be a bug
  22. ref.bind('getUrl',{"xyz": event.data.ka}, function(event, extra1){
  23. var data = event.data
  24. overlayOff();
  25. //fill input with url
  26. if(!showimage){
  27. $(data.xyz).parent().parent().find(".abbreviationInput").val(extra1.url)
  28. }
  29. else{
  30. clearForm();
  31. //hide current image
  32. var newSrc = extra1.url + "?rand=" + Math.random();
  33. image = new Image();
  34. $("#sliceImg").hide("puff")
  35. //show new image and perform a resize of the rectangle
  36. image.onload = function() {
  37. $("#sliceImg").hide("puff", function() {
  38. $(this).attr("src", newSrc).show("fold");
  39. resizeAllRect();
  40. fillFormName(extra1.url.substring(extra1.url.lastIndexOf('/') + 1).replace(/\.[^/.]+$/, ""));
  41. });
  42. }
  43. image.src = newSrc;
  44. // $("#sliceImg").attr("src",extra1.url + "?rand=" + Math.random() )
  45. // resizeAllRect()
  46. }
  47. });
  48. });
  49. }
  50. function overlayOnImg(data) {
  51. var url = new URL("" + data, document.baseURI).href
  52. document.getElementById("overlay").style.display = "block";
  53. const imageext = ["png", "jpg", "svg"]
  54. const movieext = ["mp4"]
  55. var ext = url.substr(url.lastIndexOf('.') + 1);
  56. if(imageext.includes(ext)){
  57. $('#overlaycontentsize').load(url, function(){
  58. var width = $(this).children("svg").attr("width")
  59. var height = $(this).children("svg").attr("height")
  60. $(this).children("svg").attr("viewBox","0 0 " + width + " " + height);
  61. $(this).children("svg").attr("width",window.innerWidth * 0.7);
  62. $(this).children("svg").attr("height",window.innerHeight *0.7);
  63. });
  64. }
  65. else if(movieext.includes(ext)){
  66. $('#overlaycontentsize').append("<video id='overlaycontent' controls> <source src=" + url + " type=\"video/mp4\">Your browser does not support the video tag.</video>");
  67. }
  68. else{
  69. $('#overlaycontentsize').append("<iframe id='overlaycontent' src=" + url + "></iframe>");
  70. }
  71. }
  72. function overlayOff() {
  73. document.getElementById("overlay").style.display = "none";
  74. $('#overlaycontentsize').text("");
  75. document.getElementById("overlayNotClickable").style.display = "none";
  76. $('#overlaycontentsizeNotClickable').text("");
  77. }
  78. function saveStation() { //Save 2 DB
  79. if (confirm('Are you really, really, REALLY sure you want to create a New Station?')) {
  80. $.ajax({
  81. type: "POST",
  82. url: "../server/",
  83. success: function(res) {
  84. location.reload();
  85. }
  86. });
  87. }
  88. }
  89. function getStations(stationID , patternID ){ //Get DB 2 HTML
  90. $('#stations').text("");
  91. $.ajax({
  92. type: "GET",
  93. url: "../server/",
  94. dataType: "xml",
  95. success: function(xml) {
  96. $(xml).find('station').each(function(index){
  97. var clone = document.importNode(document.querySelector('#line').content,true);
  98. $('[data-class=station]',clone).text($(this).attr('id'));
  99. $('[data-class=pattern] a',clone).before("[");
  100. $('[data-class=pattern] a',clone).text("Add Pattern");
  101. $('[data-class=pattern] a',clone).after("]");
  102. $('[data-class=pattern] a',clone).attr('href','javascript:newPattern('+ $(this).attr('id') + ');');
  103. $('[data-class=duplicate]',clone).text("");
  104. $('[data-class=delete]',clone).text("");
  105. $('#stations').append(clone);
  106. var curstation=$(this).attr('id');
  107. $(this).find('pattern').each(function(index){
  108. var clonePattern = document.importNode(document.querySelector('#line').content,true);
  109. $('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
  110. $('[data-class=pattern] a',clonePattern).attr('href','javascript:getPattern(' + curstation + ','+ $(this).attr('id') + ');');
  111. $('[data-class=date]',clonePattern).text($.format.date(Date.parse($(this).attr('changed')), 'yyyy/MM/dd HH:mm:ss'));
  112. $('[data-class=duplicate] a',clonePattern).attr('href','javascript:duplicatePattern(' + curstation + ','+ $(this).attr('id') + ');');
  113. $('[data-class=delete] a',clonePattern).attr('href','javascript:deletePattern(' + curstation + ','+ $(this).attr('id') + ');');
  114. if (patternID != null && patternID == $(this).attr('id')){
  115. $('tr',clonePattern).css("background-color","#99cce6");
  116. }
  117. $('#stations').append(clonePattern);
  118. });
  119. });
  120. }
  121. });
  122. }
  123. function newPattern(stationID) { //HTML
  124. getPattern(stationID);
  125. }
  126. function getPattern(stationID, patternID){ //Get DB 2 HTML
  127. getStations(stationID, patternID)
  128. //rest Pattern
  129. abk.forEach(function(item){
  130. $("#FormPattern_Form_" + item).val();
  131. $("#FormPattern_Form_" + item).val($("#FormPattern_Form_" + item + " option:first").val());
  132. });
  133. if (patternID == null){
  134. $('#patternform').attr('onsubmit', "savePattern("+stationID+")");
  135. $('#pattern_ID').text("");
  136. $('#pattern_description').val("");
  137. $('#imageListing').text("");
  138. $('#images').css("display", "none");
  139. $('#remove_pattern').css("display", "none");
  140. $('#error').css("display", "none");
  141. $('#replacements').css("display", "none");
  142. }
  143. else{
  144. $('#patternform').attr('onsubmit', "saveChangedPattern("+stationID+","+ patternID +")");
  145. $('#pattern_ID').text(patternID);
  146. getImages(stationID, patternID);
  147. $('#remove_pattern').css("display", "block");
  148. $('#remove_pattern').attr('onclick', "javascript:deletePattern("+stationID+","+ patternID +")");
  149. getError(stationID, patternID);
  150. getReplaceImages(stationID, patternID);
  151. $.ajax({
  152. type: "GET",
  153. url: "../server/"+stationID+ "/" + patternID,
  154. dataType: "xml",
  155. success: function(xml) {
  156. $(xml).find('parts').children().each(function(index){
  157. /*
  158. $(this).find('pattern').each(function(index){
  159. var clonePattern = document.importNode(document.querySelector('#line').content,true);
  160. $('[data-class=pattern] a',clonePattern).text($(this).find('parts').children().map(function(i, element){return $(element).text()}).get().join("."));
  161. abk.forEach(function(item){
  162. if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
  163. $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
  164. }
  165. });
  166. */
  167. //console.log($(this).prop("tagName"));
  168. //console.log($(this).text());
  169. $("#FormPattern_Form_" + $(this).prop("tagName")).val($(this).text());
  170. /*
  171. var pattern = $(this).attr('value').split(".")
  172. for(var i = 0; i < pattern.length; i++)
  173. {
  174. if(i == 0){
  175. $("#patternInput .patternPartInput").val(pattern[i]);
  176. $("#patternInput .patternPartInput").attr('size', pattern[i].length);
  177. }
  178. else{
  179. var clone = document.importNode(document.querySelector('#patternClone').content,true);
  180. $('[data-class=part]',clone).val(pattern[i]);
  181. $('[data-class=part]',clone).limitkeypress({ rexp: keypressRegex() });
  182. $('[data-class=part]',clone).attr('size', pattern[i].length);
  183. $("#patternInput").append(clone);
  184. }
  185. }
  186. $('#pattern').val($(this).attr('value'));
  187. */
  188. $('#pattern_description').val($(this).attr('description'));
  189. });
  190. }
  191. });
  192. }
  193. $('#pattern_details').css("display", "block");
  194. $('#pattern_station').text(stationID);
  195. $('#pattern_description').text("");
  196. //Reset Pattern
  197. $('#patternInput').text("");
  198. var clone = document.importNode(document.querySelector('#patternClone').content,true);
  199. $('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
  200. $("#patternInput").append(clone);
  201. }
  202. function keypressRegex(){ //Helper Function
  203. return /^.{1,10}$/;
  204. //return /^[A-Za-z0-9\*]*$/; //Ohne Sonderzeichen
  205. }
  206. function removePatternPart(value) { //HTML
  207. if($( ".patternPart" ).length > 1)
  208. value.parent().remove();
  209. }
  210. function addPatternPart(useLast, curclass) { //HTML
  211. var clone = document.importNode(document.querySelector('#patternClone').content,true);
  212. $('[data-class=part]',clone).val("*");
  213. $('[data-class=part]',clone).limitkeypress({rexp: keypressRegex()});
  214. if(useLast){
  215. $("#" + curclass).children(".patternPart").last().after(clone);
  216. $("#" + curclass).last().children(".patternPartInput").focus();
  217. }else{
  218. $(':focus').parent().after(clone);
  219. $(':focus').parent().next().children(".patternPartInput").focus();
  220. }
  221. }
  222. function getPatternString(){ //Helper Function
  223. var val = "";
  224. var first = true;
  225. $(".patternPartInput").each(function() {
  226. if(first){
  227. first = false
  228. val += $(this).val()
  229. }
  230. else{
  231. val += "." + $(this).val()
  232. }
  233. });
  234. return val;
  235. }
  236. function savePattern(stationID) { //Save 2 DB
  237. var xmlDocument = $.parseXML("<pattern><parts></parts></pattern>");
  238. $(xmlDocument).find("pattern").attr('id','0');
  239. // #FormPattern
  240. abk.forEach(function(item){
  241. if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
  242. $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
  243. }
  244. });
  245. $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
  246. $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
  247. console.log((new XMLSerializer()).serializeToString(xmlDocument));
  248. $.ajax({
  249. type: "POST",
  250. headers: {"content-id": "pattern"},
  251. data: (new XMLSerializer()).serializeToString(xmlDocument),
  252. contentType: "application/xml; charset=utf-8",
  253. url: "../server/"+stationID,
  254. success: function(res) {
  255. //getPattern(stationID, res.id)
  256. },
  257. error: function (request, status, error) {
  258. //alert(request.responseText + status + error);
  259. }
  260. });
  261. }
  262. function saveChangedPattern(stationID, patternID) { //Save 2 DB
  263. var xmlDocument = $.parseXML("<pattern><parts></parts></pattern>");
  264. $(xmlDocument).find("pattern").attr('id',$('#pattern_ID').text());
  265. // #FormPattern
  266. abk.forEach(function(item){
  267. if(typeof $("#FormPattern_Form_" + item).val() !== 'undefined' && typeof $("#FormPattern_Form_" + item).val() !== 'undefined'){
  268. $(xmlDocument).find("parts").append("<"+item+">" +$("#FormPattern_Form_" + item).find(":selected").text()+"</"+item+">")
  269. }
  270. });
  271. $(xmlDocument).find("pattern").attr('description',$('#pattern_description').val());
  272. $(xmlDocument).find("pattern").attr('changed',new Date().toISOString());
  273. //Save Pattern
  274. $.ajax({
  275. type: "PUT",
  276. headers: {"content-id": "pattern"},
  277. data: (new XMLSerializer()).serializeToString(xmlDocument),
  278. contentType: "application/xml; charset=utf-8",
  279. url: "../server/"+stationID + "/" + patternID,
  280. //processData: false,
  281. success: function(res) {
  282. },
  283. error: function (request, status, error) {
  284. alert(request.responseText + status + error);
  285. }
  286. });
  287. //Update Labels
  288. $(".imageInput").each(function() {
  289. //Optimization only update if lable changed
  290. if($(this).val() != $(this).attr("origValue"))
  291. $.ajax({
  292. type: "PUT",
  293. data: { 'label' : $(this).val()},
  294. headers: {"content-id": "label"},
  295. url: "../server/"+stationID + "/" + patternID + "/images/" + $(this).parent().find(".imageID").text() +"/" + $('#image_language option:selected').text(),
  296. success: function(res) {
  297. },
  298. error: function (request, status, error) {
  299. alert(request.responseText + status + error);
  300. }
  301. });
  302. });
  303. //Update Image Ordering
  304. var order = []
  305. $(".imageID").each(function() {
  306. order.push(parseInt($(this).text()))
  307. });
  308. $.ajax({
  309. type: "PUT",
  310. data: JSON.stringify(order),
  311. headers: {"content-id": "orderlist"},
  312. contentType: "application/json",
  313. url: "../server/"+stationID + "/" + patternID + "/images/reorder/" + $('#image_language option:selected').text(),
  314. success: function(res) {
  315. },
  316. error: function (request, status, error) {
  317. alert(request.responseText + status + error);
  318. }
  319. });
  320. //Update Error
  321. var errorList = $.parseXML("<error/>");
  322. $(".errorInput").each(function() {
  323. $(errorList).find("error").append("<reason>" +$(this).val()+"</reason>")
  324. });
  325. $.ajax({
  326. type: "PUT",
  327. headers: {"content-id": "error"},
  328. data: (new XMLSerializer()).serializeToString(errorList),
  329. contentType: "application/xml; charset=utf-8",
  330. url: "../server/"+stationID + "/" + patternID + "/error",
  331. success: function(res) {
  332. },
  333. error: function (request, status, error) {
  334. alert(request.responseText + status + error);
  335. }
  336. });
  337. //Update Replacement
  338. var replaceList = $.parseXML("<replacement/>");
  339. $(".replaceInput").each(function() {
  340. //console.log($(this).find('.abbreviation').val())
  341. //console.log($(this).find('.url').val())
  342. $(replaceList).find("replacement").append("<item>" + "<abbreviation>" + $(this).find('.abbreviation').val() + "</abbreviation>" + "<url>" + $(this).find('.url').val() + "</url>"+"</item>")
  343. });
  344. $.ajax({
  345. type: "PUT",
  346. headers: {"content-id": "replacement"},
  347. data: (new XMLSerializer()).serializeToString(replaceList),
  348. contentType: "application/xml; charset=utf-8",
  349. url: "../server/"+stationID + "/" + patternID + "/replacement",
  350. success: function(res) {
  351. },
  352. error: function (request, status, error) {
  353. alert(request.responseText + status + error);
  354. }
  355. });
  356. getPattern(stationID, patternID)
  357. }
  358. function deletePattern(stationID, patternID) { //Delete From DB
  359. if (confirm('Are you really, really, REALLY sure!')) {
  360. $.ajax({
  361. type: "DELETE",
  362. url: "../server/" + stationID + "/" + patternID,
  363. success: function(res) {
  364. location.reload();
  365. }
  366. });
  367. }
  368. }
  369. function duplicatePattern(stationID, patternID){ //Get DB 2 HTML
  370. $.ajax({
  371. type: "PUT",
  372. headers: {"content-id": "patternID"},
  373. data: { "patternID":patternID},
  374. contentType: "application/json",
  375. url: "../server/"+stationID + "/" + patternID,
  376. success: function(res) {
  377. getPattern(stationID, res["id"])
  378. },
  379. error: function (request, status, error) {
  380. alert(request.responseText + status + error);
  381. }
  382. });
  383. }
  384. function getImages(stationID, patternID){ //Get From DB 2 HTML
  385. $('#images').css("display", "block");
  386. $('#imageListing').text("");
  387. $('#imgUpload').attr("action", "../server/" + stationID + "/" + patternID + "/images");
  388. $('#addExternalImageUrl').val("");
  389. $('#addExternalImage').attr("onclick", "addExternalImage(" + stationID + "," + patternID + ")");
  390. //Image preview needs pattern
  391. $.ajax({
  392. type: "GET",
  393. url: "../server/"+stationID+ "/" + patternID,
  394. dataType: "xml",
  395. success: function(xml) {
  396. pattern = xml.getElementsByTagName('pattern')[0].getAttribute("value");
  397. //get all images
  398. $.ajax({
  399. type: "GET",
  400. url: "../server/"+stationID+ "/" + patternID + "/images",
  401. dataType: "xml",
  402. success: function(xml) {
  403. var count = 0;
  404. $(xml).find('image').each(function(index){
  405. curID = $(this).attr('id')
  406. $(this).find('variant').each(function(){
  407. if($(this).attr('lang') == $('#image_language option:selected').text()){
  408. ++count;
  409. var clone = document.importNode(document.querySelector('#imagePreview').content,true);
  410. var imgsrcsingle = "../images/uploads/"+stationID+ "/" + patternID + "/" + curID + "/"+ $(this).attr('lang') + ".svg";
  411. var imgsrc = imgsrcsingle + "?" + Date.now();
  412. //$('[data-class=image]',clone).append('<img id="theImg" src="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
  413. //$('[data-class=image]',clone).append('<object class="theImg" id="theImg" data="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
  414. //managing that internal and external pictures look the same
  415. $('[data-class=image]',clone).load(imgsrc, function(){
  416. var width = $(this).children("svg").attr("width")
  417. var height = $(this).children("svg").attr("height")
  418. $(this).children("svg").attr("viewBox","0 0 " + pictureWidth + " " + pictureHeight + "");
  419. $(this).children("svg").attr("width","200");
  420. $(this).children("svg").attr("height","100");
  421. });
  422. $('[data-class=image]',clone).attr("onclick", "overlayOnImg('" + imgsrcsingle + "')" );
  423. //Image Preview
  424. $('[data-class=showimage]',clone).attr("href", "imageReplacement.php?___image___="+stationID+ "/" + patternID + "/" + curID + "/"+ $(this).attr('lang') + ".svg" +"&ProductCode=" + pattern + "&Station=" + "Station" + stationID);
  425. //$('[data-class=image]',clone).append('<object class="theImg" id="theImg" data="' + imgsrc +'" onclick="overlayOnImg(\'' +imgsrcsingle + '\')" height="100px" />')
  426. //$('[data-class=image]',clone).append('<div style="background-image: url(' + imgsrc+ ')" height="100px" />')
  427. $('[data-class=label]',clone).val($(this).attr('label'));
  428. $('[data-class=label]',clone).attr("origValue", $(this).attr('label'));
  429. $('[data-class=imageId]',clone).text(curID);
  430. $('[data-class=imageId]',clone).attr("class", "imageID")
  431. $('[data-class=options] a',clone).attr('href','javascript:deleteImage(' + stationID + ','+ patternID + ',' + curID + ',"' + $(this).attr('lang') + '");');
  432. $('#imageListing').append(clone);
  433. }
  434. });
  435. });
  436. $('#image_count').text(count);
  437. /*
  438. $(".image").each(function() {
  439. alert("mhm");
  440. $(this).children().attr("viewBox","0 0 " + "300" + " 300");
  441. });
  442. */
  443. }
  444. });
  445. }
  446. });
  447. new Sortable(document.getElementById('imageListing'),{
  448. handle: '.handle',
  449. animation: 150
  450. });
  451. new Sortable(document.getElementById('replaceImages'),{
  452. handle: '.handle2',
  453. animation: 150
  454. });
  455. }
  456. function addExternalImage(stationID, patternID){
  457. var extImage = $.parseXML("<externalImage/>");
  458. $(extImage).find("externalImage").append("<url>" + $('#addExternalImageUrl').val() +"</url>");
  459. $(extImage).find("externalImage").append("<lang>" + $('#image_language option:selected').text() + "</lang>");
  460. console.log(extImage);
  461. $.ajax({
  462. type: "POST",
  463. headers: {"content-id": "externalImage"},
  464. data: (new XMLSerializer()).serializeToString(extImage),
  465. contentType: "application/xml; charset=utf-8",
  466. url: "../server/" + stationID + "/" + patternID + "/images",
  467. success: function(res) {
  468. getPattern(stationID, patternID)
  469. }
  470. });
  471. }
  472. function deleteImage(stationID, patternID, imageID, lang) { //Delete From DB
  473. $.ajax({
  474. type: "DELETE",
  475. url: "../server/" + stationID + "/" + patternID + "/images/" + imageID + "/" + lang,
  476. success: function(res) {
  477. getPattern(stationID, patternID)
  478. }
  479. });
  480. }
  481. function addError() { //HTML
  482. //Will be added from DB on save
  483. var clone = document.importNode(document.querySelector('#errorCode').content,true);
  484. $('#errorCodes').append(clone);
  485. }
  486. function getError(stationID, patternID){ //Get From DB 2 HTML
  487. $('#error').css("display", "block");
  488. $('#errorCodes').text("");
  489. $.ajax({
  490. type: "GET",
  491. url: "../server/"+stationID+ "/" + patternID + "/error",
  492. dataType: "xml",
  493. success: function(xml) {
  494. $(xml).find('reason').each(function(index){
  495. var clone = document.importNode(document.querySelector('#errorCode').content,true);
  496. $('[data-class=errorInput]',clone).val($(this).text());
  497. $('#errorCodes').append(clone);
  498. });
  499. }
  500. });
  501. }
  502. function removeError(value) { //HTML
  503. //Will be removed from DB on save
  504. value.parent().parent().parent().remove();
  505. }
  506. function addBlankReplacement() { //HTML
  507. //Will be added from DB on save
  508. var clone = document.importNode(document.querySelector('#imageReplacements').content,true);
  509. $('#replaceImages').append(clone);
  510. }
  511. function getReplaceImages(stationID, patternID){ //Get From DB 2 HTML
  512. $('#replacements').css("display", "block");
  513. $('#replaceImages').text("");
  514. $.ajax({
  515. type: "GET",
  516. url: "../server/"+stationID+ "/" + patternID + "/replacement",
  517. dataType: "xml",
  518. success: function(xml) {
  519. $(xml).find('item').each(function(index){
  520. var clone = document.importNode(document.querySelector('#imageReplacements').content,true);
  521. $('[data-class=abbreviation]',clone).val($(this).find('abbreviation').text());
  522. $('[data-class=url]',clone).val($(this).find('url').text());
  523. $('#replaceImages').append(clone);
  524. });
  525. }
  526. });
  527. }
  528. function removeReplacement(value) { //HTML
  529. //Will be removed from DB on save
  530. value.parent().parent().parent().remove();
  531. }
  532. //Go to next PatternInput on . or space keydown
  533. $(window).keydown(function(e) {
  534. if ((e.which === 32 || e.which === 190) && $(':focus').attr('class') === "patternPartInput") {
  535. e.preventDefault();
  536. addPatternPart(false);
  537. }
  538. });
  539. $(document).ready(function() {
  540. getStations(); //Get all Stations
  541. $("#image_language" ).change(function() {
  542. getImages($('#pattern_station').text(), $('#pattern_ID').text())
  543. });
  544. $(document).on('submit', '#patternform', function() { //prevent page reload on form submit
  545. return false;
  546. });
  547. $('.patternPartInput').limitkeypress({rexp: keypressRegex()});
  548. });