Index: openacs-4/packages/acs-subsite/www/resources/core.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/www/resources/core.js,v diff -u -r1.17.2.5 -r1.17.2.6 --- openacs-4/packages/acs-subsite/www/resources/core.js 8 Oct 2022 19:50:02 -0000 1.17.2.5 +++ openacs-4/packages/acs-subsite/www/resources/core.js 7 Aug 2023 14:53:57 -0000 1.17.2.6 @@ -155,13 +155,59 @@ } function acs_ListBulkActionClick(formName, url) { - if (document.forms == null) return; - if (document.forms[formName] == null) return; + const form = document.querySelector('form[name=' + formName + ']'); + if (!form) { + return; + } - var form = document.forms[formName]; + // + // Sometimes is convenient to have a single page serving the + // purpose of multiple bulk-actions, for instance + // "do-bulk-stuff?action=1" and "do-bulk-stuff?action=2". + // + // To do so, we parse the URL searching for query parameters. If + // there are, we inject them into the bulk-actions form together + // with the rest of the request. + // + // Note that the variables specified this way have total + // precedence and will override those specified differently. + // - form.action = url; - form.submit(); + // + // Parse the URL + // + const queryString = url.split('?')[1]; + const searchParams = new window.URLSearchParams(queryString); + + // + // Cleanup pre-existing variable conflicting with the URL ones + // + for (const [name, value] of searchParams) { + for (const e of form.querySelectorAll('[name=' + name + ']')) { + form.removeChild(e); + } + } + + // + // Inject the variables in the form. + // + // Note that most browsers now support the "formdata" event, that + // can be use to manipulate the FormData object directly on the + // form before this is submitted. However, Safari only introduced + // support for it in 2021, so we resort to this method. + // + // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/formdata_event + // + for (const [name, value] of searchParams) { + const i = document.createElement('input'); + i.setAttribute('type', 'hidden'); + i.setAttribute('name', name); + i.value = value; + form.appendChild(i); + } + + form.action = url; + form.submit(); } //