Rename frontend request handler logic to SimpleRequestMixin
This commit is contained in:
parent
1e5b7e7ee7
commit
dc6bd4d4a7
|
@ -3,10 +3,41 @@
|
|||
<%def name="declare_formposter_mixin()">
|
||||
<script type="text/javascript">
|
||||
|
||||
let FormPosterMixin = {
|
||||
let SimpleRequestMixin = {
|
||||
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}
|
||||
|
||||
|
@ -45,5 +76,9 @@
|
|||
},
|
||||
}
|
||||
|
||||
// TODO: deprecate / remove
|
||||
SimpleRequestMixin.methods.submitForm = SimpleRequestMixin.methods.simplePOST
|
||||
let FormPosterMixin = SimpleRequestMixin
|
||||
|
||||
</script>
|
||||
</%def>
|
||||
|
|
Loading…
Reference in a new issue