From ac4c3a1e6f584c3cf37e956f49f113f3e45e40ce Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 28 Feb 2023 09:51:20 +0100 Subject: [PATCH] Bug 26967: Correctly format patron address in autocomplete We should use the JS function to format patron's address in the autocomplete result Test plan: Search for patron using the autocomplete feature, using the different values of addressformat. The address should be formatted correctly, like other places in Koha. You should also notice that the street number is now displayed. --- .../en/includes/js-patron-format-address.inc | 48 ++++++++++++------- .../prog/en/includes/js_includes.inc | 1 + .../prog/en/includes/patron-search.inc | 8 ++-- .../prog/js/patron-autocomplete.js | 5 +- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc index f72d28371b4..b561431c0ad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc @@ -11,7 +11,7 @@ return map; }, {}); - function member_display_address_style_us(data, line_break) { + function member_display_address_style_us(data, line_break, include_li) { let address = ""; if ( data.address || data.address2 ) { if ( data.address ) { @@ -19,14 +19,19 @@ if ( data.street_type ) { roadtype_desc = roadtypes_map[data.street_type] ? roadtypes_map[data.street_type].street_type : data.street_type; } - address += '
  • ' + escape_str(data.street_number) + ' ' + escape_str(data.address) + ' ' + escape_str(roadtype_desc) + '
  • '; + address += include_li ? '
  • ' : ''; + address += escape_str(data.street_number) + ' ' + escape_str(data.address) + ' ' + escape_str(roadtype_desc); + address += include_li ? '
  • ' : ''; } } if ( data.address2 ) { - address += '
  • ' + escape_str(data.address2) + '
  • ' + address += include_li ? '
  • ' : ' '; + address += escape_str(data.address2); + address += include_li ? '
  • ' : ''; } if ( data.city || data.postal_code || data.state || data.country ) { - address += '
  • ' + escape_str(data.city); + address += include_li ? '
  • ' : ' '; + address += escape_str(data.city); if ( data.state ) { if ( data.city ) { address += ', '; @@ -42,13 +47,13 @@ } address += escape_str(data.country) } - address += '
  • ' + address += include_li ? '' : ''; } return address; } - function member_display_address_style_de(data, line_break) { + function member_display_address_style_de(data, line_break, include_li) { let address = ""; if ( data.address || data.address2 ) { if ( data.address ) { @@ -56,24 +61,28 @@ if ( data.street_type ) { roadtype_desc = roadtypes_map[data.street_type] ? roadtypes_map[data.street_type].street_type : data.street_type; } - address += '
  • ' + escape_str(data.address) + ' ' + escape_str(roadtype_desc) + escape_str(data.street_number) + '
  • '; + address += include_li ? '
  • ' : ' '; + address += escape_str(data.address) + ' ' + escape_str(roadtype_desc) + escape_str(data.street_number); + address += include_li ? '
  • ' : ''; } } if ( data.address2 ) { - address += '
  • ' + escape_str(data.address2) + '
  • ' + address += include_li ? '
  • ' : ' '; + address += escape_str(data.address2); + address += include_li ? '
  • ' : ''; } if ( data.city || data.postal_code || data.state || data.country ) { - address += '
  • '; + address += include_li ? '
  • ' : ' '; address += escape_str(data.postal_code) + ' ' + escape_str(data.city); address += data.state ? line_break + escape_str(data.state) : ''; address += data.country ? line_break + escape_str(data.country) : ''; - address += '
  • ' + address += include_li ? '' : ''; } return address; } - function member_display_address_style_fr(data, line_break) { + function member_display_address_style_fr(data, line_break, include_li) { let address = ""; if ( data.address || data.address2 ) { if ( data.address ) { @@ -81,18 +90,22 @@ if ( data.street_type ) { roadtype_desc = roadtypes_map[data.street_type] ? roadtypes_map[data.street_type].street_type : data.street_type; } - address += '
  • ' + escape_str(data.street_number) + ' ' + escape_str(roadtype_desc) + escape_str(data.address) + '
  • '; + address += include_li ? '
  • ' : ''; + address += escape_str(data.street_number) + ' ' + escape_str(roadtype_desc) + escape_str(data.address); + address += include_li ? '
  • ' : ''; } } if ( data.address2 ) { - address += '
  • ' + escape_str(data.address2) + '
  • ' + address += include_li ? '
  • ' : ' '; + address += escape_str(data.address2); + address += include_li ? '
  • ' : ''; } if ( data.city || data.postal_code || data.state || data.country ) { - address += '
  • '; + address += include_li ? '
  • ' : ' '; address += escape_str(data.postal_code) + ' ' + escape_str(data.city); address += data.state ? line_break + escape_str(data.state) : ''; address += data.country ? line_break + escape_str(data.country) : ''; - address += '
  • ' + address += include_li ? '' : ''; } return address; @@ -100,10 +113,11 @@ window.$format_address = function(data, options) { let line_break = options && options.no_line_break ? ' ' : '
    '; + let include_li = options && options.include_li; [%~ IF Koha.Preference( 'AddressFormat' ) ~%] - return member_display_address_style_[% Koha.Preference( 'AddressFormat' ) | html %](data, line_break); + return member_display_address_style_[% Koha.Preference( 'AddressFormat' ) | html %](data, line_break, include_li); [%~ ELSE ~%] - return member_display_address_style_us(data, line_break); + return member_display_address_style_us(data, line_break, include_li); [%~ END ~%] } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc index 2d1af01c4f8..a2ba59bf31e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc @@ -28,6 +28,7 @@ [% Asset.js("js/staff-global.js") | $raw %] [% INCLUDE 'js-date-format.inc' %] [% INCLUDE 'js-patron-get-age.inc' %] +[% INCLUDE 'js-patron-format-address.inc' %] [% Asset.js("js/patron-autocomplete.js") | $raw %] [% INCLUDE 'validator-strings.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 4078ebf65ac..ec35d923356 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -438,7 +438,7 @@ "orderable": true, "render": function( data, type, row, meta ) { let r = '
    '; return r; } @@ -450,7 +450,7 @@ "orderable": true, "render": function( data, type, row, meta ) { let r = '
    '; r += " " + escape_str(libraries_map[row.library_id].branchname); return r; @@ -471,7 +471,7 @@ [% END %] r += '
    '; r += '