page.jinja2 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
  7. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha256-siyOpF/pBWUPgIcQi17TLBkjvNgNQArcmwJB8YvkAgg=" crossorigin="anonymous" />
  8. <link href="{{ static_url }}/tagsinput/tagsinput.css" rel="stylesheet" type="text/css">
  9. <title>{{ name|title }} form</title>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="card">
  14. <form>
  15. {# Schema modal #}
  16. <div class="card-header">
  17. <div class="row">
  18. <div class="col">
  19. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#schemaModal">
  20. YAML schema 🔗
  21. </button>
  22. </div>
  23. <div class="modal fade" id="schemaModal" tabindex="-1" role="dialog">
  24. <div class="modal-dialog modal-lg" role="document">
  25. <div class="modal-content">
  26. <div class="modal-header">
  27. <h5 class="modal-title">YAML schema</h5>
  28. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  29. <span aria-hidden="true">&times;</span>
  30. </button>
  31. </div>
  32. <div class="modal-body">
  33. <pre class="prettyprint">
  34. {{ schema|e }}
  35. </pre>
  36. </div>
  37. <div class="modal-footer">
  38. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. {# Main content #}
  46. <div class="card-body">
  47. {{ contents }}
  48. </div>
  49. <div class="card-footer">
  50. <button type="submit" class="btn btn-primary" onclick="return submitForm()">Get Code</button>
  51. <div class="modal fade" id="yaml-modal" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
  52. <div class="modal-dialog" role="document">
  53. <div class="modal-content">
  54. <div class="modal-header">
  55. <h5 class="modal-title" id="modal-label">Add Code</h5>
  56. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  57. <span aria-hidden="true">&times;</span>
  58. </button>
  59. </div>
  60. <div class="modal-body">
  61. <form>
  62. <div class="form-group">
  63. <textarea class="form-control" id="add-game-yaml-body" style="font-family:monospace;" rows="10">...</textarea>
  64. </div>
  65. </form>
  66. </div>
  67. <div class="modal-footer">
  68. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  69. <button type="button" class="btn btn-primary" onclick="copy()">Copy</button>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </form>
  76. </div>
  77. </div>
  78. <script
  79. src="https://code.jquery.com/jquery-3.4.1.min.js"
  80. integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  81. crossorigin="anonymous"></script>
  82. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.serializeJSON/2.9.0/jquery.serializejson.js" integrity="sha256-UzGjnR1p5Tnl9uHyGcbtthS4cULTf5z28PXVxHVElSQ=" crossorigin="anonymous"></script>
  83. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  84. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  85. <script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js" integrity="sha256-ry6nlLQ1JmRl5RUPQ4eSuaSp/rGNPvl144WHHs7BiNE=" crossorigin="anonymous"></script>
  86. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/1.0.5/jquery.csv.min.js" integrity="sha256-zGo0JbZ5Sn6wU76MyVL0TrUZUq5GLXaFnMQCe/hSwVI=" crossorigin="anonymous"></script>
  87. <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha256-bqVeqGdJ7h/lYPq6xrPv/YGzMEb6dNxlfiTUHSgRCp8=" crossorigin="anonymous"></script>
  88. <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
  89. <script src="{{ static_url }}/tagsinput/tagsinput.js"></script>
  90. <script src="{{ static_url }}/main.js"></script>
  91. <script>
  92. const getFormId = (keys) => (
  93. keys.map(key => `[${key}]`).join('')
  94. );
  95. const setFormValue = (keys, value) => {
  96. const formId = getFormId(keys);
  97. if (typeof value === 'object') {
  98. if (value.constructor === Array) {
  99. for (const childValue of value) {
  100. // Checkboxes
  101. $(document.getElementById(`${formId}.${childValue}`)).prop('checked', true);
  102. // Tagsinput
  103. $(document.getElementById(formId)).tagsinput('add', childValue);
  104. }
  105. } else {
  106. for (const [childKey, childValue] of Object.entries(value)) {
  107. setFormValue([...keys, childKey], childValue);
  108. }
  109. }
  110. } else {
  111. // Radio
  112. $(document.getElementById(`${formId}.${value}`)).prop('checked', true);
  113. // Fill normal inputs
  114. $(document.getElementById(formId)).val(value);
  115. }
  116. };
  117. $(document).ready(() => {
  118. $('[data-toggle="tooltip"]').tooltip()
  119. // Load data from params if provided
  120. const params = new URL(window.location.href).searchParams;
  121. const dataUrl = params.get('data');
  122. if (dataUrl) {
  123. $.get(dataUrl, (data) => {
  124. setFormValue([], data);
  125. document.title = `Edit ${data.name} form`;
  126. });
  127. }
  128. const original = params.get('original');
  129. if (original) {
  130. setFormValue([], {'originals': [original]});
  131. }
  132. // Set dark theme from setting in main site
  133. const THEME_KEY = 'theme';
  134. if (localStorage.getItem(THEME_KEY) === 'dark') {
  135. $("html").attr("data-bs-theme", "dark");
  136. } else if (localStorage.getItem(THEME_KEY) === 'light') {
  137. } else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
  138. $("html").attr("data-bs-theme", "dark");
  139. }
  140. });
  141. </script>
  142. </body>
  143. </html>