Line 0
Link Here
|
|
|
1 |
<script> |
2 |
(function() { |
3 |
/** |
4 |
* Format the biblio response from a Koha RESTful API request. |
5 |
* @param {Object} biblio The biblio json object as returned from the Koha RESTful API |
6 |
* @param {Object} config A configuration object |
7 |
* Valid keys are: `link` |
8 |
* @return {string} The formatted HTML string |
9 |
*/ |
10 |
window.$biblio_to_html = function(biblio, config) { |
11 |
|
12 |
if (biblio === undefined) { |
13 |
return ''; // empty string for no biblio |
14 |
} |
15 |
|
16 |
var title = '<span class="biblio-title">'; |
17 |
if (biblio.title != null && biblio.title != '') { |
18 |
title += escape_str(biblio.title); |
19 |
} else { |
20 |
title += __("No title"); |
21 |
} |
22 |
title += '</span>'; |
23 |
|
24 |
// add subtitle |
25 |
if (biblio.subtitle != null && biblio.subtitle != '') { |
26 |
title += ' <span class="biblio-subtitle">' + escape_str(biblio.subtitle) + '</span>'; |
27 |
} |
28 |
|
29 |
// set title as link |
30 |
if (config && config.link) { |
31 |
if (config.link === 'marcdetail') { |
32 |
title = '<a href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; |
33 |
} else if (config.link === 'labeled_marc') { |
34 |
title = '<a href="/cgi-bin/koha/opac-labeledMARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; |
35 |
} else if (config.link === 'isbd') { |
36 |
title = '<a href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; |
37 |
} else { |
38 |
title = '<a href="/cgi-bin/koha/opac-detail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; |
39 |
} |
40 |
} |
41 |
|
42 |
// add medium |
43 |
if (biblio.medium != null && biblio.medium != '') { |
44 |
title += ' <span class="biblio-medium">' + escape_str(biblio.medium) + '</span>'; |
45 |
} |
46 |
|
47 |
// add part numbers/names |
48 |
let part_numbers = (typeof biblio.part_number === 'string') ? biblio.part_number.split("|") : []; |
49 |
let part_names = (typeof biblio.part_name === 'string') ? biblio.part_name.split("|") : []; |
50 |
let i = 0; |
51 |
while (part_numbers[i] || part_names[i]) { |
52 |
if (part_numbers[i]) { |
53 |
title += ' <span class="part-number">' + escape_str(part_numbers[i]) + '</span>'; |
54 |
} |
55 |
if (part_names[i]) { |
56 |
title += ' <span class="part-name">' + escape_str(part_names[i]) + '</span>'; |
57 |
} |
58 |
i++; |
59 |
} |
60 |
|
61 |
return title; |
62 |
}; |
63 |
})(); |
64 |
</script> |