<div class="row">
<div class="col-xs-6">
<strong>[% l('Query') %]</strong>
+ <form ng-keyup="$event.keyCode == 13 && search()">
<eg-z3950-search-field-list></eg-z3950-search-field-list>
+ </form>
</div>
<div class="col-xs-6">
<strong>[% l('Service and Credentials') %]</strong>
grid-controls="gridControls"
persist-key="cat.z3950_results">
+ <eg-grid-menu-item handler="showInCatalog" disabled="cant_showInCatalog"
+ label="[% l('Show in Catalog') %]"></eg-grid-menu>
+ <eg-grid-menu-item handler="import" disabled="cant_import"
+ label="[% l('Import') %]"></eg-grid-menu>
+
+ <!--
+ FIXME: it would be nice to make this column link
+ to record display page when the service is
+ 'native-evergreen-catalog', but can't do ng-if
+ inside of column value templates at the moment
+ -->
<eg-grid-field label="[% l('Title') %]" path="title" visible></eg-grid-field>
<eg-grid-field label="[% l('Author') %]" path="author" visible></eg-grid-field>
<eg-grid-field label="[% l('Edition') %]" path="edition" visible></eg-grid-field>
'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'];
// 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) {
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
* 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();
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',
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);
}
}
};
$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;
+ };
}])