Koha/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc
Martin Renvoize 29e3d3d7fe Bug 29575: (QA follow-up) Patron fields can be empty strings
We need to account for empty strings as well as 'null' values in the
patron data structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2021-12-16 12:13:51 -10:00

53 lines
2 KiB
PHP

<!-- js-patron-title.inc -->
<script>
(function() {
/**
* Format the patron response from a Koha RESTful API request.
* @param {Object} patron The patron json object as returned from the Koha RESTful API
* @param {Object} config A configuration object
* Valid keys are: `invert_name`, `display_cardnumber` and `url`
* @return {string} The formatted HTML string
*/
window.$patron_to_html = function( patron, config ) {
if ( patron === undefined ) {
return ''; // empty string for no patron
}
var title = null;
if ( patron.title != null && patron.title != '' ) {
title = '<span class="patron-title">' + escape_str(patron.title) + '</span>';
}
var name;
var firstname = escape_str(patron.firstname);
var surname = escape_str(patron.surname);
if ( patron.other_name != null && patron.other_name != '' ) {
firstname += ' (' + escape_str(patron.other_name) + ')';
}
if ( config && config.invert_name ) {
name = surname + ', ' + firstname;
}
else {
name = firstname + ' ' + surname;
}
if ( config && config.display_cardnumber ) {
name = name + ' (' + escape_str(patron.cardnumber) + ')';
}
if (config && config.url) {
if ( config.url === 'circulation_reserves' ) {
name = '<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber='+ encodeURIComponent(patron.patron_id) +'#reserves">' + name + '</a>';
}
else {
name = '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='+ encodeURIComponent(patron.patron_id) +'">' + name + '</a>';
}
}
return name;
};
})();
</script>
<!-- / js-patron-title.inc -->