A small project that collects various nice things to get started with Go Web Development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.3 KiB

<script>
const post_form = (data, status) => {
if($no_error(data, status)) {
$redirect(`/admin/table/${data.table}/${data.id}`, true);
}
}
$boot(async () => {
let [resp, status] = await $get_json('/api/admin/table/new/{{ .table }}');
if($no_error(resp, status)) {
let data = [];
for(let key of Object.keys(resp)) {
data.push({key, value: resp[key]});
}
$render_data('data-template', 'data-form', data);
$handle_form('form', post_form);
}
});
</script>
<h1><a href="/admin/table/{{ .table }}/">&laquo;</a>Admin {{ .table }}</h1>
<block>
<div id='error'></div>
<template id="error-template">
<aside id='error'><mark class="alert">${ error }</mark></aside>
</template>
<form id="form" method="POST" action="/api/admin/table/new/{{ .table }}">
<card>
<top><h2>New {{ .table }}</h2></top>
<middle id="data-form">
<template id="data-template">
<div>
<label for="${item.key}">${item.key}</label>
<input name="${item.key}" value="" />
</div>
</template>
</middle>
<bottom>
<button type="button"><a href="/admin/table/{{ .table }}/">Back</a></button>
<button class="hover:btn-alert" type="button">Clear</button>
<button class="hover:btn-hover" type="submit">Insert</button>
</bottom>
</card>
</form>
</block>