lp1739286 default search box in Z39.50
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / services / z3950.js
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);
+                }
             }
         };
     }