109 lines
5.8 KiB
Plaintext
109 lines
5.8 KiB
Plaintext
{{- /*gotype: crud-generator/html_components.EditItemModal*/ -}}
|
|
{{ define "editItemModal" }}
|
|
{{$modalId := "edit-item-modal"}}
|
|
<div id="{{$modalId}}" tabindex="-1" aria-hidden="true"
|
|
class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
<div class="relative p-4 w-full max-w-md max-h-full">
|
|
<!-- Modal content -->
|
|
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
|
<!-- Modal header -->
|
|
<div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600">
|
|
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
|
|
{{.Title}}
|
|
</h3>
|
|
<button type="button"
|
|
class="modalClose text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white"
|
|
data-modal-toggle="{{$modalId}}"
|
|
>
|
|
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
|
|
viewBox="0 0 14 14">
|
|
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
|
|
</svg>
|
|
<span class="sr-only">Close modal</span>
|
|
</button>
|
|
</div>
|
|
<!-- Modal body -->
|
|
<form class="p-4 md:p-5"
|
|
id="editItemModalForm"
|
|
{{ if .IsCreate}}
|
|
data-hx-post="{{ .Url}}"
|
|
data-hx-target="#tableDisplay"
|
|
{{ end }}
|
|
{{ if not .IsCreate}}
|
|
data-hx-put="{{ .Url}}"
|
|
data-hx-target="#row-{{.Id}}"
|
|
{{ end }}
|
|
data-hx-swap="outerHTML"
|
|
{{ if .HaseFileUpload}}
|
|
data-hx-encoding="multipart/form-data"
|
|
{{ end }}
|
|
>
|
|
{{ if .HaseFileUpload}}
|
|
<progress id="progress" value="0" max="100" style="width: 100%"></progress>
|
|
<script>
|
|
htmx.on('#editItemModalForm', 'htmx:xhr:progress', function(evt) {
|
|
let progressValue = evt.detail.loaded/evt.detail.total * 100;
|
|
if (evt.detail.total === 0 || progressValue === 100) {
|
|
const modal = new Modal(document.getElementById('{{$modalId}}'));
|
|
modal.hide();
|
|
return
|
|
}
|
|
htmx.find('#progress').setAttribute('value', progressValue)
|
|
});
|
|
</script>
|
|
{{ end }}
|
|
<div class="grid gap-4 mb-4 grid-cols-2">
|
|
<div class="col-span-2">
|
|
{{ range .Inputs }}
|
|
{{ if eq .Type "text" }}
|
|
{{ template "textInput" . }}
|
|
{{ end }}
|
|
{{ if eq .Type "int" }}
|
|
{{ template "intInput" . }}
|
|
{{ end }}
|
|
{{ if eq .Type "enum" }}
|
|
{{ template "selectInput" . }}
|
|
{{ end }}
|
|
{{ if eq .Type "dateTime" }}
|
|
{{ template "dateTimeInput" . }}
|
|
{{ end }}
|
|
{{ if eq .Type "bool" }}
|
|
{{ template "booleanInput" . }}
|
|
{{ end }}
|
|
{{ if eq .Type "image" }}
|
|
{{ template "imageInput" . }}
|
|
{{ end }}
|
|
{{ end }}
|
|
</div>
|
|
</div>
|
|
<button type="submit"
|
|
class="{{ if not .HaseFileUpload}}modalClose {{end}}text-white inline-flex items-center bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
|
|
>
|
|
{{ if .IsCreate }}
|
|
<svg class="me-1 -ms-1 w-5 h-5" fill="currentColor" viewBox="0 0 20 20"
|
|
xmlns="http://www.w3.org/2000/svg">
|
|
<path fill-rule="evenodd"
|
|
d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z"
|
|
clip-rule="evenodd"></path>
|
|
</svg>
|
|
{{ end }}
|
|
{{ .SubmitButtonLabel }}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
(() => {
|
|
const modal = new Modal(document.getElementById('{{$modalId}}'));
|
|
document.querySelectorAll('.modalClose').forEach(function (element) {
|
|
element.addEventListener('click', function () {
|
|
modal.hide();
|
|
});
|
|
});
|
|
modal.show();
|
|
})()
|
|
</script>
|
|
{{ end }}
|