[open-ils-commits] r16397 - in trunk/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/ui/default/acq/search web/templates/default/acq/search (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu May 6 12:44:24 EDT 2010


Author: senator
Date: 2010-05-06 12:44:21 -0400 (Thu, 06 May 2010)
New Revision: 16397

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
   trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
   trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
Log:
Acq: improvements to lineitem + bib search in unified search UI


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-05-06 16:04:38 UTC (rev 16396)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-05-06 16:44:21 UTC (rev 16397)
@@ -4,6 +4,7 @@
 use strict;
 use warnings;
 
+use OpenSRF::AppSession;
 use OpenILS::Event;
 use OpenILS::Utils::CStoreEditor q/:funcs/;
 use OpenILS::Utils::Fieldmapper;
@@ -476,34 +477,39 @@
 
     my $count = 0;
     my $picklist;
+    my @li_ids = ();
     while (my $resp = $req->recv("timeout" => 60)) {
         $picklist = OpenILS::Application::Acq::Order::zsearch_build_pl(
             $mgr, undef # XXX could have per-user name for temp picklist here?
         ) unless $count++;
 
         my $result = $resp->content;
+        next if not ref $result;
 
         # The result object contains a whole heck of a lot more information
         # than just bib IDs, so maybe we could tell the client something
         # useful (progress meter at least) in the future...
-        foreach my $id (@{$result->{"ids"}}) {
-            $id = $id->[0];
-            $conn->respond(
-                $RETRIEVERS{"lineitem"}->(
-                    $e, OpenILS::Application::Acq::Order::create_lineitem(
-                        $mgr,
-                        "picklist" => $picklist->id,
-                        "source_label" => $resp->content->{"service"},
-                        "marc" => $e->retrieve_biblio_record_entry($id)->marc,
-                        "eg_bib_id" => $id
-                    )->id, $options
-                )
-            );
-        }
+        push @li_ids, map {
+            my $bib = $_->[0];
+            OpenILS::Application::Acq::Order::create_lineitem(
+                $mgr,
+                "picklist" => $picklist->id,
+                "source_label" => "native-evergreen-catalog",
+                "marc" => $e->retrieve_biblio_record_entry($bib)->marc,
+                "eg_bib_id" => $bib
+            )->id;
+        } (@{$result->{"ids"}});
     }
 
+    $e->commit;
     $ses->disconnect;
-    $e->commit;
+
+    # new editor, no transaction needed this time
+    $e = new_editor("authtoken" => $auth) or return $e->die_event;
+    return $e->die_event unless $e->checkauth;
+    $conn->respond($RETRIEVERS{"lineitem"}->($e, $_, $options)) foreach @li_ids;
+    $e->disconnect;
+
     undef;
 }
 

Modified: trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-05-06 16:04:38 UTC (rev 16396)
+++ trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-05-06 16:44:21 UTC (rev 16397)
@@ -82,9 +82,7 @@
     var selectorMethods = {
         /* Important: within the following functions, "this" refers to one
          * HTMLSelect object, and "self" refers to the TermSelectorFactory. */
-        "getTerm": function() {
-            return this.valueToTerm(this.getValue());
-        },
+        "getTerm": function() { return this.valueToTerm(this.getValue()); },
         "valueToTerm": function(value) {
             var parts = value.split(":");
             if (!parts || parts.length != 2) return null;
@@ -315,9 +313,10 @@
         });
     };
 
-    this.matchHowAllow = function(id, what, which) {
+    this.matchHowAllow = function(where, what, which, exact) {
         dojo.query(
-            "option[value*='" + what + "']", this._match_how(id)
+            "option[value" + (exact ? "" : "*") + "='" + what + "']",
+            typeof(where) == "object" ? where : this._match_how(where)
         ).forEach(function(o) { o.disabled = !which; });
     };
 
@@ -346,13 +345,15 @@
             /* Re-enable all non-bib-friendly fields in all search term
              * field selectors. */
             this.allRowIds().forEach(
-                function(id) { self._selector(id).onlyBibFriendly(false); }
+                function(id) {
+                    self._selector(id).onlyBibFriendly(false);
+                    self.matchHowAllow(id, "", true, /* exact */ true);
+                    self.matchHowAllow(id, "__not", true, /* exact */ true);
+                }
             );
             /* Tell the selector factory to create new search term field
              * selectors with all fields, not just bib-friendly ones. */
             this.selectorFactory.onlyBibFriendly = false;
-            /* Allow either "any" or "all" searching. */
-            dojo.byId("acq-unified-conjunction").options[1].disabled = false;
         } else if (
             this.lastResultType != "lineitem_and_bib" &&
             resultType == "lineitem_and_bib"
@@ -370,15 +371,15 @@
             /* Disable all non-bib-friendly fields in all remaining search term
              * field selectors. */
             this.allRowIds().forEach(
-                function(id) { self._selector(id).onlyBibFriendly(true); }
+                function(id) {
+                    self._selector(id).onlyBibFriendly(true);
+                    self.matchHowAllow(id, "", false, /* exact */ true);
+                    self.matchHowAllow(id, "__not", false, /* exact */ true);
+                }
             );
             /* Tell the selector factory to create new search term field
              * selectors with only bib friendly options. */
             this.selectorFactory.onlyBibFriendly = true;
-            /* Force an "any" search; I'm not sure we can do "all"
-             * searches yet. */
-            dojo.byId("acq-unified-conjunction").selectedIndex = 0;
-            dojo.byId("acq-unified-conjunction").options[1].disabled = true;
         }
         this.lastResultType = resultType;
     };
@@ -444,6 +445,19 @@
             }
         );
 
+        /* Kind of inelegant; could be improved: this section turns off
+         * match-type options that don't apply to bib searching. */
+        this.matchHowAllow(
+            match_how, "",
+            !this.selectorFactory.onlyBibFriendly, /* exact */ true
+        );
+        this.matchHowAllow(
+            match_how, "__not",
+            !this.selectorFactory.onlyBibFriendly, /* exact */ true
+        );
+        if (this.selectorFactory.onlyBibFriendly)
+            match_how.setValue("__fuzzy");
+
         nodeByName("selector", row).appendChild(selector);
         nodeByName("remove", row).appendChild(this.removerButton(uniq));
 
@@ -517,18 +531,31 @@
     };
 
     this.buildBibSearchString = function() {
+        var conj = {"and": " ", "or": " || "}[
+            dojo.byId("acq-unified-conjunction").getValue()
+        ];
+
         var sso = {};
+        /* Notice that below we use conj in two places and a constant " || "
+         * in one. That constant " || " is applied for the "file of terms"
+         * search term type, which is in itself always an or search. */
         for (var id in this.widgets) {
             var term = this._selector(id).getTerm();
             var attr = term.bib_attr_name;
+            var match_how = this._match_how(id).getValue();
+            var widget = this.widgets[id];
 
             if (!sso[attr]) sso[attr] = [];
-            sso[attr].push(this.widgets[id].value);
+            sso[attr].push(
+                (match_how.indexOf("__not") == -1 ? "" : "-") +
+                (typeof(widget.attr) == "function" ?
+                    widget.attr("value").join(" || ") : widget.value)
+            );
         }
         var ssa = [];
         for (var attr in sso)
-            ssa.push(attr + ": " + sso[attr].join(" || "));
-        return ssa.join(" || ");
+            ssa.push(attr + ": " + sso[attr].join(conj));
+        return ssa.join(conj);
     };
 }
 
@@ -654,7 +681,6 @@
 
     this.search = function(search_object, bib_search_string) {
         var count_results = 0;
-        var tasks = 1;
         var bibs_too = false;
         var result_type = dojo.byId("acq-unified-result-type").getValue();
         var conjunction = dojo.byId("acq-unified-conjunction").getValue();
@@ -662,15 +688,12 @@
         /* lineitem_and_bib: a special case */
         if (result_type == "lineitem_and_bib") {
             result_type = "lineitem";
-            tasks++;
             bibs_too = true;
         }
 
         function result_completion() {
-            if (!count_results)
-                self.show("no_results");
-            else
-                self.finish(result_type);
+            if (!count_results) self.show("no_results");
+            else self.finish(result_type);
         }
 
         var method_name = "open-ils.acq." + result_type + ".unified_search";
@@ -698,34 +721,34 @@
                     }
                 },
                 "oncomplete": function() {
-                    if (tasks > 1) tasks--;
-                    else result_completion();
+                    if (bibs_too) {
+                        fieldmapper.standardRequest(
+                            ["open-ils.acq",
+                                "open-ils.acq.biblio.wrapped_search"], {
+                                "params": [
+                                    openils.User.authtoken,
+                                    bib_search_string,
+                                    self.result_types.lineitem.search_options
+                                ],
+                                "async": true,
+                                "onresponse": function(r) {
+                                    if (r = openils.Util.readResponse(r)) {
+                                        if (!count_results++)
+                                            self.show("lineitem");
+                                        self.add("lineitem", r);
+                                    }
+                                },
+                                "oncomplete": function() {
+                                    result_completion();
+                                }
+                            }
+                        );
+                    } else {
+                        result_completion();
+                    }
                 }
             }
         );
-
-        if (bibs_too) {
-            fieldmapper.standardRequest(
-                ["open-ils.acq", "open-ils.acq.biblio.wrapped_search"], {
-                    "params": [
-                        openils.User.authtoken,
-                        bib_search_string,
-                        this.result_types.lineitem.search_options
-                    ],
-                    "async": true,
-                    "onresponse": function(r) {
-                        if (r = openils.Util.readResponse(r)) {
-                            if (!count_results++) self.show("lineitem");
-                            self.add("lineitem", r);
-                        }
-                    },
-                    "oncomplete": function() {
-                        if (tasks > 1) tasks--;
-                        else result_completion();
-                    }
-                }
-            );
-        }
     }
 }
 

Modified: trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-05-06 16:04:38 UTC (rev 16396)
+++ trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-05-06 16:44:21 UTC (rev 16397)
@@ -146,11 +146,11 @@
                                 <option value="">is</option>
                                 <option value="__not">is NOT</option>
                                 <option value="__fuzzy" disabled="disabled">
-                                    contains the term
+                                    contains
                                 </option>
                                 <option value="__not,__fuzzy"
                                     disabled="disabled">
-                                    does NOT contain the term
+                                    does NOT contain
                                 </option>
                                 <option value="__lte" disabled="disabled">
                                     is on or BEFORE



More information about the open-ils-commits mailing list