Koha/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format.inc
Martin Renvoize 744ac4825b
Bug 33504: Update patron_to_html to deal with null
In the patron_to_html function we were dealing explicitly with the case
where patron may be passed undefined, but forgetting that it may be
returned as 'null' from the api too.  Changing from `( patron ===
undefined )` to `( patron == null )` is the recommended approach for
detecting 'undefined or null' in javascript.

Signed-off-by: Magnus Enger <magnus@libriotech.no>
Works as advertised. Martin's test plan from Bugzilla:

To test.
1) Use ILS-DI to renew an checkout
2) View the circulation history for the item
3) Click the 'View' button next to the count of renewals
4) Note that the modal just stalls at 'Retrieving renewals'
5) Apply the patch
6) Now the 'retrieving renewals' message should list the renewals instead.

Note that step 2 should be something like "Go to the "Circulation
history" of the patron.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-05-05 09:13:20 -03:00

55 lines
2.1 KiB
PHP

<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 == null ) {
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.middle_name != null && patron.middle_name != '' ) {
firstname += ' ' + escape_str(patron.middle_name);
}
if ( patron.other_name != null && patron.other_name != '' ) {
firstname += ' (' + escape_str(patron.other_name) + ')';
}
if ( config && config.invert_name ) {
name = surname + ( firstname ? ', ' + 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>