| | |
| | | data: this.changes.get(form.id)?.changes??{}, |
| | | }); |
| | | } |
| | | if (form.options.endpoint) { |
| | | console.log('Submitting form...'); |
| | | await this.handleServerSave(form, this.collectFormData(form.form)); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | if (form.options.cache) { |
| | | this.scheduleBackup(); |
| | | } |
| | | |
| | | if (form.options.endpoint) { |
| | | this.scheduleServerSave(form, changes); |
| | | } |
| | | } |
| | | |
| | | scheduleBackup() { |
| | |
| | | this.changes.delete(formId); |
| | | } |
| | | |
| | | scheduleServerSave(form, changes){ |
| | | |
| | | window.debouncer.schedule( |
| | | `form_${form.id}_server_save`, |
| | | async () => { |
| | | await this.handleServerSave(form, changes); |
| | | }, |
| | | 1500 |
| | | ); |
| | | } |
| | | cancelServerSave(formId) { |
| | | window.debouncer.cancel(`form_${formId}_server_save`); |
| | | } |
| | | async handleServerSave(form, changes) { |
| | | this.cancelServerSave(form.id); |
| | | |
| | | if (window.jvbQueue) { |
| | | changes.user = window.auth.getUser(); |
| | | window.jvbQueue.addToQueue({ |
| | | endpoint: form.options.endpoint, |
| | | data: changes, |
| | | headers: form.options.headers??{}, |
| | | }); |
| | | } else { |
| | | await window.auth.fetch(jvbBase.api+form.options.endpoint, { |
| | | body: changes, |
| | | headers: form.options.headers??{}, |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Register a form for handling |
| | |
| | | ignore: [], |
| | | ... options |
| | | }; |
| | | |
| | | //Bail if form already registered |
| | | if (Object.hasOwn(form.dataset, 'formId') && this.forms.has(form.dataset.formId)) return; |
| | | |
| | |
| | | |
| | | this.initializeFields(form, config); |
| | | this.forms.set(formId, config); |
| | | |
| | | return config; |
| | | } |
| | | clearForm(formId) { |