[Koha-patches] [PATCH] Tags AJAX integration on OPAC details page, so it behaves like results.
Joe Atzberger
joe.atzberger at liblime.com
Thu May 29 03:31:28 CEST 2008
Also, prevent duplicate tags (same user, biblio and term). Strip
leading/trailing whitespace from term. Block whitespace terms.
The CSS for details could be enhanced to emphasize tagstatus more.
---
C4/Tags.pm | 32 +++++++++++++++-----
koha-tmpl/opac-tmpl/prog/en/js/tags.js | 2 +-
.../opac-tmpl/prog/en/modules/opac-detail.tmpl | 7 ++--
3 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/C4/Tags.pm b/C4/Tags.pm
index f706ffc..09e5993 100644
--- a/C4/Tags.pm
+++ b/C4/Tags.pm
@@ -531,18 +531,25 @@ sub add_tag ($$;$$) { # biblionumber,term,[borrowernumber,approvernumber]
my $biblionumber = shift or return undef;
my $term = shift or return undef;
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin
-
- # first, add to tags regardless of approaval
+ $term =~ s/^\s+//;
+ $term =~ s/\s+$//;
+ ($term) or return undef; # must be more than whitespace
+ my $rows = get_tag_rows({biblionumber=>$biblionumber, borrowernumber=>$borrowernumber, term=>$term, limit=>1});
my $query = "INSERT INTO tags_all
(borrowernumber,biblionumber,term,date_created)
VALUES (?,?,?,NOW())";
$debug and print STDERR "add_tag query:\n $query\n",
"add_tag query args: ($borrowernumber,$biblionumber,$term)\n";
+ if (scalar @$rows) {
+ $debug and carp "Duplicate tag detected. Tag not added.";
+ return undef;
+ }
+ # add to tags_all regardless of approaval
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($borrowernumber,$biblionumber,$term);
# then
- if (@_) { # if an arg remains, it is the borrowernumber of the approver: tag is pre-approved.
+ if (@_) { # if an arg remains, it is the borrowernumber of the approver: tag is pre-approved. Note, whitelist unaffected.
my $approver = shift;
add_tag_approval($term,$approver);
add_tag_index($term,$biblionumber,$approver);
@@ -620,12 +627,19 @@ trying to calculate that and the "weight" (number of times a tag appears) on the
biblionumber - book record it is attached to
weight - number of times tag applied by any user
-tags_blacklist - TODO
+tags_blacklist - A set of regular expression filters. Unsurprisingly, these should be perl-
+compatible (PCRE) for your version of perl. Since this is a blacklist, a term will be
+blocked if it matches any of the given patterns. WARNING: do not add blacklist regexps
+if you do not understand their operation and interaction. It is quite easy to define too
+simple or too complex a regexp and effectively block all terms. The blacklist operation is
+fairly resource intensive, since every line of tags_blacklist will need to be read and compared.
+It is recommended that tags_blacklist be used minimally, and only by an administrator with an
+understanding of regular expression syntax and performance.
-So the best way to think about the different tabes is that they are each tailored to a certain
+So the best way to think about the different tables is that they are each tailored to a certain
use. Note that tags_approval and tags_index do not rely on the user's borrower mapping, so
-the tag population can continue to grow even if a user is removed, along with the corresponding
-rows in tags_all.
+the tag population can continue to grow even if a user (along with their corresponding
+rows in tags_all) is removed.
=head2 Tricks
@@ -664,8 +678,10 @@ mysql> select biblionumber from biblio where title LIKE "%Health%";
+--------------+
26 rows in set (0.00 sec)
-Then, take those numbers and type them into this perl command line:
+Then, take those numbers and type/pipe them into this perl command line:
perl -ne 'use C4::Tags qw(get_tags add_tag); use Data::Dumper;chomp; add_tag($_,"health",51,1); print Dumper get_tags({limit=>5,term=>"health",});'
+Note, the borrowernumber in this example is 51. Use your own or any arbitrary valid borrowernumber.
+
=cut
diff --git a/koha-tmpl/opac-tmpl/prog/en/js/tags.js b/koha-tmpl/opac-tmpl/prog/en/js/tags.js
index 62c66b2..95f3d19 100644
--- a/koha-tmpl/opac-tmpl/prog/en/js/tags.js
+++ b/koha-tmpl/opac-tmpl/prog/en/js/tags.js
@@ -69,7 +69,7 @@ KOHA.Tags = {
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+ "'.");},
+ 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.");},
},
};
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl
index 83c4309..540263d 100755
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl
@@ -18,6 +18,7 @@
});
<!-- TMPL_IF NAME="GoogleJackets" -->KOHA.Google.GetCoverFromIsbn();<!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="TagsEnabled" -->$(".tagbutton").click(KOHA.Tags.add_tag_button);<!-- /TMPL_IF -->
});
//]]>
@@ -193,13 +194,13 @@
<span class="label" id="addtagl"><a href="#">Add</a></span>
<form name="tagform<!-- TMPL_VAR NAME="biblionumber" -->" method="post" action="/cgi-bin/koha/opac-tags.pl" id="tagform">
<label for="newtag<!-- TMPL_VAR NAME="biblionumber" -->">New:</label><input name="newtag<!-- TMPL_VAR NAME="biblionumber" -->" id="newtag<!-- TMPL_VAR NAME="biblionumber" -->" maxlength="100" />
- <input name="tagbutton" class="input tagbutton" type="submit" value="Add" />
+ <input name="tagbutton" class="input tagbutton" title="<!-- TMPL_VAR NAME="biblionumber" -->" type="submit" value="Add" />
<a href="#">Cancel</a>
</form>
- <br />
- <span id="tagstatus<!-- TMPL_VAR NAME="biblionumber" -->" class="tagstatus" style="display:none;">
+ <span id="newtag<!-- TMPL_VAR NAME="biblionumber" -->_status" class="tagstatus" style="display:none;">
Tag status here.
</span>
+ <br />
<!-- /TMPL_IF -->
</div>
<!-- /TMPL_IF -->
--
1.5.5.GIT
More information about the Koha-patches
mailing list