From 6517e6fbeb80601a8aab8478484f6dbd22e3b001 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Fri, 22 Jun 2012 17:42:57 -0400 Subject: [PATCH] Fix some failings of the Triggered Event Viewer 1) give choices in a dropdown for the Reactor field 2) like searching automatically wraps search terms in % except when at least one % is already present. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Mike Rylander --- .../perlmods/lib/OpenILS/Application/Actor.pm | 39 +++++++++++++++++++ .../src/templates/actor/user/event_log.tt2 | 26 ++++++++++++- .../js/dojo/openils/widget/PCrudFilterPane.js | 14 ++++++- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 966a991602..50cff13551 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -4605,4 +4605,43 @@ sub mark_users_contact_invalid { ); } +# Putting the following method in open-ils.actor is a bad fit, except in that +# it serves an interface that lives under 'actor' in the templates directory, +# and in that there's nowhere else obvious to put it (open-ils.trigger is +# private). +__PACKAGE__->register_method( + api_name => "open-ils.actor.action_trigger.reactors.all_in_use", + method => "get_all_at_reactors_in_use", + api_level=> 1, + argc => 1, + signature=> { + params => [ + { name => 'authtoken', type => 'string' } + ], + return => { + desc => 'list of reactor names', type => 'array' + } + } +); + +sub get_all_at_reactors_in_use { + my ($self, $conn, $auth) = @_; + + my $e = new_editor(authtoken => $auth); + $e->checkauth or return $e->die_event; + return $e->die_event unless $e->allowed('VIEW_TRIGGER_EVENT_DEF'); + + my $reactors = $e->json_query({ + select => { + atevdef => [{column => "reactor", transform => "distinct"}] + }, + from => {atevdef => {}} + }); + + return $e->die_event unless ref $reactors eq "ARRAY"; + $e->disconnect; + + return [ map { $_->{reactor} } @$reactors ]; +} + 1; diff --git a/Open-ILS/src/templates/actor/user/event_log.tt2 b/Open-ILS/src/templates/actor/user/event_log.tt2 index 9f745caebd..b5e3d0d6aa 100644 --- a/Open-ILS/src/templates/actor/user/event_log.tt2 +++ b/Open-ILS/src/templates/actor/user/event_log.tt2 @@ -51,6 +51,8 @@ grid.filterUi.doApply(); } + var _reactors_cache; + /* This and its subclasses exist because *FilterPane expect things that act like AutoFieldWidget, which is a widget /builder/. */ dojo.declare( @@ -66,7 +68,7 @@ "build": function() { var dijitArgs = dojo.mixin( { - "store": this.store, + "store": this.store || this.storeBuilder(), "query": {}, "labelAttr": "label", "searchAttr": "label", @@ -79,6 +81,27 @@ } ); + dojo.declare( + "openils.widget._FSBuilder.Reactor", + [openils.widget._FSBuilder], { + "storeBuilder": function() { + _reactors_cache = _reactors_cache || + fieldmapper.standardRequest( + ["open-ils.actor", "open-ils.actor.action_trigger.reactors.all_in_use"], + { "params": [openils.User.authtoken] } + ).sort(); + return new dojo.data.ItemFileReadStore({ + "data": { + "identifier": "name", + "items": _reactors_cache.map( + function(o) { return {"name": o, "label": o}; } + ) + } + }); + } + } + ); + dojo.declare( "openils.widget._FSBuilder.CoreType", [openils.widget._FSBuilder], { @@ -132,6 +155,7 @@ var filter_widget_builders = { "ath:core_type": openils.widget._FSBuilder.CoreType, "atul:state": openils.widget._FSBuilder.EventState, + "atul:reactor": openils.widget._FSBuilder.Reactor, }; function print_all() { diff --git a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js index eb34315076..684980dabf 100644 --- a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js @@ -486,6 +486,11 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { return; }; + /* wrap s in %'s unless it already contains at least one %. */ + this._add_like_wildcards = function(s) { + return s.indexOf("%") == -1 ? ("%" + s + "%") : s; + }; + this.get_selected_operator = function() { if (this.operator_selector) return this.operator_selector.item; @@ -538,10 +543,15 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { } else { var clause = {}; var op = this.get_selected_operator_name(); + + var prep_function = function(o) { return o; /* no-op */ }; + if (String(op).match(/like/)) + prep_function = this._add_like_wildcards; + if (values.length == 1) - clause[op] = values.pop(); + clause[op] = prep_function(values.pop()); else - clause[op] = values; + clause[op] = dojo.map(values, prep_function); return clause; } } else { -- 2.43.2