form.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  4. <title>work/out form</title>
  5. <!-- libs, do not modify. When local than load local libs. -->
  6. <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
  7. <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
  8. <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
  9. <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
  10. <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
  11. <script type="text/javascript" src="/js_libs/util.js"></script>
  12. <script type="text/javascript" src="/js_libs/printf.js"></script>
  13. <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
  14. <script type="text/javascript" src="/js_libs/parsequery.js"></script>
  15. <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
  16. <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
  17. <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
  18. <link rel="stylesheet" href="/js_libs/custommenu.css" type="text/css"/>
  19. <link rel="stylesheet" href="/js_libs/ui.css" type="text/css"/>
  20. <link rel="stylesheet" href="/js_libs/relaxngui.css" type="text/css"/>
  21. <!-- custom stuff, play arround -->
  22. <script src='../js/form-render.min.js'></script>
  23. <script>
  24. if (location.href.match(/\/$/) == null) {
  25. //location.href = location.href + '/';
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <form id="fb-render">
  31. <script>
  32. //https://stackoverflow.com/questions/5448545/how-to-retrieve-get-parameters-from-javascript
  33. function getSearchParameters() {
  34. var prmstr = window.location.search.substr(1);
  35. return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {};
  36. }
  37. function transformToAssocArray( prmstr ) {
  38. var params = {};
  39. var prmarr = prmstr.split("&");
  40. for ( var i = 0; i < prmarr.length; i++) {
  41. var tmparr = prmarr[i].split("=");
  42. params[tmparr[0]] = tmparr[1];
  43. }
  44. return params;
  45. }
  46. function openlink(menuitem){
  47. var menu = { name: menuitem };
  48. $.ajax({
  49. type: "PUT",
  50. url: window.name,
  51. contentType: "application/json",
  52. data: JSON.stringify(menu),
  53. success: function (data) {
  54. }
  55. });
  56. }
  57. var formRenderInstance;
  58. //https://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-object-with-jquery
  59. function objectifyForm(formArray) {
  60. //serialize data function
  61. var returnArray = {};
  62. for (var i = 0; i < formArray.length; i++){
  63. returnArray[formArray[i]['name']] = formArray[i]['value'];
  64. }
  65. return returnArray;
  66. }
  67. //return json data that should be sent when frames button is pressed
  68. function buttonPressed(){
  69. //does not allow for multi select boxes
  70. //getting formdata: https://gomakethings.com/serializing-form-data-with-the-vanilla-js-formdata-object/ */
  71. //var myForm = document.getElementById('fb-render');
  72. //return Object.fromEntries(new FormData(myForm));
  73. objectifyForm($("#fb-render").serializeArray())
  74. return objectifyForm($("#fb-render").serializeArray());
  75. //return formRenderInstance.userData;
  76. }
  77. jQuery(function($) {
  78. $.ajax({
  79. type: "GET",
  80. url: "./json",
  81. dataType: "json",
  82. success: function(json) {
  83. formRenderInstance = $('#fb-render').formRender({
  84. formData: json,
  85. });
  86. //necesarry as input fields do not have unique names resulting in overriding when the data is serialized
  87. $("#fb-render input[type=checkbox]").each(function(){
  88. this.name = this.value
  89. this.value = "true"
  90. });
  91. //Fill out inputs
  92. var urlpara = getSearchParameters();
  93. for (var key in urlpara) {
  94. if (urlpara.hasOwnProperty(key)) {
  95. $( "input[name*='" + key + "']" ).val( urlpara[key] );
  96. }
  97. }
  98. //$( "input[value*]" ).val( urlpara[key] );
  99. $(":input").each(function(){
  100. $(this).attr("onclick", $(this).attr("value"))
  101. });
  102. },
  103. error: function (request, status, error) {
  104. }
  105. });
  106. });
  107. </script>
  108. </body>
  109. </html>