1// Copyright (c) 2021-2025 GrayBits LLC 2 3import * as Notification from 'gray_matter/utility/notification' 4import PopInInterface from 'gray_matter/utility/pop_in_interface' 5import Errors from 'gray_matter/forms/errors' 6import axios from 'axios' 7 8export default class MiniForm extends PopInInterface { 9 constructor(parent, options){ 10 super(parent, options); 11 this.preSubmit = options.pre_submit; 12 this.postSubmit = options.post_submit; 13 this.onError = options.on_error; 14 this.miniFormSetup = options.mini_form_setup; 15 this.processing = false; 16 } 17 setup(pop_in){ 18 if (this.miniFormSetup){ 19 this.miniFormSetup(this); 20 } 21 this.form = this.element.querySelector('form'); 22 this.form.dataset.turbo = false; 23 this.submit_buttons = this.form.querySelectorAll('button[type="submit"]'); 24 this.form.addEventListener('submit', e => this.submitForm(e)); 25 this.errors = new Errors(this.form); 26 } 27 28 preventSubmission(){ 29 this.processing = true; 30 this.submit_buttons.forEach((e) => e.disabled = true); 31 } 32 33 enableSubmission(){ 34 this.processing = false; 35 this.submit_buttons.forEach((e) => e.disabled = false); 36 } 37 38 async submitForm(e, leave_open){ 39 if (this.processing) return; 40 this.preventSubmission(); 41 42 e.stopPropagation(); 43 e.preventDefault(); 44 try { 45 if (this.preSubmit){ 46 this.preSubmit(e, this); 47 } 48 const response = await axios[this.form.method](this.form.action, new FormData(this.form)); 49 if (!leave_open) this.cancel(e, response.data.parent); 50 if (this.postSubmit){ 51 this.postSubmit(e, this, response); 52 } 53 this.enableSubmission(); 54 } catch(error) { 55 if (this.onError){ 56 this.onError(e, this, error); 57 } 58 Notification.showResponseError(error); 59 this.errors.clear(); 60 this.errors.show(error.response.data); 61 this.enableSubmission(); 62 } 63 } 64};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.