Bug 27029

Summary: Detail page missing Javascript accessible biblionumber value
Product: Koha Reporter: David Cook <dcook>
Component: OPACAssignee: David Cook <dcook>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: enhancement    
Priority: P5 - low CC: andrew, caroline.cyr-la-rose, fridolin.somers, koha, m.de.rooy, victor
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=26890
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.05.00,20.11.03,20.05.09
Circulation function:
Bug Depends on:    
Bug Blocks: 28021    
Attachments: Bug 27029: Add data-biblionumber attribute to OPAC detail page
Bug 27029: Add data-biblionumber attribute to OPAC detail page
Bug 27029: Add data-biblionumber attribute to OPAC detail page
Bug 27029: (QA follow-up) Adding html filter
Bug 27029: Add a selenium regression test

Description David Cook 2020-11-16 00:11:38 UTC
Bug 26890 raises the point that there's no biblionumber on the detail page that is easily Javascript accessible.

We really should be publishing the biblionumber in a feature-independent way, so that different features can leverage the same biblionumber. 

Here's my ideas so far:

1. data-biblionumber attribute in the body element
2. A RDFa schema.org identifier put in a child of the div.record element
3. Use Template::Toolkit to create a Javascript object that contains the biblionumber as a property
4. HTML element like "<span class="label">Catalogue ID</span>: <span id="biblionumber">1234</span>"

I'm actually kind of inclined towards #4, since I have occasionally had people ask for the biblionumber to be published on the HTML to make it easier to see and reference... (although more so for the Staff Interface than the OPAC admittedly)
Comment 1 David Cook 2020-11-16 00:26:43 UTC
Ok maybe not body as that would involve updating bodytag.inc, which is too far reaching. div#catalogue_detail_biblio would work though as follows:

<div id="catalogue_detail_biblio" class="maincontent" data-biblionumber="29">

Looks like the schema.org is partially in the XSLT and partially in opac-detail.tt so that's... no.
Comment 2 David Cook 2020-11-16 00:31:04 UTC
(In reply to David Cook from comment #1)
> <div id="catalogue_detail_biblio" class="maincontent" data-biblionumber="29">
> 

Then you can grab the biblionumber as easily as doing the following:

document.querySelector("div#catalogue_detail_biblio").dataset.biblionumber;

Or jquery:

$("div#catalogue_detail_biblio").attr("data-biblionumber");

$("div#catalogue_detail_biblio").data("biblionumber");
Comment 3 David Cook 2020-11-16 00:32:59 UTC
Created attachment 113648 [details] [review]
Bug 27029: Add data-biblionumber attribute to OPAC detail page

This patch adds a data-biblionumber attribute to the
div#catalogue_detail_biblio elements on opac-detail.pl, so that
Javascript running on the page can easily fetch and use the
record's biblionumber.
Comment 4 David Cook 2020-11-16 00:35:10 UTC
Note that this would be useful for Koha plugins or any OPACUserJS which wants to add functionality onto the OPAC detail page.
Comment 5 David Cook 2020-11-16 00:35:34 UTC
Adding myself as Assignee, but still curious what Owen Leonard thinks.
Comment 6 Mark Hofstetter 2020-11-16 07:19:42 UTC
Thx for the quick uptake on my idea/wish

I'll look into it, I'll try to make it today
Comment 7 Mark Hofstetter 2020-11-16 14:19:09 UTC
I tested this fix, what is the process to sign it off?
Comment 8 David Cook 2020-11-16 23:07:06 UTC
(In reply to Mark Hofstetter from comment #7)
> I tested this fix, what is the process to sign it off?

Thanks, Mark. 

You should be able to find everything you need here: https://wiki.koha-community.org/wiki/Git_bz_configuration#Signing_off

Since you've already marked it as Signed Off on Bugzilla, it basically boils down to adding a "Signed-off-by: Mark Hofstetter <koha@trust-box.at>" to the bottom of my patch and re-uploading to replace my original patch.
Comment 9 Mark Hofstetter 2020-11-17 12:18:41 UTC
Created attachment 113705 [details] [review]
Bug 27029: Add data-biblionumber attribute to OPAC detail page

This patch adds a data-biblionumber attribute to the
div#catalogue_detail_biblio elements on opac-detail.pl, so that
Javascript running on the page can easily fetch and use the
record's biblionumber.

Signed-off-by: Mark Hofstetter <mark@hofstetter.at>, <koha@trust-box.at>
Comment 10 David Cook 2020-11-17 22:42:01 UTC
Perfect, Mark!

If you go to https://dashboard.koha-community.org/, you'll also see that your name now appears in the list of sign offs as well.
Comment 11 Mark Hofstetter 2020-11-18 20:50:57 UTC
until the patch is in core you may use

    // "if" statment may/has to be removed when 
    // https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=27029
    // is in koha
    var biblionumber = $("div#catalogue_detail_biblio").data("biblionumber");
    if (!biblionumber) {
            var x = document.getElementsByClassName("unapi-id")[0]
                        .getAttribute("title");
            biblionumber = x.split(':')[2];
    }

see https://github.com/HKS3/koha-plugin-subordinate-items/
Comment 12 Marcel de Rooy 2021-01-22 10:59:47 UTC
Created attachment 115675 [details] [review]
Bug 27029: Add data-biblionumber attribute to OPAC detail page

This patch adds a data-biblionumber attribute to the
div#catalogue_detail_biblio elements on opac-detail.pl, so that
Javascript running on the page can easily fetch and use the
record's biblionumber.

Signed-off-by: Mark Hofstetter <mark@hofstetter.at>, <koha@trust-box.at>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 13 Marcel de Rooy 2021-01-22 10:59:50 UTC
Created attachment 115676 [details] [review]
Bug 27029: (QA follow-up) Adding html filter

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 14 Jonathan Druart 2021-01-27 10:36:04 UTC
Created attachment 115862 [details] [review]
Bug 27029: Add a selenium regression test
Comment 15 Jonathan Druart 2021-01-27 13:37:30 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 16 Fridolin Somers 2021-01-29 15:02:27 UTC
Nice small enhancement, I choose to backport.

Pushed to 20.11.x for 20.11.03
Comment 17 Andrew Fuerste-Henry 2021-02-04 21:57:46 UTC
Agreed, this seems small and handy. Pushed t0 20.05.x for 20.05.09
Comment 18 Victor Grousset/tuxayo 2021-02-09 22:16:22 UTC
Not backported to oldoldstable (19.11.x). Feel free to ask if it's needed.