In function editor template modify add/delete functionality so it uses htmx.ajax and updates url

This commit is contained in:
Peter Stockings
2024-03-29 21:20:35 +11:00
parent 163a1dbc5f
commit cb3afa77fc
3 changed files with 22 additions and 27 deletions

View File

@@ -276,8 +276,8 @@
</button>
<button
class="bg-transparent hover:bg-red-500 text-red-700 font-semibold hover:text-white py-2 px-4 border border-red-500 hover:border-transparent rounded flex mr-2 items-center"
hx-delete="{{ url_for('delete_http_function', name=name) }}" hx-target="#container" hx-swap="innerHTML"
hx-confirm="Are you sure you want to delete {{ name }}?" hx-push-url="true">
hx-delete="{{ url_for('delete_http_function', function_id=function_id) }}" hx-target="#container"
hx-swap="innerHTML" hx-confirm="Are you sure you want to delete {{ name }}?" hx-push-url="true">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-4 h-4 mr-2">
<path stroke-linecap="round" stroke-linejoin="round"
@@ -337,18 +337,13 @@
let log_request = document.querySelector('#log_request').checked
let log_response = document.querySelector('#log_response').checked
fetch("{{ url_for('create_http_function') }}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ name, script_content, environment_info, is_public, log_request, log_response }),
})
.then(response => response.text())
.then(text => {
document.querySelector('#container').innerHTML = text
htmx.process(htmx.find('#container'))
})
htmx.ajax('POST', "{{ url_for('create_http_function') }}", {
target: '#container',
swap: 'innerHTML',
values: { name, script_content, environment_info, is_public, log_request, log_response }
});
})
</script>
{% endif %}