Acq: in acquistions unified search, make timestamp fields searchable
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Apr 2010 19:36:51 +0000 (19:36 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Apr 2010 19:36:51 +0000 (19:36 +0000)
Even if only at whole-day precision

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16159 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
Open-ILS/web/js/ui/default/acq/search/unified.js

index 5090c53..fb74708 100644 (file)
@@ -44,6 +44,8 @@ sub could_be_range {
     0;
 }
 
+sub castdate { +{"=" => {"transform" => "date", "value" => $_[0]}}; }
+
 sub prepare_acqlia_search_and {
     my ($acqlia) = @_;
 
@@ -55,6 +57,7 @@ sub prepare_acqlia_search_and {
             "where" => {"-and" => [{"lineitem" => {"=" => {"+jub" => "id"}}}]}
         };
 
+        # castdate not supported for acqlia fields: they're all type text
         my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
         my $point = $subquery->{"where"}->{"-and"};
         my $term_clause;
@@ -84,6 +87,7 @@ sub prepare_acqlia_search_or {
     my $result = {"+acqlia" => {"-or" => $point}};
 
     foreach my $unit (@$acqlia) {
+        # castdate not supported for acqlia fields: they're all type text
         my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
         my $term_clause;
         if ($fuzzy and not ref $v) {
@@ -120,7 +124,8 @@ sub breakdown_term {
         $key, $term->{$key},
         $term->{"__fuzzy"} ? 1 : 0,
         $term->{"__between"} ? 1 : 0,
-        $term->{"__not"} ? 1 : 0
+        $term->{"__not"} ? 1 : 0,
+        $term->{"__castdate"} ? 1 : 0
     );
 }
 
@@ -208,13 +213,16 @@ sub prepare_terms {
 
         $outer_clause->{$conj} = [] unless $outer_clause->{$conj};
         foreach my $unit (@{$terms->{$class}}) {
-            my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
+            my ($k, $v, $fuzzy, $between, $not, $castdate) =
+                breakdown_term($unit);
+
             my $term_clause;
             if ($fuzzy and not ref $v) {
                 $term_clause = {$k => {"ilike" => "%" . $v . "%"}};
             } elsif ($between and could_be_range($v)) {
                 $term_clause = {$k => {"between" => $v}};
             } elsif (check_1d_max($v)) {
+                $v = castdate($v) if $castdate;
                 $term_clause = {$k => $v};
             } else {
                 next;
index 4f19542..0686e82 100644 (file)
@@ -1,3 +1,4 @@
+dojo.require("dojo.date.stamp");
 dojo.require("openils.widget.AutoGrid");
 dojo.require("openils.widget.AutoWidget");
 dojo.require("openils.PermaCrud");
@@ -276,17 +277,26 @@ function TermManager() {
                 this._match_how(id).getValue().split(",").filter(Boolean);
 
             var value;
-            try {
-                value = this.widgets[id].attr("value");
-            } catch (E) {
+            if (typeof(this.widgets[id].declaredClass) != "undefined") {
+                if (this.widgets[id].declaredClass.match(/Date/)) {
+                    value =
+                        dojo.date.stamp.toISOString(this.widgets[id].value).
+                            split("T")[0];
+                } else {
+                    value = this.widgets[id].attr("value");
+                }
+            } else {
                 value = this.widgets[id].value;
             }
 
             if (!so[hint])
                 so[hint] = [];
+
             var unit = {};
-            match_how.forEach(function(key) { unit[key] = true; });
             unit[attr] = value;
+            match_how.forEach(function(key) { unit[key] = true; });
+            if (this.terms[hint][attr].datatype == "timestamp")
+                unit.__castdate = true;
 
             so[hint].push(unit);
         }