design.js 23 KB

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