webstaff: implement saving default Z39.50 targets
authorGalen Charlton <gmc@esilibrary.com>
Tue, 8 Sep 2015 16:07:36 +0000 (16:07 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:20 +0000 (15:44 -0400)
Also make the target password input field's type be
"password".

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/z3950/t_list.tt2
Open-ILS/src/templates/staff/cat/z3950/t_target.tt2
Open-ILS/web/js/ui/default/staff/cat/services/z3950.js
Open-ILS/web/js/ui/default/staff/cat/z3950/app.js

index 86292c9..5e2ab8b 100644 (file)
     </div>
     <div class="col-xs-6">
         <strong>[% l('Service and Credentials') %]</strong>
-        <eg-z3950-target-list ng-show="show_search_form()">
+        <eg-z3950-target-list ng-show="show_search_form()"></eg-z3950-target-list>
+        <div class="button-group">
+            <button class="btn btn-default" ng-click="saveDefaultZ3950Targets()">
+                [% l('Save as Default') %]
+            </button>
+        </div>
     </div>
 </div>
 
index 9365ec2..17ca475 100644 (file)
@@ -11,7 +11,7 @@
         </div>
         <div class="form-group col-xs-6">
             <label for="password-for-z3950-{{target.code}}">[% l('Password') %]</label>
-            <input type="text" class="form-control" id="password-for-z3950-{{target.code}}" ng-model="target.password">
+            <input type="password" class="form-control" id="password-for-z3950-{{target.code}}" ng-model="target.password">
         </div>
     </div>
 </div>
index 45969be..9e4b8ff 100644 (file)
@@ -10,6 +10,7 @@ function($q,   egCore,   egAuth) {
     };
     
     service.loadTargets = function() {
+        var default_targets = egCore.hatch.getLocalItem('eg.cat.z3950.default_targets');
         egCore.net.request(
             'open-ils.search',
             'open-ils.search.z3950.retrieve_services',
@@ -21,13 +22,18 @@ function($q,   egCore,   egAuth) {
             var localTarget = res['native-evergreen-catalog'];
             delete res['native-evergreen-catalog'];
             angular.forEach(res, function(value, key) {
-                this.push({
+                var tgt = {
                     code:       key,
                     settings:   value,
-                    selected:   false,
+                    selected:   (key in default_targets),
                     username:   '',
                     password:   ''
-                });
+                };
+                if (tgt.code in default_targets && tgt.settings.auth == 't') {
+                    tgt['username'] = default_targets[tgt.code]['username'] || '';
+                    tgt['password'] = default_targets[tgt.code]['password'] || '';
+                }
+                this.push(tgt);
             }, service.targets);
             service.targets.sort(function (a, b) {
                 a = a.settings.label;
@@ -37,7 +43,7 @@ function($q,   egCore,   egAuth) {
             service.targets.unshift({
                 code:       'native-evergreen-catalog',
                 settings:   localTarget,
-                selected:   false,
+                selected:   ('native-evergreen-catalog' in default_targets),
                 username:   '',
                 password:   ''
             });
@@ -119,6 +125,21 @@ function($q,   egCore,   egAuth) {
         service.raw_search = raw_search;
     }
 
+    // store selected targets
+    service.saveDefaultZ3950Targets = function() {
+        var saved_targets = {};
+        angular.forEach(service.targets, function(target, idx) {
+            if (target.selected) {
+                saved_targets[target.code] = {};
+            }
+            if (target.settings.auth == 't') {
+                saved_targets[target.code]['username'] = target.username;
+                saved_targets[target.code]['password'] = target.password;
+            }
+        }); 
+        egCore.hatch.setLocalItem('eg.cat.z3950.default_targets', saved_targets);
+    }
+
     return service;
 }])
 .directive("egZ3950TargetList", function () {
index 5476c71..3d8d9d1 100644 (file)
@@ -131,6 +131,10 @@ function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvi
         egZ3950TargetSvc.clearSearchFields();
     };
 
+    $scope.saveDefaultZ3950Targets = function() {
+        egZ3950TargetSvc.saveDefaultZ3950Targets();
+    }
+
     var display_form = true;
     $scope.show_search_form = function() {
         return display_form;