Fix some failings of the Triggered Event Viewer
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 22 Jun 2012 21:42:57 +0000 (17:42 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 27 Jul 2012 16:16:25 +0000 (12:16 -0400)
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 <lebbeous@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/templates/actor/user/event_log.tt2
Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js

index 966a991..50cff13 100644 (file)
@@ -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;
index 9f745ca..b5e3d0d 100644 (file)
@@ -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",
     );
 
     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], {
             "store": new dojo.data.ItemFileReadStore({
     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() {
index eb34315..684980d 100644 (file)
@@ -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 {