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.
57 lines
1.4 KiB
57 lines
1.4 KiB
<script>
|
|
const GetJsonErr = async (url) => {
|
|
const resp = await fetch(url);
|
|
return [await resp.json(), resp.status];
|
|
}
|
|
|
|
const post_user = (data, status) => {
|
|
if($no_error(data, status)) {
|
|
$redirect(`/admin/table/${data.table}/${data.id}`, true);
|
|
}
|
|
}
|
|
|
|
$boot(async () => {
|
|
let [resp, status] = await GetJsonErr('/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_user);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<h1><a href="/admin/table/{{ .table }}/">«</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>
|
|
|