From 113bf0adb015cb7a60cb75fe13ab89066cb0c4d2 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 16 Jul 2015 18:17:04 +0000 Subject: [PATCH] Z39.50 webstaff WIP: more functionality and fixes * check for empty query correctly * retain reference to target list * preserve search query input when toggling Z39.50 target selection * implement clear form handler * allow enter key to submit search * track index of Z39.50 results so that individual ones can be selected * note results of experiences to make the title be conditionally a hyperlink * implement show in catalog * implement direct import --- Open-ILS/src/templates/staff/cat/z3950/t_list.tt2 | 13 ++++++ .../web/js/ui/default/staff/cat/services/z3950.js | 13 +++++- Open-ILS/web/js/ui/default/staff/cat/z3950/app.js | 53 ++++++++++++++++++++-- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/z3950/t_list.tt2 b/Open-ILS/src/templates/staff/cat/z3950/t_list.tt2 index 0158c45e38..dcd5840f15 100644 --- a/Open-ILS/src/templates/staff/cat/z3950/t_list.tt2 +++ b/Open-ILS/src/templates/staff/cat/z3950/t_list.tt2 @@ -1,7 +1,9 @@
[% l('Query') %] +
+
[% l('Service and Credentials') %] @@ -30,6 +32,17 @@ grid-controls="gridControls" persist-key="cat.z3950_results"> + + + + diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/z3950.js b/Open-ILS/web/js/ui/default/staff/cat/services/z3950.js index 9cd97afc35..4ef7e70fac 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/z3950.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/z3950.js @@ -14,7 +14,8 @@ function($q, egCore, egAuth) { 'open-ils.search.z3950.retrieve_services', egAuth.token() ).then(function(res) { - service.targets = []; + // keep the reference, just clear the list + service.targets.length = 0; // native Evergreen search goes first var localTarget = res['native-evergreen-catalog']; delete res['native-evergreen-catalog']; @@ -46,7 +47,9 @@ function($q, egCore, egAuth) { // don't want to throw away the reference, otherwise // directives bound to searchFields won't // refresh + var curFormInput = {}; for (var field in service.searchFields) { + curFormInput[field] = service.searchFields[field].query; delete service.searchFields[field]; } angular.forEach(service.targets, function(target, idx) { @@ -54,13 +57,19 @@ function($q, egCore, egAuth) { angular.forEach(target.settings.attrs, function(attr, key) { if (!(key in service.searchFields)) service.searchFields[key] = { label : attr.label, - query : '' + query : (key in curFormInput) ? curFormInput[key] : '' }; }); } }); }; + service.clearSearchFields = function() { + for (var field in service.searchFields) { + service.searchFields[field].query = ''; + } + } + // return the selected Z39.50 targets and search strings // in a format suitable for passing directly to // open-ils.search.z3950.search_class diff --git a/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js b/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js index 1e63d4e084..8a6d7d6688 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js @@ -26,8 +26,8 @@ angular.module('egCatZ3950Search', * List view - grid stuff */ .controller('Z3950SearchCtrl', - ['$scope','$q','$location','$timeout','egCore','egGridDataProvider','egZ3950TargetSvc', -function($scope , $q , $location , $timeout , egCore , egGridDataProvider, egZ3950TargetSvc ) { + ['$scope','$q','$location','$timeout','$window','egCore','egGridDataProvider','egZ3950TargetSvc', +function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvider, egZ3950TargetSvc ) { // get list of targets egZ3950TargetSvc.loadTargets(); @@ -39,14 +39,14 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider, egZ3 var deferred = $q.defer(); var query = egZ3950TargetSvc.currentQuery(); - console.debug(query); - if (query.search.length == 0) { + if (Object.keys(query.search).length == 0) { return $q.when(); } query['limit'] = count; query['offset'] = offset; + var resultIndex = offset; egCore.net.request( 'open-ils.search', 'open-ils.search.z3950.search_class', @@ -58,6 +58,8 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider, egZ3 function(result) { for (var i in result.records) { result.records[i].mvr['service'] = result.service; + result.records[i].mvr['index'] = resultIndex++; + result.records[i].mvr['marcxml'] = result.records[i].marcxml; deferred.notify(result.records[i].mvr); } } @@ -67,8 +69,51 @@ function($scope , $q , $location , $timeout , egCore , egGridDataProvider, egZ3 }; $scope.z3950SearchGridProvider = provider; + $scope.gridControls = {}; $scope.search = function() { $scope.z3950SearchGridProvider.refresh(); }; + $scope.clearForm = function() { + egZ3950TargetSvc.clearSearchFields(); + }; + + $scope.showInCatalog = function() { + var items = $scope.gridControls.selectedItems(); + // relying on cant_showInCatalog to protect us + var url = egCore.env.basePath + + 'cat/catalog/record/' + items[0].tcn(); + $timeout(function() { $window.open(url, '_blank') }); + }; + $scope.cant_showInCatalog = function() { + var items = $scope.gridControls.selectedItems(); + if (items.length != 1) return true; + if (items[0]['service'] == 'native-evergreen-catalog') return false; + return true; + }; + + $scope.import = function() { + var deferred = $q.defer(); + var items = $scope.gridControls.selectedItems(); + egCore.net.request( + 'open-ils.cat', + 'open-ils.cat.biblio.record.xml.import', + egCore.auth.token(), + items[0]['marcxml'] + // FIXME and more + ).then( + function() { deferred.resolve() }, + null, // onerror + function(result) { + console.debug('imported'); + } + ); + + return deferred.promise; + }; + $scope.cant_import = function() { + var items = $scope.gridControls.selectedItems(); + if (items.length == 1) return false; + return true; + }; }]) -- 2.11.0