Rename frontend request handler logic to SimpleRequestMixin

This commit is contained in:
Lance Edgar 2023-01-18 21:56:29 -06:00
parent 1e5b7e7ee7
commit dc6bd4d4a7

View file

@ -3,10 +3,41 @@
<%def name="declare_formposter_mixin()"> <%def name="declare_formposter_mixin()">
<script type="text/javascript"> <script type="text/javascript">
let FormPosterMixin = { let SimpleRequestMixin = {
methods: { methods: {
submitForm(action, params, success, failure) { simpleGET(url, params, success, failure) {
this.$http.get(url, {params: params}).then(response => {
if (response.data.error) {
this.$buefy.toast.open({
message: `Request failed: ${'$'}{response.data.error}`,
type: 'is-danger',
duration: 4000, // 4 seconds
})
if (failure) {
failure(response)
}
} else {
success(response)
}
}, response => {
this.$buefy.toast.open({
message: "Request failed: (unknown server error)",
type: 'is-danger',
duration: 4000, // 4 seconds
})
if (failure) {
failure(response)
}
})
},
simplePOST(action, params, success, failure) {
let csrftoken = ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n} let csrftoken = ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n}
@ -45,5 +76,9 @@
}, },
} }
// TODO: deprecate / remove
SimpleRequestMixin.methods.submitForm = SimpleRequestMixin.methods.simplePOST
let FormPosterMixin = SimpleRequestMixin
</script> </script>
</%def> </%def>