From 88e99d1c29124470cefad9daeb886c6d2c72301b Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Mon, 8 Feb 2010 13:46:32 +0100 Subject: [PATCH] BZ4104: Removes tagging in staff client Signed-off-by: Galen Charlton --- .../prog/en/includes/doc-head-close.inc | 1 - koha-tmpl/intranet-tmpl/prog/en/js/tags.js | 158 --------- .../prog/en/modules/basket/basket.tmpl | 80 +---- tags/tags.pl | 327 ------------------ 4 files changed, 3 insertions(+), 563 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/js/tags.js delete mode 100755 tags/tags.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc index d4c7846b60..845ceeb992 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/doc-head-close.inc @@ -43,7 +43,6 @@ - diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/tags.js b/koha-tmpl/intranet-tmpl/prog/en/js/tags.js deleted file mode 100644 index 9c117d0b33..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/js/tags.js +++ /dev/null @@ -1,158 +0,0 @@ -if (typeof KOHA == "undefined" || !KOHA) { - var KOHA = {}; -} - -/** -* A namespace for Tags related functions. -* readCookie is expected to already be declared. That's why the assignment below is unscoped. -* readCookie should be from basket.js or undefined. - -$.ajaxSetup({ - url: "/cgi-bin/koha/tags/tags.pl", - type: "POST", - dataType: "script" -}); -*/ -if (typeof(readCookie) == "undefined") { - readCookie = function (name) { // from http://www.quirksmode.org/js/cookies.html - var nameEQ = name + "="; - var ca = document.cookie.split(';'); - for (var i=0;i < ca.length;i++) { - var c = ca[i]; - while (c.charAt(0)==' '){ c = c.substring(1,c.length); } - if (c.indexOf(nameEQ) == 0){ return c.substring(nameEQ.length,c.length); } - } - return null; - } -} -KOHA.Tags = { - add_tag_button: function(){ - var mybibnum = $(this).attr("title"); - var mynewtag = "newtag" + mybibnum; - var mytagid = "#" + mynewtag; - var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID - mydata[mynewtag] = $(mytagid).val(); // need [bracket] for variable property id - var response; // AJAX from server will assign value to response. - $.post( - "/cgi-bin/koha/tags/tags.pl", - mydata, - function(data){ - // alert("AJAX Response: " + data); - eval(data); - // alert("counts: " + response["added"] + response["deleted"] + response["errors"]); - KOHA.Tags.set_tag_status( - mytagid + "_status", - KOHA.Tags.common_status(response["added"], response["deleted"], response["errors"]) - ); - if (response.alerts) { - alert(response.alerts.join("\n\n")); - } - }, - 'script' - ); - return false; - }, - common_status : function(addcount, delcount, errcount) { - var cstat = ""; - if (addcount && addcount > 0) {cstat += _("Added ") + addcount + (addcount==1 ? _(" tag") : _(" tags")) + ". " ;} - if (delcount && delcount > 0) {cstat += _("Deleted ") + delcount + (delcount==1 ? _(" tag") : _(" tags")) + ". " ;} - if (errcount && errcount > 0) {cstat += (errcount==1 ? _("ERROR") : errcount + _(" ERRORS")) + _(" during operation.");} - return cstat; - }, - set_tag_status : function(tagid, newstatus) { - $(tagid).html(newstatus); - $(tagid).css({display:"inline"}); - }, - append_tag_status : function(tagid, newstatus) { - $(tagid).append(newstatus); - $(tagid).css({display:"inline"}); - }, - - tag_message: { - tagsdisabled : function(arg) {return (_("Sorry, tags are not enabled on this system."));}, - scrubbed_all_bad : function(arg) {return (_("Error! Your tag was entirely markup code. It was NOT added. Please try again with plain text."));}, - badparam : function(arg) {return (_("Error! Illegal parameter '" +arg+ "'."));}, - scrubbed : function(arg) {return (_("Note: your tag contained markup code that was removed. The tag was added as '" +arg+ "'."));}, - failed_add_tag : function(arg) {return (_("Error! The add_tag operation failed on '" +arg+ "'. Note: you can only tag an item with a given term once. Check 'My Tags' to see your current tags."));}, - failed_delete : function(arg) {return (_("Error! You cannot delete the tag '" +arg+ "'. Note: you can only delete your own tags."));}, - login : function(arg) {return (_("You must be logged in to add tags."));} - }, - - // Used to tag multiple items at once. The main difference - // is that status is displayed on a per item basis. - add_multitags_button : function(bibarray, tag){ - var mydata = {CGISESSID: readCookie('CGISESSID')}; // Someday this should be OPACSESSID - for (var i = 0; i < bibarray.length; i++) { - var mynewtag = "newtag" + bibarray[i]; - mydata[mynewtag] = tag; - } - var response; // AJAX from server will assign value to response. - $.post( - "/cgi-bin/koha/tags/tags.pl", - mydata, - function(data){ - eval(data); - $(".tagstatus").empty(); - var bibErrors = false; - - // Display the status for each tagged bib - for (var i = 0; i < bibarray.length; i++) { - var bib = bibarray[i]; - var mytagid = "#newtag" + bib; - var status = ""; - - // Number of tags added. - if (response[bib]) { - var added = response[bib]["added"]; - if (added > 0) { - status = "Added " + added + (added == 1 ? " tag" : " tags") + ". "; - KOHA.Tags.set_tag_status(mytagid + "_status", status); - } - - // Show a link that opens an error dialog, if necessary. - var errors = response[bib]["errors"]; - if (errors.length > 0) { - bibErrors = true; - var errid = "tagerr_" + bib; - var errstat = ""; - errstat += "Error" + (errors.length > 1 ? "s" : "") + " adding tag."; - errstat += ""; - KOHA.Tags.append_tag_status(mytagid + "_status", errstat); - var errmsg = ""; - for (var e = 0; e < errors.length; e++){ - if (e) { - errmsg += "\n\n"; - } - errmsg += errors[e]; - } - $("#" + errid).click(function(){ - alert(errmsg); - }); - } - } - } - - if (bibErrors || response["global_errors"]) { - var msg = ""; - if (bibErrors) { - msg = "Unable to add one or more tags."; - } - - // Show global errors in a dialog. - if (response["global_errors"]) { - var global_errors = response["global_errors"]; - var msg; - for (var e = 0; e < global_errors.length; e++) { - msg += "\n\n"; - msg += response.alerts[global_errors[e]]; - } - } - alert(msg); - } - }, - 'script' - ); - return false; - } -}; - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tmpl index 8cf9c5b6eb..9257162a2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/basket.tmpl @@ -1,6 +1,6 @@ -Koha Online Catalog › Your Cart - +<!-- TMPL_IF NAME="LibraryNameTitle" --><!-- TMPL_VAR NAME="LibraryNameTitle" --><!-- TMPL_ELSE -->Koha Online<!-- /TMPL_IF --> Catalog › Your Cart + /includes/favicon.ico" type="image/x-icon" /> @@ -44,48 +44,6 @@ function placeHold () { -var MSG_NO_TAG_SPECIFIED = _("No tag was specified."); - -function tagSelected() { - var bibs = document.getElementById('records').value; - if (bibs) { - $("#tagsel_tag").hide(); - $("#tag_hides").hide(); - $("#tagsel_form").show(); - } else { - alert(MSG_NO_RECORD_SELECTED); - } -} - -function tagCanceled() { - $("#tagsel_form").hide(); - $("#tagsel_tag").show(); - $("#tag_hides").show(); -} - -function tagAdded() { - var checkedBoxes = $("input:checkbox:checked"); - if (!$(checkedBoxes).size()) { - alert(MSG_NO_RECORD_SELECTED); - return false; - } - - var tag = $("#tagsel_new").val(); - if (!tag || (tag == "")) { - alert(MSG_NO_TAG_SPECIFIED); - return false; - } - - var bibs = []; - for (var i = 0; i < $(checkedBoxes).size(); i++) { - var box = $(checkedBoxes).get(i); - bibs[i] = $(box).val(); - } - - KOHA.Tags.add_multitags_button(bibs, tag); - return false; -} - $(document).ready(function(){ $("#CheckAll").click(function(){ var checked = []; @@ -107,16 +65,6 @@ function tagAdded() { }); $(".holdsep").text("| "); $(".hold").text(_("Place Hold")); - - - $(".tagsep").text("| "); - $("#tagsel_tag").text(_("Tag")); - $("#tagsel_button").click(function(){ - tagAdded(); - return false; - }); - - }); @@ -159,7 +107,7 @@ function tagAdded() {
  • - + Hide Window
  • @@ -169,8 +117,6 @@ function tagAdded() {

    Select All Clear All | Selected items : - -Remove | Add to a list @@ -180,16 +126,6 @@ function tagAdded() { | Place Hold - - - -

    @@ -348,7 +284,6 @@ function tagAdded() { Select All Clear All | Selected items : - Remove @@ -360,14 +295,6 @@ function tagAdded() { - - -

    @@ -402,7 +329,6 @@ function tagAdded() { &rft.btitle=&rft.date=&rft.tpages=&rft.isbn=&rft.aucorp=&rft.place=&rft.pub=&rft.edition=&rft.series=&rft.genre="> -
    _status" class="tagstatus results_summary" style="display:none">Tag status here.
    diff --git a/tags/tags.pl b/tags/tags.pl deleted file mode 100755 index bfce9ccd56..0000000000 --- a/tags/tags.pl +++ /dev/null @@ -1,327 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2000-2002 Katipo Communications -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA - - -=head1 - -TODO :: Description here - -C4::Scrubber is used to remove all markup content from the sumitted text. - -=cut - -use strict; -use warnings; -use CGI; -use CGI::Cookie; # need to check cookies before having CGI parse the POST request - -use C4::Auth qw(:DEFAULT check_cookie_auth); -use C4::Context; -use C4::Debug; -use C4::Output 3.02 qw(:html :ajax pagination_bar); -use C4::Dates qw(format_date); -use C4::Scrubber; -use C4::Biblio; -use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag); - -my %newtags = (); -my @deltags = (); -my %counts = (); -my @errors = (); -my $perBibResults = {}; - -# Indexes of @errors that do not apply to a particular biblionumber. -my @globalErrorIndexes = (); - -sub ajax_auth_cgi ($) { # returns CGI object - my $needed_flags = shift; - my %cookies = fetch CGI::Cookie; - my $input = CGI->new; - my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID'); - my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); - $debug and - print STDERR "($auth_status, $auth_sessid) = check_cookie_auth($sessid," . Dumper($needed_flags) . ")\n"; - if ($auth_status ne "ok") { - output_with_http_headers $input, undef, - "window.alert('Your CGI session cookie ($sessid) is not current. " . - "Please refresh the page and try again.');\n", 'js'; - exit 0; - } - $debug and print STDERR "AJAX request: " . Dumper($input), - "\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n"; - return $input; -} - -# The trick here is to support multiple tags added to multiple bilbios in one POST. -# The HTML might not use this, but it makes it more web-servicey from the start. -# So the name of param has to have biblionumber built in. -# For lack of anything more compelling, we just use "newtag[biblionumber]" -# We split the value into tags at comma and semicolon - -my $is_ajax = is_ajax(); -my $openadds = C4::Context->preference('TagsModeration') ? 0 : 1; -my $query = ($is_ajax) ? &ajax_auth_cgi({}) : CGI->new(); -unless (C4::Context->preference('TagsEnabled')) { - push @errors, {+ tagsdisabled=>1 }; - push @globalErrorIndexes, $#errors; -} else { - foreach ($query->param) { - if (/^newtag(.*)/) { - my $biblionumber = $1; - unless ($biblionumber =~ /^\d+$/) { - $debug and warn "$_ references non numerical biblionumber '$biblionumber'"; - push @errors, {+'badparam' => $_ }; - push @globalErrorIndexes, $#errors; - next; - } - $newtags{$biblionumber} = $query->param($_); - } elsif (/^del(\d+)$/) { - push @deltags, $1; - } - } -} - -my $add_op = (scalar(keys %newtags) + scalar(@deltags)) ? 1 : 0; -my ($template, $loggedinuser, $cookie); -if ($is_ajax) { - $loggedinuser = C4::Context->userenv->{'id'}; # must occur AFTER auth - $debug and print STDERR "op: $loggedinuser\n"; -} else { - ($template, $loggedinuser, $cookie) = get_template_and_user({ - template_name => "tags/tags.tmpl", - query => $query, - type => "intranet", - authnotrequired => ($add_op ? 0 : 1), # auth required to add tags - debug => 1, - }); -} - -if ($add_op) { - unless ($loggedinuser) { - push @errors, {+'login' => 1 }; - push @globalErrorIndexes, $#errors; - %newtags=(); # zero out any attempted additions - @deltags=(); # zero out any attempted deletions - } -} - -my $scrubber; -my @newtags_keys = (keys %newtags); -if (scalar @newtags_keys) { - $scrubber = C4::Scrubber->new(); - foreach my $biblionumber (@newtags_keys) { - my $bibResults = {adds=>0, errors=>[]}; - my @values = split /[;,]/, $newtags{$biblionumber}; - foreach (@values) { - s/^\s*(.+)\s*$/$1/; - my $clean_tag = $scrubber->scrub($_); - unless ($clean_tag eq $_) { - if ($clean_tag =~ /\S/) { - push @errors, {scrubbed=>$clean_tag}; - push @{$bibResults->{errors}}, {scrubbed=>$clean_tag}; - } else { - push @errors, {scrubbed_all_bad=>1}; - push @{$bibResults->{errors}}, {scrubbed_all_bad=>1}; - next; # we don't add it if there's nothing left! - } - } - my $result = ($openadds) ? - add_tag($biblionumber,$clean_tag,$loggedinuser,$loggedinuser) : # pre-approved - add_tag($biblionumber,$clean_tag,$loggedinuser) ; - if ($result) { - $counts{$biblionumber}++; - $bibResults->{adds}++; - } else { - push @errors, {failed_add_tag=>$clean_tag}; - push @{$bibResults->{errors}}, {failed_add_tag=>$clean_tag}; - $debug and warn "add_tag($biblionumber,$clean_tag,$loggedinuser...) returned bad result (" . (defined $result ? $result : 'UNDEF') .")"; - } - } - $perBibResults->{$biblionumber} = $bibResults; - } -} -my $dels = 0; -foreach (@deltags) { - if (remove_tag($_,$loggedinuser)) { - $dels++; - } else { - push @errors, {failed_delete=>$_}; - } -} - -if ($is_ajax) { - my $sum = 0; - foreach (values %counts) {$sum += $_;} - my $js_reply = sprintf("response = {\n\tadded: %d,\n\tdeleted: %d,\n\terrors: %d",$sum,$dels,scalar @errors); - - # If no add attempts were made, flag global errors. - if (@globalErrorIndexes) { - $js_reply .= ",\n\tglobal_errors: ["; - my $first = 1; - foreach (@globalErrorIndexes) { - $js_reply .= "," unless $first; - $first = 0; - $js_reply .= "\n\t\t$_"; - } - $js_reply .= "\n\t]"; - } - - my $err_string = ''; - if (scalar @errors) { - $err_string = ",\n\talerts: ["; # open response_function - my $i = 1; - foreach (@errors) { - my $key = (keys %$_)[0]; - $err_string .= "\n\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")'; - if($i < scalar @errors){ $err_string .= ","; } - $i++; - } - $err_string .= "\n\t]\n"; # close response_function - } - - # Add per-biblionumber results for use on results page - my $js_perbib = ""; - for my $bib (keys %$perBibResults) { - my $bibResult = $perBibResults->{$bib}; - my $js_bibres = ",\n\t$bib: {\n\t\tadded: $bibResult->{adds}"; - $js_bibres .= ",\n\t\terrors: ["; - my $i = 0; - foreach (@{$bibResult->{errors}}) { - $js_bibres .= "," if ($i); - my $key = (keys %$_)[0]; - $js_bibres .= "\n\t\t\t KOHA.Tags.tag_message.$key(\"" . $_->{$key} . '")'; - $i++; - } - $js_bibres .= "\n\t\t]\n\t}"; - $js_perbib .= $js_bibres; - } - - output_with_http_headers($query, undef, "$js_reply\n$err_string\n$js_perbib\n};", 'js'); - exit; -} - -my $results = []; -my $my_tags = []; - -if ($loggedinuser) { - $my_tags = get_tag_rows({borrowernumber=>$loggedinuser}); - foreach (@$my_tags) { - my $biblio = GetBiblioData($_->{biblionumber}); - $_->{bib_summary} = $biblio->{title}; - ($biblio->{author}) and $_->{bib_summary} .= " by " . $biblio->{author}; - my $date = $_->{date_created} || ''; - $date =~ /\s+(\d{2}\:\d{2}\:\d{2})/; - $_->{time_created_display} = $1; - $_->{date_created_display} = format_date($_->{date_created}); - } -} - -$template->param(tagsview => 1, -dateformat => C4::Context->preference("dateformat")); - -if ($add_op) { - my $adds = 0; - for (values %counts) {$adds += $_;} - $template->param( - add_op => 1, - added_count => $adds, - deleted_count => $dels, - ); -} else { - my ($arg,$limit,$mine); - my $hardmax = 100; # you might disagree what this value should be, but there definitely should be a max - $limit = $query->param('limit') || $hardmax; - $mine = $query->param('mine') || 0; # set if the patron want to see only his own tags. - ($limit =~ /^\d+$/ and $limit <= $hardmax) or $limit = $hardmax; - $template->param(limit => $limit); - my $arghash = {approved=>1, limit=>$limit, 'sort'=>'-weight_total'}; - $arghash->{'borrowernumber'} = $loggedinuser if $mine; - # ($openadds) or $arghash->{approved} = 1; - if ($arg = $query->param('tag')) { - $arghash->{term} = $arg; - } elsif ($arg = $query->param('biblionumber')) { - $arghash->{biblionumber} = $arg; - } - $results = get_approval_rows($arghash); - - my $count = scalar @$results; - $template->param(TAGLOOP_COUNT => $count, mine => $mine); - # Here we make a halfhearted attempt to separate the tags into "strata" based on weight_total - # FIXME: code4lib probably has a better algorithm, iirc - # FIXME: when we get a better algorithm, move to C4 - my $maxstrata = 5; - my $strata = 1; - my $previous = 0; - my $chunk = ($count/$maxstrata)/2; - my $total = 0; - my %cloud; - foreach (reverse @$results) { - my $current = $_->{weight_total}; - $total++; - $cloud{$strata}++; - if ($current == $previous) { - $_->{cloudweight} = $strata; - next; - } - if ($strata < $maxstrata and - ($cloud{$strata} > $chunk or - $count-$total <= $maxstrata-$strata)) { - $strata++; - } - $_->{cloudweight} = $strata; - $previous = $current; - } -} -(scalar @errors ) and $template->param(ERRORS => \@errors); -my @orderedresult = sort { $a->{'term'} cmp $b->{'term'} } @$results; -(scalar @$results) and $template->param(TAGLOOP => \@orderedresult ); -(scalar @$my_tags) and $template->param(MY_TAGS => $my_tags); - -output_html_with_http_headers $query, $cookie, $template->output; -__END__ - -=head1 EXAMPLE AJAX POST PARAMETERS - -CGISESSID 7c6288263107beb320f70f78fd767f56 -newtag396 fire,+foobar,+ - -So this request is trying to add 3 tags to biblio #396. The CGISESSID is the same as that the browser would -typically communicate using cookies. If it is valid, the server will split the value of "newtag396" and -process the components for addition. In this case the intended tags are: - fire - foobar - - -The first tag is acceptable. The second will be scrubbed of markup, resulting in the tag "foobar". -The third tag is all markup, and will be rejected. - -=head1 EXAMPLE AJAX JSON response - -response = { - added: 2, - deleted: 0, - errors: 2, - alerts: [ - KOHA.Tags.tag_message.scrubbed("foobar"), - KOHA.Tags.tag_message.scrubbed_all_bad("1"), - ], -}; - -=cut - -- 2.39.5