From a800292c541156d539cdf523b5dcd6587a2257e9 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 9 Jun 2017 12:29:58 +0000 Subject: [PATCH] [SIGNED OFF] Bug 5471 - Quotes in tags fail This patch makes changes to the tag moderation template and JavaScript to fix handling of tags with double or single quotes. This patch also moves the tags moderation JavaScript out of the template and into a separate JS file. To test you should have multiple tags awaiting moderation, including tags which contain double and single quotes. - Go to Tools -> Tags. - In the list of tags pending approval, test approving and rejecting tags, including those containing single or double quotes. - The state of the "Approve" or "Reject" buttons should correctly change according to the action you chose. - The label in the status column should update correctly. - In the "Check lists" form, submitting approved, rejected, and unclassified terms should result in the correct message. Signed-off-by: Lee Jamison Works correctly based on test plan. Tested using single- and double-quoted tags. Passes QA Tools. --- .../intranet-tmpl/prog/en/modules/tags/review.tt | 216 ++++----------------- .../intranet-tmpl/prog/js/pages/tags-review.js | 162 ++++++++++++++++ tags/review.pl | 9 +- 3 files changed, 201 insertions(+), 186 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt index 9b7ecd1..ffb606d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tt @@ -6,6 +6,23 @@ [% INCLUDE 'datatables.inc' %] [% INCLUDE 'calendar.inc' %] + + - [% INCLUDE 'header.inc' %] @@ -239,14 +93,14 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; } - - + + - + [% UNLESS ( filter_approved_pending ) %][% END %] - + @@ -254,30 +108,30 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; } - [% IF ( tagloo.approved == 0 ) %] - [% IF ( tagloo.approved ) %] @@ -285,8 +139,8 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; } [% ELSE %] [% UNLESS ( filter_approved_pending ) %][% END %] @@ -329,7 +183,7 @@ tr > td input,td input[type="submit"] { font-size: 85%; padding: 1px; }
Enter a word or phrase to check against approved/rejected lists:
-
+
[% IF ( test_term ) %] [% IF ( verdict_ok ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js b/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js new file mode 100644 index 0000000..7e41e60 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js @@ -0,0 +1,162 @@ +$.ajaxSetup({ + url: "/cgi-bin/koha/tags/review.pl", + type: "POST", + dataType: "script" +}); + +var ok_count = 0; +var nok_count = 0; +var rej_count = 0; +var alerted = 0; + +function pull_counts () { + ok_count = parseInt(document.getElementById("terms_summary_approved_count" ).innerHTML); + nok_count = parseInt(document.getElementById("terms_summary_unapproved_count").innerHTML); + rej_count = parseInt(document.getElementById("terms_summary_rejected_count" ).innerHTML); +} + +function count_approve () { + pull_counts(); + if (nok_count > 0) { + $("#terms_summary_unapproved_count").html(nok_count -1); + $("#terms_summary_approved_count" ).html( ok_count +1); + } +} + +function count_reject () { + pull_counts(); + if (nok_count > 0) { + $("#terms_summary_unapproved_count").html(nok_count -1); + $("#terms_summary_rejected_count" ).html(rej_count +1); + } +} + +var success_approve = function(tag){ + // window.alert(_("AJAX approved tag: ") + tag); +}; +var failure_approve = function(tag){ + window.alert(MSG_AJAX_APPROVE_FAILED.format(decodeURIComponent( tag ))); +}; +var success_reject = function(tag){ + // window.alert(_("AJAX rejected tag: ") + tag); +}; +var failure_reject = function(tag){ + window.alert(MSG_AJAX_REJECTION_FAILED.format(decodeURIComponent( tag ))); +}; +var success_test = function(tag){ + $('#verdict').html(MSG_AJAX_TAG_PERMITTED.format( decodeURIComponent( tag ) )); +}; +var failure_test = function(tag){ + $('#verdict').html(MSG_AJAX_TAG_PROHIBITED.format( decodeURIComponent( tag ) )); +}; +var indeterminate_test = function(tag){ + $('#verdict').html(MSG_AJAX_TAG_UNCLASSIFIED.format( decodeURIComponent( tag ) )); +}; + +var success_test_call = function() { + $('#test_button').prop('disabled', false); + $('#test_button').html("" +_(" Test")); +}; + +$(document).ready(function() { + $("#tagst").dataTable($.extend(true, {}, dataTablesDefaults, { + "aoColumnDefs": [ + { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, + { "sType": "anti-the", "aTargets" : [ "anti-the" ] }, + { "sType": "title-string", "aTargets" : [ "title-string" ] } + ], + "aaSorting": [[ 4, "desc" ]], + "sPaginationType": "four_button" + })); + $('.ajax_buttons' ).css({visibility:"visible"}); + $("p.check").html("
<\/i> "+ LABEL_SELECT_ALL +"<\/a> | <\/i> "+ LABEL_CLEAR_ALL +"<\/a> | "+ LABEL_SELECT_ALL_PENDING +"<\/a><\/div>"); + $("#CheckAll").click(function(){ + $(".checkboxed").checkCheckboxes(); + return false; + }); + $("#CheckNone").click(function(){ + $(".checkboxed").unCheckCheckboxes(); + return false; + }); + $("#CheckPending").click(function(){ + $(".checkboxed").checkCheckboxes(".pending"); + return false; + }); + $(".approval_btn").on('click',function(event) { + event.preventDefault(); + pull_counts(); + var getelement; + var gettitle; + // window.alert(_("Click detected on ") + event.target + ": " + $(event.target).html); + if ($(event.target).is('.ok')) { + $.ajax({ + data: { + ok: $(event.target).attr("title") + }, + success: count_approve // success_approve + }); + $(event.target).next(".rej").prop('disabled', false).css("color","#000"); + $(event.target).next(".rej").html(" " + _("Reject")); + $(event.target).prop('disabled', true).css("color","#666"); + $(event.target).html(" " + LABEL_APPROVED ); + getelement = $(event.target).data("num"); + gettitle = ".status" + getelement; + $(gettitle).text( LABEL_APPROVED ); + if ($(gettitle).hasClass("pending") ){ + $(gettitle).toggleClass("pending approved"); + } else { + $(gettitle).toggleClass("rejected approved"); + } + } + if ($(event.target).is('.rej')) { + $.ajax({ + data: { + rej: $(event.target).attr("title") + }, + success: count_reject // success_reject + }); + $(event.target).prev(".ok").prop('disabled', false).css("color","#000"); + $(event.target).prev(".ok").html(" " + LABEL_APPROVE ); + $(event.target).prop('disabled', true).css("color","#666"); + $(event.target).html(" " + LABEL_REJECTED ); + getelement = $(event.target).data("num"); + gettitle = ".status" + getelement; + $(gettitle).text( LABEL_REJECTED ); + if ($(gettitle).hasClass("pending") ){ + $(gettitle).toggleClass("pending rejected"); + } else { + $(gettitle).toggleClass("approved rejected"); + } + return false; // cancel submit + } + if ($(event.target).is('#test_button')) { + $(event.target).text( LABEL_TESTING ).prop('disabled', true); + $.ajax({ + data: { + test: $('#test').attr("value") + }, + success: success_test_call // success_reject + }); + return false; // cancel submit + } + }); + $("*").ajaxError(function(evt, request, settings){ + if ((alerted +=1) <= 1){ window.alert(MSG_AJAX_ERROR.format(alerted)); } + }); + + var reviewerField = $("#approver"); + reviewerField.autocomplete({ + source: "/cgi-bin/koha/circ/ysearch.pl", + minLength: 3, + select: function( event, ui ) { + reviewerField.val( ui.item.borrowernumber ); + return false; + } + }) + .data( "ui-autocomplete" )._renderItem = function( ul, item ) { + return $( "
  • " ) + .data( "ui-autocomplete-item", item ) + .append( "
    " + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) + .appendTo( ul ); + }; +}); diff --git a/tags/review.pl b/tags/review.pl index b7e959b..009966d 100755 --- a/tags/review.pl +++ b/tags/review.pl @@ -25,7 +25,7 @@ use Data::Dumper; use POSIX; use CGI qw ( -utf8 ); use CGI::Cookie; # need to check cookies before having CGI parse the POST request - +use URI::Escape; use C4::Auth qw(:DEFAULT check_cookie_auth); use C4::Context; use Koha::DateUtils; @@ -63,14 +63,13 @@ if (is_ajax()) { my ($tag, $js_reply); if ($tag = $input->param('test')) { my $check = is_approved($tag); - $js_reply = ( $check >= 1 ? 'success' : - $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('$tag');\n"; + $js_reply = ( $check >= 1 ? 'success' : $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('".uri_escape($tag)."');\n"; } if ($tag = $input->param('ok')) { - $js_reply = ( whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('$tag');\n"; + $js_reply = ( whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('".uri_escape($tag)."');\n"; } if ($tag = $input->param('rej')) { - $js_reply = ( blacklist($operator,$tag) ? 'success' : 'failure') . "_reject('$tag');\n"; + $js_reply = ( blacklist($operator,$tag) ? 'success' : 'failure') . "_reject('".uri_escape($tag)."');\n"; } output_with_http_headers $input, undef, $js_reply, 'js'; exit; -- 2.1.4
         Status Term WeightActionsActionsReviewerDateDate
    [% offset + loop.count %] - [% ELSE %][% END %] + [% IF ( tagloo.approved == 0 ) %] + [% ELSE %][% END %] [% IF ( tagloo.approved == -1 ) %] - Rejected + Rejected [% ELSIF ( tagloo.approved == 1 ) %] - Approved + Approved [% ELSE %] - Pending + Pending [% END %] [% tagloo.term %] + [% tagloo.term|html %] [% tagloo.weight_total %]