From 10f3ea0749028eaf9aeb61ad6bf3c2058b3b91d4 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Fri, 27 Dec 2024 15:35:49 +0000 Subject: [PATCH] Updated code to call correct endpoint for key Also moved ID for current record out of Curval condition --- .../form-group/autosave/lib/autosaveBase.ts | 9 ++++----- src/frontend/components/modal/modals/curval/index.js | 11 +---------- .../js/lib/util/gadsStorage/lib/gadsStorage.ts | 2 +- views/edit.tt | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/frontend/components/form-group/autosave/lib/autosaveBase.ts b/src/frontend/components/form-group/autosave/lib/autosaveBase.ts index 7acf4b3a1..cf88aac8e 100644 --- a/src/frontend/components/form-group/autosave/lib/autosaveBase.ts +++ b/src/frontend/components/form-group/autosave/lib/autosaveBase.ts @@ -3,8 +3,8 @@ import gadsStorage from "util/gadsStorage"; export default abstract class AutosaveBase extends Component { constructor(element: HTMLElement) { - super(element); - this.initAutosave(); + super(element); + this.initAutosave(); } get isClone() { @@ -16,8 +16,7 @@ export default abstract class AutosaveBase extends Component { } get recordId() { - const id = location.pathname.split('/').pop(); - return isNaN(parseInt(id)) ? 0 : id; + return $('body').find('.form-edit').data('current-id') || 0; } get storage() { @@ -28,7 +27,7 @@ export default abstract class AutosaveBase extends Component { return `linkspace-record-change-${this.layoutId}-${this.recordId}`; } - columnKey($field:JQuery) { + columnKey($field: JQuery) { return `linkspace-column-${$field.data('column-id')}-${this.layoutId}-${this.recordId}`; } diff --git a/src/frontend/components/modal/modals/curval/index.js b/src/frontend/components/modal/modals/curval/index.js index dab21b863..7b496874d 100644 --- a/src/frontend/components/modal/modals/curval/index.js +++ b/src/frontend/components/modal/modals/curval/index.js @@ -1,14 +1,5 @@ -//import { getComponentElements, initializeComponent } from 'component' import { initializeComponent } from 'component'; import CurvalModalComponent from './lib/component'; +// Originally this was an async load - this has been changed as the autosave code becomes overcomplex with async export default (scope) => initializeComponent(scope, '.modal--curval', CurvalModalComponent); - -//export default (scope) => { -// if (!getComponentElements(scope, '.modal--curval').length) return; - -// import(/* webpackChunkName="modal" */ "./lib/component") -// .then(({ default: CurvalModalComponent }) => { -// initializeComponent(scope, '.modal--curval', CurvalModalComponent) -// }); -//} diff --git a/src/frontend/js/lib/util/gadsStorage/lib/gadsStorage.ts b/src/frontend/js/lib/util/gadsStorage/lib/gadsStorage.ts index f6e12ce94..828231718 100644 --- a/src/frontend/js/lib/util/gadsStorage/lib/gadsStorage.ts +++ b/src/frontend/js/lib/util/gadsStorage/lib/gadsStorage.ts @@ -14,7 +14,7 @@ class GadsStorage { } private async getStorageKey() { - const fetchResult = await fetch("/get_key"); + const fetchResult = await fetch("/api/get_key"); const data = await fetchResult.json(); if (data.error !== 0) { throw new Error("Failed to get storage key"); diff --git a/views/edit.tt b/views/edit.tt index 5345a8dde..74f50e28c 100755 --- a/views/edit.tt +++ b/views/edit.tt @@ -11,6 +11,7 @@ class="[% IF edit_modal %]curval-edit-form[% ELSE %]form-edit[% END %]" method="post" enctype="multipart/form-data" + data-current-id="[% cur_id %]" [% IF edit_modal; action = cur_id @@ -19,7 +20,6 @@ %] action="[% action %]" [%# This form also used for bulk actions %] data-curval-id="[% edit_modal %]" - data-current-id="[% cur_id %]" data-modal-field-ids="[% modal_field_ids %]" data-instance-name="[% layout.identifier %]" [% END; %]