Bug 28854: (follow-up) Add handling for part_numbers/names

This patch adds part number/name handling to the new biblio-format js
include. This will add such details to bundle management tables.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2022-06-27 16:36:09 +01:00 committed by Tomas Cohen Arazi
parent 0938a735de
commit 4eda276c18
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -1,47 +1,61 @@
<script>
(function() {
/**
* Format the biblio response from a Koha RESTful API request.
* @param {Object} biblio The biblio json object as returned from the Koha RESTful API
* @param {Object} config A configuration object
* Valid keys are: `link`
* @return {string} The formatted HTML string
*/
window.$biblio_to_html = function( biblio, config ) {
* Format the biblio response from a Koha RESTful API request.
* @param {Object} biblio The biblio json object as returned from the Koha RESTful API
* @param {Object} config A configuration object
* Valid keys are: `link`
* @return {string} The formatted HTML string
*/
window.$biblio_to_html = function(biblio, config) {
if ( biblio === undefined ) {
if (biblio === undefined) {
return ''; // empty string for no biblio
}
var title = '<span class="biblio-title">';
if ( biblio.title != null && biblio.title != '' ) {
if (biblio.title != null && biblio.title != '') {
title += escape_str(biblio.title);
} else {
title += __("No title");
}
title += '</span>';
if ( biblio.subtitle != null && biblio.subtitle != '' ) {
title += '<span clas="biblio-subtitle">' + escape_str(biblio.subtitle) + '</span>';
// add subtitle
if (biblio.subtitle != null && biblio.subtitle != '') {
title += '<span class="biblio-subtitle">' + escape_str(biblio.subtitle) + '</span>';
}
// set title as link
if (config && config.link) {
if ( config.link === 'marcdetail' ) {
title = '<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber='+ encodeURIComponent(biblio.biblio_id) +'">' + title + '</a>';
}
else if ( config.link === 'labeled_marc') {
title = '<a href="/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber='+ encodeURIComponent(biblio.biblio_id) +'">' + title + '</a>';
}
else if ( config.link === 'isbd' ) {
title = '<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber='+ encodeURIComponent(biblio.biblio_id) +'">' + title + '</a>';
}
else {
title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber='+ encodeURIComponent(biblio.biblio_id) +'">' + title + '</a>';
if (config.link === 'marcdetail') {
title = '<a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>';
} else if (config.link === 'labeled_marc') {
title = '<a href="/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>';
} else if (config.link === 'isbd') {
title = '<a href="/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>';
} else {
title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>';
}
}
if ( biblio.medium != null && biblio.medium != '' ) {
title += '<span class="biblio-medium">'+escape_str(biblio.medium)+'</span>';
// add medium
if (biblio.medium != null && biblio.medium != '') {
title += '<span class="biblio-medium">' + escape_str(biblio.medium) + '</span>';
}
// add part numbers/names
let part_numbers = (typeof biblio.part_number === 'string') ? biblio.part_number.split("|") : [];
let part_names = (typeof biblio.part_name === 'string') ? biblio.part_name.split("|") : [];
let i = 0;
while (part_numbers[i] || part_names[i]) {
if (part_numbers[i]) {
title += '<span class="part-number">' + escape_str(part_numbers[i]) + '</span>';
}
if (part_names[i]) {
title += '<span class="part-name">' + escape_str(part_name[i]) + '</span>';
}
i++;
}
return title;