Skip to content

Commit

Permalink
MDL-72691 reportbuilder: Encode popup data inside report actions.
Browse files Browse the repository at this point in the history
Encode all popup data for report actions inside the action link
itself, because previously reloading a report via AJAX meant
actions no longer opened in popups, because the required JS was
absent from the page.
  • Loading branch information
lostrogit committed Oct 4, 2021
1 parent 1a9bee6 commit a9f45b0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion reportbuilder/amd/build/local/selectors.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reportbuilder/amd/build/local/selectors.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reportbuilder/amd/build/report.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reportbuilder/amd/build/report.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions reportbuilder/amd/src/local/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const SELECTORS = {
systemReport: '[data-region="core_reportbuilder/system-report"]',
filtersForm: '[data-region="filters-form"]',
},
actions: {
reportActionPopup: '[data-action="report-action-popup"]',
}
};

/**
Expand Down
11 changes: 11 additions & 0 deletions reportbuilder/amd/src/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ export const init = reportId => {
await setPageNumber(tableRoot, pageNumber, false)
.then(refreshTableContent);
});

// Listen for trigger popup events.
document.addEventListener('click', event => {
const reportActionPopup = event.target.closest(reportSelectors.actions.reportActionPopup);
if (reportActionPopup === null) {
return;
}
event.preventDefault();
const popupAction = JSON.parse(reportActionPopup.dataset.popupAction);
window.openpopup(event, popupAction.jsfunctionargs);
});
};
7 changes: 5 additions & 2 deletions reportbuilder/classes/local/report/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ public function get_action_link(stdClass $row): ?string {
self::replace_placeholders($this->url->params(), $row)
);

$popupaction = $this->popup ? new popup_action('click', $url) : null;
if ($this->popup) {
$this->attributes['data-action'] = 'report-action-popup';
$this->attributes['data-popup-action'] = json_encode(new popup_action('click', $url));
}

return $OUTPUT->action_icon($url, $this->icon, $popupaction, self::replace_placeholders($this->attributes, $row));
return $OUTPUT->action_icon($url, $this->icon, null, self::replace_placeholders($this->attributes, $row));
}

/**
Expand Down

0 comments on commit a9f45b0

Please sign in to comment.