1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| {% import ( "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/util" ) %}
{% func JSONModal(key string, title string, item any, indent int) %}{% stripspace %} <div id="modal-{%s key %}" class="modal" style="display: none;"> <a class="backdrop" href="#"></a> <div class="modal-content"> <div class="modal-header"> <a href="#" class="modal-close">×</a> <h2>{%s title %}</h2> </div> <div class="modal-body"> <div id="modal-{%s key %}-data" hidden="hidden" style="display:none;">{%s util.ToJSON(item) %}</div> <button onclick="clip('{%s key %}');">Copy to clipboard</button> <div class="mt"> {%= JSON(item) %} </div> </div> </div> </div> <script> function clip(k) { if (!navigator.clipboard) { return; } const el = document.getElementById("modal-" + k + "-data"); navigator.clipboard.writeText(el.innerText); } </script> {% endstripspace %}{% endfunc %}
{% func JSON(v any) %}{% stripspace %} {% code b, ok := v.([]byte) if ok { _ = util.FromJSON(b, &v) } %} {% code out, err := cutil.FormatJSON(v) %} {% if err == nil %} {%s= out %} {% else %} {%s err.Error() %} {% endif %} {% endstripspace %}{% endfunc %}
|