4 * Format the patron response from a Koha RESTful API request.
5 * @param {Object} patron The patron json object as returned from the Koha RESTful API
6 * @param {Object} config A configuration object
7 * Valid keys are: `invert_name`, `display_cardnumber` and `url`
8 * @return {string} The formatted HTML string
10 window.$patron_to_html = function( patron, config ) {
12 if ( patron === undefined ) {
13 return ''; // empty string for no patron
17 if ( patron.title != null && patron.title != '' ) {
18 title = '<span class="patron-title">' + escape_str(patron.title) + '</span>';
22 var firstname = escape_str(patron.firstname);
23 var surname = escape_str(patron.surname);
25 if ( patron.other_name != null && patron.other_name != '' ) {
26 firstname += ' (' + escape_str(patron.other_name) + ')';
28 if ( config && config.invert_name ) {
29 name = surname + ( firstname ? ', ' + firstname : '' );
32 name = firstname + ' ' + surname;
35 if ( config && config.display_cardnumber ) {
36 name = name + ' (' + escape_str(patron.cardnumber) + ')';
39 if (config && config.url) {
40 if ( config.url === 'circulation_reserves' ) {
41 name = '<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber='+ encodeURIComponent(patron.patron_id) +'#reserves">' + name + '</a>';
44 name = '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='+ encodeURIComponent(patron.patron_id) +'">' + name + '</a>';