FleetCart/Modules/Variation/Resources/assets/admin/js/edit.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-12-03 14:07:47 +00:00
import Vue from "vue";
import VariationMixin from "./mixins/VariationMixin";
import { toaster } from "@admin/js/Toaster";
new Vue({
el: "#app",
mixins: [VariationMixin],
created() {
this.form = this.prepareFormData(FleetCart.data["variation"]);
},
mounted() {
this.initColorPicker();
},
methods: {
prepareFormData(formData) {
formData.uid = this.uid();
formData.values.forEach((value) => {
value.uid = this.uid();
});
return formData;
},
submit() {
this.formSubmitting = true;
$.ajax({
type: "PUT",
url: route("admin.variations.update", this.form.id),
data: this.transformData(this.form),
dataType: "json",
success: (response) => {
toaster(response.message, {
type: "success",
});
this.errors.reset();
},
})
.catch((error) => {
this.errors.reset();
this.errors.record(error.responseJSON.errors);
this.scrollToFirstErrorField(this.$refs.form.elements);
})
.always(() => {
this.formSubmitting = false;
});
},
},
});