diff --git a/lib/GADS/Role/Presentation/Record.pm b/lib/GADS/Role/Presentation/Record.pm index 155d65440..0e0e14f6b 100644 --- a/lib/GADS/Role/Presentation/Record.pm +++ b/lib/GADS/Role/Presentation/Record.pm @@ -20,9 +20,6 @@ sub edit_columns @columns = grep $_->userinput || $_->has_browser_code, @columns if $options{new}; - @columns = grep !$_->is_curcommon || !$_->show_add , @columns - if $options{modal}; - @columns = grep $_->type ne 'file', @columns if $options{bulk} && $options{bulk} eq 'update'; diff --git a/src/frontend/components/button/lib/component.ts b/src/frontend/components/button/lib/component.ts index 93d852185..eb118a3d2 100644 --- a/src/frontend/components/button/lib/component.ts +++ b/src/frontend/components/button/lib/component.ts @@ -99,6 +99,12 @@ class ButtonComponent extends Component { createRemoveCurvalButton(el); }); }); + map.set("btn-js-curval-modal", (el) => { + import(/* webpackChunkName: "curval-modal-button" */ "./modal-curval-button") + .then(({default: createModalCurvalButton}) => { + createModalCurvalButton(el); + }); + }); map.set("btn-js-remove-unload", (el) => { import(/* webpackChunkName: "remove-unload-button" */ "./remove-unload-button") .then(({default: createRemoveUnloadButton}) => { diff --git a/src/frontend/components/button/lib/modal-curval-button.ts b/src/frontend/components/button/lib/modal-curval-button.ts new file mode 100644 index 000000000..98da48d7e --- /dev/null +++ b/src/frontend/components/button/lib/modal-curval-button.ts @@ -0,0 +1,33 @@ +import {Modal} from "bootstrap"; +import CurvalModalComponent from "components/modal/modals/curval"; + +/** + * Create modal curval button + * @param {JQuery} element The element to function as an open modal curval button + */ +export default function createModalCurvalButton(element: JQuery) { + + /* The ID of the curval field that this button is for */ + const field_id = element.closest('.linkspace-field').data('column-id'); + /* To enable multiple modals to be open create a new modal for each curval + * field, based on the field ID */ + const modal_id = 'curvalModal' + field_id; + /* Has it already been created in the document? */ + if (!$("#"+modal_id).length) { + const $modal = $("#curvalModal").clone(); + $modal.attr("id", modal_id); + /* This class is to ensure the component is initialized */ + $modal.addClass("modal--curval"); + /* Always add to the end, so that layering is possible and the last + * always displays at the top */ + $modal.insertAfter($('.modal').last()); + CurvalModalComponent($modal.closest(".content-block")); + } + /* At this point the modal may have been initialised already (e.g. + * if this code is to create the edit button for a curval) or it may + * not, so use getOrCreateInstance() so that it handles both situations */ + const modal = Modal.getOrCreateInstance('#'+modal_id, {}); + element.on("click", (ev: JQuery.ClickEvent) => { + modal.show(element.get(0)); + }); +} diff --git a/src/frontend/components/modal/modals/curval/lib/component.js b/src/frontend/components/modal/modals/curval/lib/component.js index e7f2c4a86..41c0d36f1 100644 --- a/src/frontend/components/modal/modals/curval/lib/component.js +++ b/src/frontend/components/modal/modals/curval/lib/component.js @@ -133,7 +133,7 @@ class CurvalModalComponent extends ModalComponent { const instance_name = $field.data("curval-instance-name"); const editButton = $( ` - @@ -335,7 +335,7 @@ class CurvalModalComponent extends ModalComponent { // At this point we either have a full form's values, or nothing at all. // If nothing at all we need to add the CSRF token for the POST request. if (form_data.getAll("csrf_token").length == 0) { - const $csrf = $field.closest("form.form-edit").find("input[name=\"csrf_token\"]"); + const $csrf = $field.closest("form").find("input[name=\"csrf_token\"]"); form_data.append("csrf_token", $csrf.val()); } diff --git a/src/frontend/js/site.js b/src/frontend/js/site.js index 5e05ed93f..356b6ba4d 100644 --- a/src/frontend/js/site.js +++ b/src/frontend/js/site.js @@ -14,7 +14,6 @@ import CalcFieldsComponent from "components/form-group/calc-fields"; import CalculatorComponent from "components/calculator"; import CheckboxComponent from "components/form-group/checkbox"; import CollapsibleComponent from "components/collapsible"; -import CurvalModalComponent from "components/modal/modals/curval"; import DashboardComponent from "components/dashboard"; import DataTableComponent from "components/data-table"; import DependentFieldsComponent from "components/form-group/dependent-fields"; @@ -56,7 +55,6 @@ registerComponent(CalcFieldsComponent); registerComponent(CalculatorComponent); registerComponent(CheckboxComponent); registerComponent(CollapsibleComponent); -registerComponent(CurvalModalComponent); registerComponent(DashboardComponent); registerComponent(DataTableComponent); registerComponent(DependentFieldsComponent); diff --git a/views/edit.tt b/views/edit.tt index c09c03a9c..edbebf0d0 100755 --- a/views/edit.tt +++ b/views/edit.tt @@ -1061,8 +1061,6 @@ @@ -1082,9 +1080,8 @@ table_columns = []; table_buttons = [{ - type = "modal_button" + button_type = "button" button_class = "btn btn-sm btn-link btn-js-curval-modal" - modalId = "curvalModal" label = "Edit" filter = "" sub_field = "fields/hidden.tt" @@ -1123,7 +1120,7 @@ }] } } - modal = { + data = { dataCurrentId = val.id dataLayoutId = col.id dataInstanceName = col.layout_parent.identifier diff --git a/views/tables/basic_cell_button.tt b/views/tables/basic_cell_button.tt index 8c47df189..ab65b1e32 100644 --- a/views/tables/basic_cell_button.tt +++ b/views/tables/basic_cell_button.tt @@ -4,7 +4,12 @@ %] [% IF button_type == "button" %] - [% ELSE %] diff --git a/views/tables/basic_cell_modal_button.tt b/views/tables/basic_cell_modal_button.tt index dc15a89f9..2d6d4f639 100644 --- a/views/tables/basic_cell_modal_button.tt +++ b/views/tables/basic_cell_modal_button.tt @@ -8,10 +8,7 @@ type="button" class="[% button_class || 'btn btn-delete btn-sm btn-js-delete' %]" data-bs-toggle="modal" - data-bs-target="#[% modalId | html %]"[% IF dataInstanceName %] - data-instance-name="[% dataInstanceName | html %]"[% END %][% IF dataLayoutId %] - data-layout-id="[% dataLayoutId | html %]"[% END %][% IF dataCurrentId %] - data-current-id="[% dataCurrentId | html %]"[% END %][% IF dataTitle %] + data-bs-target="#[% modalId | html %]"[% IF dataTitle %] data-title="[% dataTitle | html %]"[% END %][% IF dataID %] data-id=[% dataID | html %][% END %] > diff --git a/views/tables/basic_row.tt b/views/tables/basic_row.tt index 038ea0420..7676d707a 100644 --- a/views/tables/basic_row.tt +++ b/views/tables/basic_row.tt @@ -37,7 +37,10 @@ sub_field=field.sub_field sub_params=field.sub_params field_name=field.name - field_value=field.value; + field_value=field.value + dataInstanceName=field.dataInstanceName + dataLayoutId=field.dataLayoutId + dataCurrentId=field.dataCurrentId; CASE 'modal_button'; INCLUDE tables/basic_cell_modal_button.tt class=field.class @@ -50,9 +53,6 @@ field_name=field.name field_value=field.value modalId=field.modalId - dataInstanceName=field.dataInstanceName - dataLayoutId=field.dataLayoutId - dataCurrentId=field.dataCurrentId dataTitle=field.dataTitle dataID=field.dataID; CASE 'header'; diff --git a/views/tables/basic_table.tt b/views/tables/basic_table.tt index d7f4fa630..641d57898 100644 --- a/views/tables/basic_table.tt +++ b/views/tables/basic_table.tt @@ -77,9 +77,9 @@ modalId = button.modalId || '' sub_field = button.sub_field || '' sub_params = button.sub_params || row.button.sub_params || '' - dataCurrentId = row.modal.dataCurrentId || '' - dataLayoutId = row.modal.dataLayoutId || '' - dataInstanceName = row.modal.dataInstanceName || '' + dataCurrentId = row.data.dataCurrentId || '' + dataLayoutId = row.data.dataLayoutId || '' + dataInstanceName = row.data.dataInstanceName || '' dataTitle = row.modal.dataTitle || '' dataID = row.modal.dataID || '' }); diff --git a/views/wizard/curval.tt b/views/wizard/curval.tt index d98c963e4..56916add3 100644 --- a/views/wizard/curval.tt +++ b/views/wizard/curval.tt @@ -1,4 +1,5 @@ -