acq invoice : sort by title
authorBill Erickson <berick@esilibrary.com>
Tue, 31 Jul 2012 17:43:15 +0000 (13:43 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 31 Jul 2012 17:43:15 +0000 (13:43 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm
Open-ILS/src/templates/acq/invoice/view.tt2
Open-ILS/web/js/ui/default/acq/invoice/view.js
Open-ILS/web/js/ui/default/acq/search/unified.js

index d924e4c..da594a2 100644 (file)
@@ -425,6 +425,7 @@ sub unified_search {
         $hint => [{"column" => "id", "transform" => "distinct"}]
     };
 
+    my $attr_from_filter;
     if ($options->{"order_by"}) {
         # What's the point of this block?  When using ORDER BY in conjuction
         # with SELECT DISTINCT, the fields present in ORDER BY have to also
@@ -442,9 +443,30 @@ sub unified_search {
 q/order_by clause must be of the long form, like:
 "order_by": [{"class": "foo", "field": "bar", "direction": "asc"}]/
             );
+
         } else {
+
+            # we can't combine distinct(id) with another select column, 
+            # since the non-distinct column may arbitrarily (via hash keys)
+            # sort to the front of the final SQL, which PG will complain about.  
+            $select_clause = { $hint => ["id"] };
             $select_clause->{$class} ||= [];
-            push @{$select_clause->{$class}}, $field;
+            push @{$select_clause->{$class}}, 
+                {column => $field, transform => 'first', aggregate => 1};
+
+            # when sorting by LI attr values, we have to limit 
+            # to a specific type of attr value to sort on.
+            if ($class eq 'acqlia') {
+                $attr_from_filter = {
+                    "fkey" => "id",
+                    "filter" => {
+                        "attr_type" => "lineitem_marc_attr_definition",
+                        "attr_name" => $options->{"order_by_attr"} || "title"
+                    },
+                    "type" => "left",
+                    "field" =>"lineitem"
+                };
+            }
         }
     }
 
@@ -479,6 +501,14 @@ q/order_by clause must be of the long form, like:
         return new OpenILS::Event("BAD_PARAMS", "desc" => "No usable terms");
     }
 
+
+    # if ordering by acqlia, insert the from clause 
+    # filter to limit to one type of attr.
+    if ($attr_from_filter) {
+        $query->{from}->{jub} = {} unless $query->{from}->{jub};
+        $query->{from}->{jub}->{acqlia} = $attr_from_filter;
+    }
+
     my $results = $e->json_query($query) or return $e->die_event;
     my @id_list = map { $_->{"id"} } (grep { $_->{"id"} } @$results);
 
index 59c5bb0..add14fc 100644 (file)
                                 </button>
                             </td>
                             <td align='right'>
+                                <input type='checkbox' id='acq-invoice-search-sort-title'/>
+                                [% l('Sort by title') %]
+                                <span style='padding-left:8px;'>
                                 <input type='checkbox' id='acq-invoice-search-limit-invoiceable' checked='checked'/>
                                 [% l('Limit to Invoiceable Items') %]
                             </td>
index 3848b22..28d82ff 100644 (file)
@@ -277,6 +277,11 @@ function performSearch() {
         }
     }
 
+    if (dojo.byId('acq-invoice-search-sort-title').checked) {
+        uriManager.order_by = 
+            [ {"class": "acqlia", "field":"attr_value", "transform":"first"} ];
+    }
+
     resultManager.go(searchObject)
     console.log('Lineitem Search: ' + js2JSON(searchObject));
     focusLastSearchInput();
@@ -291,6 +296,7 @@ function renderUnifiedSearch() {
         termManager = new TermManager();
         resultManager = new ResultManager();
         resultsLoader = new searchResultsLoader();
+        uriManager = new URIManager();
 
         // define custom lineitem result handler
         resultManager.result_types = {
index bf73d61..2c1eff0 100644 (file)
@@ -800,7 +800,7 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) {
         if (window.unifiedSearchExternalMode) {
             // assume for now that external mode implies inline results display
             
-            uriManager = new URIManager();
+            uriManager = uriManager || new URIManager();
             uriManager.search_object = search_object;
             uriManager.result_type = dojo.byId("acq-unified-result-type").getValue();
             uriManager.conjunction = dojo.byId("acq-unified-conjunction").getValue();