design.js 20 KB

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