diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
index cdf73a5b86..6c6ef20c66 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
@@ -656,10 +656,11 @@
var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
+ var libraries_table;
$(document).ready(function() {
var libraries_url = '/api/v1/libraries';
- var libraries = $("#libraries").kohaTable({
+ libraries_table = $("#libraries").kohaTable({
"ajax": {
"url": libraries_url
},
diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js
index 3154a6afdf..084cb8c82c 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js
@@ -595,6 +595,20 @@ function _dt_default_ajax (params){
}
}
+function build_url_with_state(dt, table_settings){
+ let table_key = 'DataTables_%s_%s_%s'.format(
+ table_settings.module,
+ table_settings.page,
+ table_settings.table);
+
+ let state = JSON.stringify(dt.state());
+ delete state.time;
+ let searchParams = new URLSearchParams(window.location.search);
+ searchParams.set(table_key + '_state', btoa(state));
+
+ return window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash;
+}
+
function _dt_buttons(params){
let settings = params.settings || {};
let table_settings = params.table_settings;
@@ -740,17 +754,8 @@ function _dt_buttons(params){
titleAttr: __("Copy shareable link"),
text: ' ' + __("Copy shareable link") + '',
action: function (e, dt, node, config) {
- let table_key = 'DataTables_%s_%s_%s'.format(
- table_settings.module,
- table_settings.page,
- table_settings.table);
+ const url = build_url_with_state(dt, table_settings);
- let state = JSON.stringify(dt.state());
- delete state.time;
- let searchParams = new URLSearchParams(window.location.search);
- searchParams.set(table_key + '_state', btoa(state));
-
- let url = window.location.origin + window.location.pathname + '?' + searchParams.toString() + window.location.hash;
if( navigator.clipboard && navigator.clipboard.writeText){
writeToClipboard(url, node);
}
diff --git a/t/cypress/integration/KohaTable_spec.ts b/t/cypress/integration/KohaTable_spec.ts
index a9b973be66..6803edf9fa 100644
--- a/t/cypress/integration/KohaTable_spec.ts
+++ b/t/cypress/integration/KohaTable_spec.ts
@@ -264,65 +264,53 @@ describe("kohaTable (using REST API)", () => {
);
cy.get(`#${table_id} th`).contains("Name");
cy.get(`#${table_id} th`).contains("Code");
-
- // Close the 'Columns' list
- cy.get(".dt-button-background").click();
- cy.get(".dt-button-background").should("not.exist");
- cy.wait(500); // ensure the animation completes, random failures?
-
- // Copy the shareable link (Name and Code shown)
- cy.window().focus();
- cy.get(
- `#${table_id}_wrapper .copyConditions_controls`
- ).click({ force: true });
- cy.get(".tooltip").contains("Copied!");
});
cy.window().then(win => {
- // Retrieve the content of the clipboard
- win.navigator.clipboard.readText().then(url => {
- expect(url).to.match(
- /branches.pl\?DataTables_admin_libraries_libraries_state=/
+ // Copy the shareable link (Name and Code shown)
+ const url = win.build_url_with_state(
+ win.libraries_table.DataTable(),
+ win.table_settings
+ );
+ expect(url).to.match(
+ /branches.pl\?DataTables_admin_libraries_libraries_state=/
+ );
+
+ // Remove localStorage
+ win.localStorage.clear();
+
+ // Use it
+ cy.visit(url);
+
+ // Code is shown whereas it is hidden in the config
+ cy.get("@columns").then(columns => {
+ cy.get(`#${table_id} th`).should(
+ "have.length",
+ columns.length
+ );
+ cy.get(`#${table_id} th`).contains("Name");
+ cy.get(`#${table_id} th`).contains("Code");
+
+ // Hide "Name"
+ cy.get(`#${table_id}_wrapper .buttons-colvis`).click();
+ cy.get(`#${table_id}_wrapper .dt-button-collection`)
+ .contains("Name")
+ .click();
+ });
+
+ // Go to the shareable link
+ // but do not remove localStorage!
+ cy.visit(url);
+
+ // Name is hidden and Code is shown
+ cy.get("@columns").then(columns => {
+ cy.get(`#${table_id} th`).should(
+ "have.length",
+ columns.length
);
- // Remove localStorage
- win.localStorage.clear();
-
- // Use it
- cy.visit(url);
-
- // Code is shown whereas it is hidden in the config
- cy.get("@columns").then(columns => {
- cy.get(`#${table_id} th`).should(
- "have.length",
- columns.length
- );
- cy.get(`#${table_id} th`).contains("Name");
- cy.get(`#${table_id} th`).contains("Code");
-
- // Hide "Name"
- cy.get(
- `#${table_id}_wrapper .buttons-colvis`
- ).click();
- cy.get(`#${table_id}_wrapper .dt-button-collection`)
- .contains("Name")
- .click();
- });
-
- // Go to the shareable link
- // but do not remove localStorage!
- cy.visit(url);
-
- // Name is hidden and Code is shown
- cy.get("@columns").then(columns => {
- cy.get(`#${table_id} th`).should(
- "have.length",
- columns.length
- );
-
- cy.get(`#${table_id} th`).contains("Name");
- cy.get(`#${table_id} th`).contains("Code");
- });
+ cy.get(`#${table_id} th`).contains("Name");
+ cy.get(`#${table_id} th`).contains("Code");
});
});
});