my $retriever = $RETRIEVERS{$ret_type};
my $hint = F("acq::$ret_type")->{"hint"};
+ my $select_clause = {
+ $hint => [{"column" => "id", "transform" => "distinct"}]
+ };
+
+ 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
+ # be in the SELECT clause. This will take _one_ such field and add
+ # it to the SELECT clause as needed.
+ my ($order_by, $class, $field);
+ unless (
+ ($order_by = $options->{"order_by"}->[0]) &&
+ ($class = $order_by->{"class"}) =~ /^[\da-z_]+$/ &&
+ ($field = $order_by->{"field"}) =~ /^[\da-z_]+$/
+ ) {
+ $e->disconnect;
+ return new OpenILS::Event(
+ "BAD_PARAMS", "note" =>
+q/order_by clause must be of the long form, like:
+"order_by": [{"class": "foo", "field": "bar", "direction": "asc"}]/
+ );
+ } else {
+ $select_clause->{$class} ||= [];
+ push @{$select_clause->{$class}}, $field;
+ }
+ }
+
my $query = {
- "select" => {$hint => [{"column" => "id", "transform" => "distinct"}]},
+ "select" => $select_clause,
"from" => {
"jub" => {
"acqpo" => {
}
}
},
- "order_by" => {$hint => {"id" => {}}},
+ "order_by" => ($options->{"order_by"} || {$hint => {"id" => {}}}),
"offset" => ($options->{"offset"} || 0)
};
}
my $results = $e->json_query($query) or return $e->die_event;
+ my @id_list = map { $_->{"id"} } (grep { $_->{"id"} } @$results);
+
if ($options->{"id_list"}) {
- $conn->respond($_->{"id"}) foreach (grep { $_->{"id"} } @$results);
+ $conn->respond($_) foreach @id_list;
} else {
- $conn->respond($retriever->($e, $_->{"id"}, $options))
- foreach (grep { $_->{"id"} } @$results);
+ $conn->respond($retriever->($e, $_, $options)) foreach @id_list;
}
$e->disconnect;
"disabled": "disabled",
"selected": "selected",
"value": "",
- "innerHTML": "Select Search Field" // XXX i18n
+ "innerHTML": localeStrings.SELECT_SEARCH_FIELD
})
);
"&c=" + dojo.byId("acq-unified-conjunction").getValue();
};
- this.search = function(search_object, termManager) {
+ this.search = function(uriManager, termManager) {
var bib_search_string = null;
this.count_results = 0;
this.result_type = dojo.byId("acq-unified-result-type").getValue();
this.params[
dojo.byId("acq-unified-conjunction").getValue() == "and" ? 1 : 2
- ] = search_object;
+ ] = uriManager.search_object;
+ if (uriManager.order_by)
+ this.params[4].order_by = uriManager.order_by;
var interface = this.result_types[this.result_type].interface;
interface.dataLoader = this._dataLoader;
]
},
"result_type": "purchase_order",
- "conjunction": "and"
+ "conjunction": "and",
+ "order_by": [
+ {"class": "acqpo", "field": "edit_time", "direction": "desc"}
+ ]
},
"pl": {
"search_object": {
]
},
"result_type": "picklist",
- "conjunction": "and"
+ "conjunction": "and",
+ "order_by": [
+ {"class": "acqpl", "field": "edit_time", "direction": "desc"}
+ ]
},
"inv": {
"search_object": {
]
},
"result_type": "invoice",
- "conjunction": "and"
+ "conjunction": "and",
+ "order_by": [
+ {"class": "acqinv", "field": "recv_date", "direction": "desc"}
+ ]
}
};
hideForm();
openils.Util.show("acq-unified-body");
termManager.reflect(uriManager.search_object);
- resultManager.search(uriManager.search_object, termManager);
+ resultManager.search(uriManager, termManager);
} else {
termManager.addRow();
openils.Util.show("acq-unified-body");