Line 0
Link Here
|
0 |
- |
1 |
(function () { |
|
|
2 |
/** |
3 |
* Format the patron response from a Koha RESTful API request. |
4 |
* @param {Object} patron The patron json object as returned from the Koha RESTful API |
5 |
* @param {Object} config A configuration object |
6 |
* Valid keys are: `invert_name`, `display_cardnumber` and `url` |
7 |
* @return {string} The formatted HTML string |
8 |
*/ |
9 |
window.$patron_to_html = function (patron, config) { |
10 |
if (patron == null) { |
11 |
return ""; // empty string for no patron |
12 |
} |
13 |
|
14 |
var title = null; |
15 |
if (patron.title != null && patron.title != "") { |
16 |
title = |
17 |
'<span class="patron-title">' + |
18 |
escape_str(patron.title) + |
19 |
"</span>"; |
20 |
} |
21 |
|
22 |
var name; |
23 |
var firstname = escape_str(patron.firstname); |
24 |
var preferred_name = escape_str(patron.preferred_name); |
25 |
var surname = escape_str(patron.surname); |
26 |
|
27 |
if (patron.middle_name != null && patron.middle_name != "") { |
28 |
firstname += " " + escape_str(patron.middle_name); |
29 |
preferred_name += " " + escape_str(patron.middle_name); |
30 |
} |
31 |
|
32 |
if (patron.other_name != null && patron.other_name != "") { |
33 |
firstname += " (" + escape_str(patron.other_name) + ")"; |
34 |
preferred_name += " (" + escape_str(patron.other_name) + ")"; |
35 |
} |
36 |
if (config && config.invert_name) { |
37 |
name = surname + (preferred_name ? ", " + preferred_name : ""); |
38 |
} else { |
39 |
name = preferred_name + " " + surname; |
40 |
} |
41 |
if (name.replace(" ", "").length == 0) { |
42 |
if (patron.library) { |
43 |
return _("A patron from %s").format(patron.library.name); |
44 |
} else { |
45 |
return _("A patron from another library"); |
46 |
} |
47 |
} |
48 |
|
49 |
if (config && config.hide_patron_name) { |
50 |
name = ""; |
51 |
} |
52 |
|
53 |
if (config && config.display_cardnumber) { |
54 |
if (name.length > 0) { |
55 |
name = name + " (" + escape_str(patron.cardnumber) + ")"; |
56 |
} else { |
57 |
name = escape_str(patron.cardnumber); |
58 |
} |
59 |
} |
60 |
|
61 |
if (config && config.url) { |
62 |
if (config.url === "circulation_reserves") { |
63 |
name = |
64 |
'<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=' + |
65 |
encodeURIComponent(patron.patron_id) + |
66 |
'#reserves">' + |
67 |
name + |
68 |
"</a>"; |
69 |
} else { |
70 |
name = |
71 |
'<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + |
72 |
encodeURIComponent(patron.patron_id) + |
73 |
'">' + |
74 |
name + |
75 |
"</a>"; |
76 |
} |
77 |
} |
78 |
|
79 |
return name; |
80 |
}; |
81 |
})(); |