Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/GADS/Role/Presentation/Record.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
6 changes: 6 additions & 0 deletions src/frontend/components/button/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) => {
Expand Down
33 changes: 33 additions & 0 deletions src/frontend/components/button/lib/modal-curval-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Modal} from "bootstrap";
import CurvalModalComponent from "components/modal/modals/curval";

/**
* Create modal curval button
* @param {JQuery<HTMLElement>} element The element to function as an open modal curval button
*/
export default function createModalCurvalButton(element: JQuery<HTMLElement>) {

/* 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));
});
}
4 changes: 2 additions & 2 deletions src/frontend/components/modal/modals/curval/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CurvalModalComponent extends ModalComponent {
const instance_name = $field.data("curval-instance-name");
const editButton = $(
`<td>
<button type="button" class="btn btn-sm btn-link btn-js-curval-modal" data-bs-toggle="modal" data-bs-target="#curvalModal" data-layout-id="${col_id}"
<button type="button" class="btn btn-sm btn-link btn-js-curval-modal" data-layout-id="${col_id}"
data-instance-name="${instance_name}" ${current_id ? `data-current-id="${current_id}"`:""}>
<span class="btn__title">Edit</span>
</button>
Expand Down Expand Up @@ -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());
}

Expand Down
2 changes: 0 additions & 2 deletions src/frontend/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -56,7 +55,6 @@ registerComponent(CalcFieldsComponent);
registerComponent(CalculatorComponent);
registerComponent(CheckboxComponent);
registerComponent(CollapsibleComponent);
registerComponent(CurvalModalComponent);
registerComponent(DashboardComponent);
registerComponent(DataTableComponent);
registerComponent(DependentFieldsComponent);
Expand Down
7 changes: 2 additions & 5 deletions views/edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,6 @@
<button
type="button"
class="btn btn-js-curval-modal btn-add-link"
data-bs-toggle="modal"
data-bs-target=#curvalModal
>
<span class="btn__title">Add</span>
</button>
Expand All @@ -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"
Expand Down Expand Up @@ -1123,7 +1120,7 @@
}]
}
}
modal = {
data = {
dataCurrentId = val.id
dataLayoutId = col.id
dataInstanceName = col.layout_parent.identifier
Expand Down
7 changes: 6 additions & 1 deletion views/tables/basic_cell_button.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
%]
<td [% cell_class %][% data_attr %]>
[% IF button_type == "button" %]
<button type="button" class="[% button_class || 'btn btn-primary' %]">
<button
type="button" class="[% button_class || 'btn btn-primary' %]"[% IF dataInstanceName %]
data-instance-name="[% dataInstanceName | html %]"[% END %][% IF dataLayoutId %]
data-layout-id="[% dataLayoutId | html %]"[% END %][% IF dataCurrentId %]
data-current-id="[% dataCurrentId | html %]"[% END %]
>
<span class="btn__title">[% INCLUDE fields/sub/filter.tt value=label; %]</span>
</button>
[% ELSE %]
Expand Down
5 changes: 1 addition & 4 deletions views/tables/basic_cell_modal_button.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %]
>
Expand Down
8 changes: 4 additions & 4 deletions views/tables/basic_row.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions views/tables/basic_table.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
});
Expand Down
3 changes: 2 additions & 1 deletion views/wizard/curval.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="modal modal--curval" id="[% modalId %]" tabindex="-1" role="dialog" aria-labelledby="[% modalId %]]Label" aria-hidden="true">
[%# This is only a template, class modal--curval is added after cloning to ensure this modal is not incorrectly used %]
<div class="modal" id="[% modalId %]" tabindex="-1" role="dialog" aria-labelledby="[% modalId %]]Label" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered " role="document">
<div class="modal-content">
[% INCLUDE wizard/sub/modal_header.tt; %]
Expand Down
Loading