Bug 27930: Move _escape_* from acqui/parcel.tt to js/staff-global.js

This patch moves the _escape_str and _escape_price functions into the
staff-global.js include

Test plan
1/ The acquisitions parcel page should look the same before and after
the patch.
2/ Signoff

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2021-03-11 14:22:54 +00:00 committed by Jonathan Druart
parent 3c65a3cdfe
commit 68c37861c0
2 changed files with 31 additions and 32 deletions

View file

@ -333,13 +333,6 @@
dt_overwrite_html_sorting_localeCompare();
var columns_filter = {};
function _escape_str(s){
return s != null ? s.escapeHtml() : "";
}
function _escape_price(p){
return p != null ? p.escapeHtml().format_price() : "";
}
$(document).ready(function(){
if ( $("#receivedt").length ) {
@ -400,15 +393,15 @@
"searchable": true,
"orderable": true,
"render": function(data, type, row, meta) {
if (type != 'display') return _escape_str(data);
return "<a href=\"/cgi-bin/koha/acqui/basket.pl?basketno=" + encodeURIComponent(row.basket.basket_id) + "\">" + _escape_str(data) + " (" + _escape_str(row.basket.basket_id) + ")</a>";
if (type != 'display') return escape_str(data);
return "<a href=\"/cgi-bin/koha/acqui/basket.pl?basketno=" + encodeURIComponent(row.basket.basket_id) + "\">" + escape_str(data) + " (" + escape_str(row.basket.basket_id) + ")</a>";
}
},
{ "data": "basket.basket_group.name",
"orderable": true,
"render": function(data, type, row, meta) {
if ( type != 'display' ) {
return _escape_str(data);
return escape_str(data);
}
if ( row.basket.basket_group_id == null ) {
return _("No basket group");
@ -417,15 +410,15 @@
return "<a href=\"/cgi-bin/koha/acqui/basketgroup.pl?op=add&amp;booksellerid="
+ encodeURIComponent(row.basket.vendor_id) + "&amp;basketgroupid="
+ encodeURIComponent(row.basket.basket_group_id) + "\">"
+ _escape_str(row.basket.basket_group.name) + " (" + _escape_str(row.basket.basket_group_id) + ")</a>";
+ escape_str(row.basket.basket_group.name) + " (" + escape_str(row.basket.basket_group_id) + ")</a>";
}
}
},
{
"data": "order_id",
"render": function(data, type, row, meta) {
if (type != 'display') return _escape_str(data);
return "<a href=\"neworderempty.pl?ordernumber="+encodeURIComponent(data)+"&amp;booksellerid="+encodeURIComponent(row.basket.vendor_id)+"\">"+_escape_str(data)+"</a>";
if (type != 'display') return escape_str(data);
return "<a href=\"neworderempty.pl?ordernumber="+encodeURIComponent(data)+"&amp;booksellerid="+encodeURIComponent(row.basket.vendor_id)+"\">"+escape_str(data)+"</a>";
}
},
{
@ -435,22 +428,22 @@
"render": function(data, type, row, meta) {
var result = '';
if ( row && row.biblio_id != null ) {
result = "<p><a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber="+encodeURIComponent(row.biblio_id)+"\">"+_escape_str(row.biblio.title)+"</a>";
result = "<p><a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber="+encodeURIComponent(row.biblio_id)+"\">"+escape_str(row.biblio.title)+"</a>";
if ( row.biblio.author != null )
result += _(" by ") + _escape_str(row.biblio.author);
result += _(" by ") + escape_str(row.biblio.author);
if ( row.biblio.isbn != null )
result += " &ndash; " + _escape_str(row.biblio.isbn);
result += " &ndash; " + escape_str(row.biblio.isbn);
[% IF Koha.Preference('marcflavour')=='UNIMARC' %]
if ( row.biblio.ean != null )
result += " &ndash; EAN:" + _escape_str(row.biblio.ean);
result += " &ndash; EAN:" + escape_str(row.biblio.ean);
[% END %]
if ( row.biblio.publisher != null ) {
result += "<br/>" + _("Publisher: ") + _escape_str(row.biblio.publisher);
result += "<br/>" + _("Publisher: ") + escape_str(row.biblio.publisher);
if ( row.biblio.publication_year != null ) {
result += ", " + _escape_str(row.biblio.publication_year);
result += ", " + escape_str(row.biblio.publication_year);
}
else if ( row.biblio.copyright_date != null ) {
result += _escape_str(row.biblio.copyright_date);
result += escape_str(row.biblio.copyright_date);
}
}
var suggestions = row.biblio.suggestions;
@ -460,10 +453,10 @@
var suggester = suggestion.suggester;
var suggested_by = [];
if ( suggester.surname != null ) {
suggested_by.push(_escape_str(suggester.surname));
suggested_by.push(escape_str(suggester.surname));
}
if ( suggester.firstname != null ) {
suggested_by.push(_escape_str(suggester.firstname));
suggested_by.push(escape_str(suggester.firstname));
}
result += "<br/>" + _("Suggested by: ") +
@ -471,7 +464,7 @@
+ encodeURIComponent(suggestion.suggestionid)
+ '&amp;op=show">'
+ suggested_by.join(", ")
+ " (#" + _escape_str(suggestions[0].suggestionid) + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
+ " (#" + escape_str(suggestions[0].suggestionid) + ")</a>"; // FIXME: could be changed if we allow matching multiple suggestions
}
}
result += '</p>';
@ -481,7 +474,7 @@
if ( internal_note != null && internal_note != '' ) {
result += '<p class="ordernote"><strong>'
+ _("Internal note: ")
+ '</strong>' + _escape_str(internal_note)
+ '</strong>' + escape_str(internal_note)
+ ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
+ encodeURIComponent(row.order_id) + '&amp;referrer=/cgi-bin/koha/acqui/parcel.pl%3Finvoiceid=[% invoiceid | uri %]'
+ '&type=internal">' + _("Change internal note") + '</a>]</p>';
@ -496,7 +489,7 @@
if ( vendor_note != null && vendor_note != '' ) {
result += '<p class="ordernote"><strong>'
+ _("Vendor note: ")
+ '</strong>' + _escape_str(vendor_note) + '</p>';
+ '</strong>' + escape_str(vendor_note) + '</p>';
}
else {
result += ' [<a href="/cgi-bin/koha/acqui/modordernotes.pl?ordernumber='
@ -522,7 +515,7 @@
{
"data": "replacement_price",
"render": function(data, type, row, meta) {
return _escape_price(row.replacement_price);
return escape_price(row.replacement_price);
},
},
{
@ -532,13 +525,13 @@
{
"data": "ecost",
"render": function(data, type, row, meta) {
return _escape_price(row.ecost);
return escape_price(row.ecost);
},
},
{
"data": "",
"render": function(data, type, row, meta) {
return _escape_price(row.quantity * row.ecost);
return escape_price(row.quantity * row.ecost);
},
"orderable": false, // FIXME: How can we do it in DBIC?
"searchable": false
@ -546,8 +539,8 @@
{
"data": "fund.name",
"render": function(data, type, row, meta) {
if (type != 'display') return _escape_str(data);
return _escape_str(row.fund.name);
if (type != 'display') return escape_str(data);
return escape_str(row.fund.name);
}
},
{
@ -556,7 +549,7 @@
return '<a href="orderreceive.pl?ordernumber='
+ encodeURIComponent(row.order_id) + '&amp;invoiceid=[% invoiceid | uri %]' + '">'
+ _("Receive") + '</a><br/>'
+ '<a href="#" onclick="transfer_order_popup(' + _escape_str(row.order_id) + '); return false;">'
+ '<a href="#" onclick="transfer_order_popup(' + escape_str(row.order_id) + '); return false;">'
+ _("Transfer") + '</a>';
},
"orderable": false,
@ -569,7 +562,7 @@
if ( row.current_holds_count > 0 ) {
result += '<span class="button" title="'
+ _("Can't cancel order, (%s) holds are linked with this order. Cancel holds first").format( _escape_str(row.holds_count) ) + '">'
+ _("Can't cancel order, (%s) holds are linked with this order. Cancel holds first").format( escape_str(row.holds_count) ) + '">'
+ _("Can't cancel order") + '</span><br/>';
}
else {

View file

@ -26,6 +26,9 @@ String.prototype.escapeHtml = function() {
return HtmlCharsToEscape[c] || c;
});
};
function escape_str(s){
return s != null ? s.escapeHtml() : "";
}
/*
* Void method for numbers, for consistency
@ -33,6 +36,9 @@ String.prototype.escapeHtml = function() {
Number.prototype.escapeHtml = function() {
return this;
};
function escape_price(p){
return p != null ? p.escapeHtml().format_price() : "";
}
// http://stackoverflow.com/questions/14859281/select-tab-by-name-in-jquery-ui-1-10-0/16550804#16550804
$.fn.tabIndex = function () {