Bug 25288: (QA follow-up) Escape data and restore empty list behaviour

After the QA round on bug 25279, some things needed to get fixed:
- Data needs to be escaped
- When no library is defined, we should keep the original behaviour and
  message.
- aria-hidden="true" for FontAwesome coding guideline enforced
- Added role="button" as well.

This patch does that.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2020-05-06 18:50:29 -03:00 committed by Jonathan Druart
parent dd0c207f53
commit d1a8c3fcfe
2 changed files with 47 additions and 30 deletions

View file

@ -147,6 +147,9 @@ if ( $op eq 'add_form' ) {
$op = 'list'; $op = 'list';
} }
$template->param( libraries_count => Koha::Libraries->search->count )
if $op eq 'list';
$template->param( $template->param(
messages => \@messages, messages => \@messages,
op => $op, op => $op,

View file

@ -183,19 +183,23 @@
[% IF op == 'list' %] [% IF op == 'list' %]
<h3>Libraries</h3> <h3>Libraries</h3>
<table id="libraries"> [% IF libraries_count > 0 %]
<thead> <table id="libraries">
<tr> <thead>
<th>Name</th> <tr>
<th>Code</th> <th>Name</th>
<th>Address</th> <th>Code</th>
<th>MARC organization code</th> <th>Address</th>
<th>IP</th> <th>MARC organization code</th>
<th>Pickup location</th> <th>IP</th>
<th>Actions</th> <th>Pickup location</th>
</tr> <th data-class-name="actions">Actions</th>
</thead> </tr>
</table> </thead>
</table>
[% ELSE %]
<div class="dialog message">There are no libraries defined. <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">Start defining libraries</a>.</div>
[% END %]
[% END %] [% END %]
</main> </main>
@ -218,13 +222,23 @@
var columns_settings = [% ColumnsSettings.GetColumns( 'admin', 'libraries', 'libraries', 'json' ) | $raw %]; var columns_settings = [% ColumnsSettings.GetColumns( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
$(document).ready(function() { $(document).ready(function() {
const to_html = (x) => $('<div/>').text(x).html();
var libraries_url = '/api/v1/libraries'; var libraries_url = '/api/v1/libraries';
var libraries = $("#libraries").api({ var libraries = $("#libraries").api({
"ajax": { "ajax": {
"url": libraries_url "url": libraries_url
}, },
'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
'emptyTable': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>', 'emptyTable': '<div class="dialog message">'+_("There are no libraries defined.")+' <a href="/cgi-bin/koha/admin/branches.pl?op=add_form">'+_("Start defining libraries")+'</a>.</div>',
"columnDefs": [ {
"targets": [0,1,3,4,7,8,9,10,11,12,13,14,15],
"render": function (data, type, row, meta) {
if ( type == 'display' ) {
return to_html(data);
}
return data;
}
} ],
"columns": [ "columns": [
{ {
"data": "name", "data": "name",
@ -239,27 +253,27 @@
{ {
"data": function( row, type, val, meta ) { "data": function( row, type, val, meta ) {
const library_info = []; const library_info = [];
if ( row.address1 != null ) library_info.push(row.address1); if ( row.address1 != null ) library_info.push(to_html(row.address1));
if ( row.address2 != null ) library_info.push(row.address2); if ( row.address2 != null ) library_info.push(to_html(row.address2));
if ( row.address3 != null ) library_info.push(row.address3); if ( row.address3 != null ) library_info.push(to_html(row.address3));
// geographical_location = city, state postal_code // geographical_location = city, state postal_code
const locations = []; const locations = [];
if ( row.city != null ) locations.push(row.city); if ( row.city != null ) locations.push(to_html(row.city));
if ( row.state != null ) locations.push(row.state); if ( row.state != null ) locations.push(to_html(row.state));
const geographical_location = locations.join(', '); const geographical_location = locations.join(', ');
if ( geographical_location != '' && row.postal_code != null) { if ( geographical_location != '' && row.postal_code != null) {
library_info.push(geographical_location+' '+row.postal_code); library_info.push(geographical_location+' '+to_html(row.postal_code));
} }
else { else {
library_info.push(geographical_location); library_info.push(geographical_location);
} }
if ( row.country != null ) library_info.push(row.country); if ( row.country != null ) library_info.push(to_html(row.country));
if ( row.phone != null ) library_info.push(_("Ph: ") + row.phone); if ( row.phone != null ) library_info.push(_("Ph: ") + to_html(row.phone));
if ( row.fax != null ) library_info.push(_("Fax: ") + row.fax); if ( row.fax != null ) library_info.push(_("Fax: ") + to_html(row.fax));
if ( row.email != null ) library_info.push('<a href="mailto:'+row.email+'">'+row.email+'</a>'); if ( row.email != null ) library_info.push('<a href="mailto:'+encodeURIComponent(row.email)+'">'+to_html(row.email)+'</a>');
if ( row.url != null ) library_info.push('<a href="'+row.url+'">'+row.url+'</a>'); if ( row.url != null ) library_info.push('<a href="'+encodeURIComponent(row.url)+'">'+to_html(row.url)+'</a>');
if ( row.opac_info != null ) library_info.push(_("OPAC Info") + ': <div>'+row.opac_info+'</div>'); if ( row.opac_info != null ) library_info.push(_("OPAC Info") + ': <div>'+to_html(row.opac_info)+'</div>');
if ( row.notes != null ) library_info.push(_("Notes")+': '+row.notes); if ( row.notes != null ) library_info.push(_("Notes")+': '+to_html(row.notes));
return library_info.join('<br/>'); return library_info.join('<br/>');
}, },
"searchable": false, "searchable": false,
@ -286,11 +300,11 @@
{ {
"data": function( row, type, val, meta ) { "data": function( row, type, val, meta ) {
var result = '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?op=add_form&amp;branchcode='+row.library_id+'"><i class="fa fa-pencil"></i> '+_("Edit")+'</a>'; var result = '<a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/branches.pl?op=add_form&amp;branchcode='+encodeURIComponent(row.library_id)+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>';
result += '<form action="/cgi-bin/koha/admin/branches.pl" method="post">'; result += '<form action="/cgi-bin/koha/admin/branches.pl" method="post">';
result += '<input type="hidden" name="branchcode" value="'+row.library_id+'" />'; result += '<input type="hidden" name="branchcode" value="'+to_html(row.library_id)+'" />'+"\n";
result += '<input type="hidden" name="op" value="delete_confirm" />'; result += '<input type="hidden" name="op" value="delete_confirm" />';
result += '<button type="submit" id="delete_library_'+row.library_id+'" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> '+_("Delete")+'</button></form>'; result += '<button type="submit" id="delete_library_'+to_html(row.library_id)+'" class="btn btn-default btn-xs" role="button"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</button></form>';
return result; return result;