lp1739286 default search box in Z39.50
authorJason Etheridge <jason@EquinoxInitiative.org>
Tue, 10 Jul 2018 23:46:04 +0000 (19:46 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Wed, 11 Jul 2018 14:48:30 +0000 (10:48 -0400)
This change tweaks the layout of search fields in the web client Z39.50
interface and adds radio buttons for the default search field to auto-focus.
The behavior is "sticky" without the need for an explicit Save action.  If the
current default field is not present due to a given combination of selected
services, then no field will be focused by default.

Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/templates/staff/cat/z3950/t_search_fields.tt2
Open-ILS/web/js/ui/default/staff/cat/services/z3950.js

index 61c74de..782e409 100644 (file)
@@ -1,9 +1,19 @@
 <div class="form-horizontal">
-    <div ng-repeat="search_field in fields | orderObjectBy: 'label'" class="z3950-search-field-list form-group">
-        <label for="z3950-field-{{search_field.key}}" class="col-xs-6 control-label">{{search_field.label}}</label>
-        <div class="col-xs-6">
-            <input type="text" class="form=control" id="z3950-field-{{search_field.key}}" ng-model="search_field.query" ng-if="search_field.key != 'item_type'">
-            <select ng-if="search_field.key == 'item_type'" ng-model="search_field.query">
+    <div class="z3950-search-field-list row">
+        <label class="col-xs-2">[% l('Default') %]</label>
+        <label class="col-xs-3">[% l('Field') %]</label>
+        <label class="col-xs-7">[% l('Value') %]</label>
+    </div>
+    <div ng-repeat="search_field in fields | orderObjectBy: 'label'" class="z3950-search-field-list row">
+        <div class="col-xs-2">
+            <input type="radio" name="default_field" ng-model="default_field" value="{{search_field.key}}" ng-change="save(search_field.key)"/>
+        </div>
+        <div class="col-xs-3">
+            <label for="z3950-field-{{search_field.key}}" class="control-label">{{search_field.label}}</label>
+        </div>
+        <div class="col-xs-7">
+            <input type="text" class="form-control" id="z3950-field-{{search_field.key}}" ng-model="search_field.query" ng-if="search_field.key != 'item_type'" focus-me="default_field == search_field.key"/>
+            <select id="z3950-field-item_type" ng-if="search_field.key == 'item_type'" ng-model="search_field.query" focus-me="default_field == 'item_type'">
                 <option value="">[% l('All Formats') %]</option>
                 <option value='art'>[% l('Papers or Articles') %]</option>
                 <option value='bks'>[% l('Books') %]</option>
index 918de4b..065b4e6 100644 (file)
@@ -140,6 +140,18 @@ function($q,   egCore,   egAuth) {
         egCore.hatch.setLocalItem('eg.cat.z3950.default_targets', saved_targets);
     }
 
+    // store default field
+    service.saveDefaultField = function(default_field) {
+        console.log('saveDefaultField',default_field);
+        egCore.hatch.setLocalItem('eg.cat.z3950.default_field', default_field);
+    }
+
+    service.fetchDefaultField = function() {
+        var default_field = egCore.hatch.getLocalItem('eg.cat.z3950.default_field') || 'isbn';
+        console.log('fetchDefaultField',default_field);
+        return default_field;
+    }
+
     return service;
 }])
 .directive("egZ3950TargetList", function () {
@@ -169,6 +181,13 @@ function($q,   egCore,   egAuth) {
             templateUrl: './cat/z3950/t_search_fields',
             link: function(scope, elem, attr) {
                 scope.fields = egZ3950TargetSvc.searchFields;
+                scope.default_field = egZ3950TargetSvc.fetchDefaultField();
+                scope.$watch('default_field', function(oldVal, newVal) {
+                    egZ3950TargetSvc.saveDefaultField(newVal);
+                }, true);
+                scope.save = function(v) { // FIXME - should be able to do this through $watch instead of ng-change
+                    egZ3950TargetSvc.saveDefaultField(v);
+                }
             }
         };
     }