Bugfix is_approved() to handle the 3-state nature of approval.
authorJoe Atzberger <joe.atzberger@liblime.com>
Tue, 3 Jun 2008 14:27:15 +0000 (09:27 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 6 Jun 2008 03:41:40 +0000 (22:41 -0500)
That is, a term is either approved, or rejected, or neither.
Without an external dictionary, most terms will fall into the
latter category.

Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Tags.pm
koha-tmpl/intranet-tmpl/prog/en/modules/tags/review.tmpl
tags/review.pl

index 11046c4..cfdebb5 100644 (file)
@@ -339,9 +339,9 @@ sub is_approved ($) {
        $sth->execute($term);
        unless ($sth->rows) {
                $ext_dict and return (spellcheck($term) ? 0 : 1);       # spellcheck returns empty on OK word
-               return undef;
+               return 0;
        }
-       return $sth->fetch;
+       return $sth->fetchrow;
 }
 
 sub get_tag_index ($;$) {
@@ -550,11 +550,11 @@ sub add_tag ($$;$$) {     # biblionumber,term,[borrowernumber,approvernumber]
        $sth->execute($borrowernumber,$biblionumber,$term);
 
        # then 
-       if (@_) {       # if an arg remains, it is the borrowernumber of the approver: tag is pre-approved.  Note, whitelist unaffected.
+       if (scalar @_) {        # if arg remains, it is the borrowernumber of the approver: tag is pre-approved.
                my $approver = shift;
                add_tag_approval($term,$approver);
                add_tag_index($term,$biblionumber,$approver);
-       } elsif (is_approved($term)) {
+       } elsif (is_approved($term) >= 1) {
                add_tag_approval($term,1);
                add_tag_index($term,$biblionumber,1);
        } else {
index f339075..e5cf750 100644 (file)
@@ -63,6 +63,9 @@
        var failure_test    = function(tag){
                $('#verdict').html(tag + ' is prohibited!');
        };
+       var indeterminate_test = function(tag){
+               $('#verdict').html(tag + ' is neither permitted nor prohibited!');
+       };
 
        var success_test_call = function() {
                $('#test_button').removeAttr("disabled");
@@ -350,6 +353,8 @@ Calendar.setup({
                &quot;<!-- TMPL_VAR NAME="test_term" -->&quot; is permitted.
        <!-- TMPL_ELSIF NAME="verdict_rej" -->
                &quot;<!-- TMPL_VAR NAME="test_term" -->&quot; is prohibited.
+       <!-- TMPL_ELSIF NAME="verdict_indeterminate" -->
+               &quot;<!-- TMPL_VAR NAME="test_term" -->&quot; is neither permitted nor prohibited.
        <!-- /TMPL_IF -->
        <!-- /TMPL_IF -->
    </div>
index f6e9501..2c8c88d 100755 (executable)
@@ -62,7 +62,9 @@ if (is_ajax()) {
        $debug and print STDERR "op: " . Dumper($operator) . "\n";
        my ($tag, $js_reply);
        if ($tag = $input->param('test')) {
-               $js_reply = ( is_approved(          $tag) ? 'success' : 'failure') . "_test('$tag');\n";
+               my $check = is_approved($tag);
+               $js_reply = ( $check >=  1 ? 'success' :
+                                         $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('$tag');\n";
        }
        if ($tag = $input->param('ok')) {
                $js_reply = (   whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('$tag');\n";
@@ -102,9 +104,11 @@ $borrowernumber == 0 and push @errors, {op_zero=>1};
 } elsif ($op eq 'test'   ) {
        my $tag = $input->param('test');
        push @tags, $tag;
+       my $check = is_approved($tag);
        $template->param(
                test_term => $tag,
-               (is_approved($tag) ? 'verdict_ok' : 'verdict_rej') => 1,
+               ( $check >=  1 ? 'verdict_ok' :
+                 $check <= -1 ? 'verdict_rej' : 'verdict_indeterminate' ) => 1,
        );
 }