Use common POST logic for submitting new customer order

This commit is contained in:
Lance Edgar 2023-09-09 16:18:39 -05:00
parent ccb4661b39
commit a9fbf48053

View file

@ -1091,6 +1091,7 @@
const CustomerOrderCreator = {
template: '#customer-order-creator-template',
mixins: [SimpleRequestMixin],
data() {
let defaultUnitChoices = ${json.dumps(default_uom_choices)|n}
@ -1198,9 +1199,6 @@
pendingProduct: {},
departmentOptions: ${json.dumps(department_options)|n},
## TODO: should find a better way to handle CSRF token
csrftoken: ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n},
submittingOrder: false,
}
},
@ -1500,31 +1498,11 @@
submitBatchData(params, success, failure) {
let url = ${json.dumps(request.current_route_url())|n}
let headers = {
## TODO: should find a better way to handle CSRF token
'X-CSRF-TOKEN': this.csrftoken,
}
## TODO: should find a better way to handle CSRF token
this.$http.post(url, params, {headers: headers}).then((response) => {
if (response.data.error) {
this.$buefy.toast.open({
message: response.data.error,
type: 'is-danger',
duration: 2000, // 2 seconds
})
if (failure) {
failure(response)
}
} else if (success) {
this.simplePOST(url, params, response => {
if (success) {
success(response)
}
}, response => {
this.$buefy.toast.open({
message: "Unexpected error occurred",
type: 'is-danger',
duration: 2000, // 2 seconds
})
if (failure) {
failure(response)
}