From 690287bd3160f378c3ce26747437d00f8c7f6c3b 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. Signed-off-by: Christopher Brannon --- .../en/includes/js-patron-format-address.inc | 46 ++++++++++++------- .../prog/en/includes/js_includes.inc | 1 + .../prog/en/includes/patron-search.inc | 8 ++-- .../prog/js/patron-autocomplete.js | 5 +- 4 files changed, 36 insertions(+), 24 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 f72d28371b..2fe4451816 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,18 +61,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.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 ? '
  • ' : ''; + 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; @@ -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 2d1af01c4f..a2ba59bf31 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 4078ebf65a..ec35d92335 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 = '
      '; - r += $format_address(row, { no_line_break: 1 }); + r += $format_address(row, { no_line_break: true, include_li: true }); r += '
    '; return r; } @@ -450,7 +450,7 @@ "orderable": true, "render": function( data, type, row, meta ) { let r = '
      '; - r += $format_address(row, { no_line_break: 1 }); + r += $format_address(row, { no_line_break: true, include_li: true }); r += '
    '; r += " " + escape_str(libraries_map[row.library_id].branchname); return r; @@ -471,7 +471,7 @@ [% END %] r += '
    '; r += '
      '; - r += $format_address(row, { no_line_break: 1 }); + r += $format_address(row, { no_line_break: true, include_li: true }); if ( row.email ) { r += "
    • " + _("Email: ") + "" + escape_str(row.email) + "
    • "; @@ -496,7 +496,7 @@ [% END %] r += '
      '; r += '
        '; - r += $format_address(row, { no_line_break: 1 }); + r += $format_address(row, { no_line_break: true, include_li: true }); if ( row.email ) { r += "
      • " + _("Email: ") + "" + escape_str(row.email) + "
      • "; diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js index 49ff14f84b..cc8ec068ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -106,10 +106,7 @@ function patron_autocomplete(node, options) { + ")," : "" ) + " " - + ( item.address ? item.address.escapeHtml() : "" ) + " " - + ( item.city ? item.city.escapeHtml() : "" ) + " " - + ( item.zipcode ? item.zipcode.escapeHtml() : "" ) + " " - + ( item.country ? item.country.escapeHtml() : "" ) + " " + + $format_address(item, { no_line_break: true, include_li: false }) + " " + ( !singleBranchMode ? "" -- 2.30.2