2 * Z39.50 search and import
5 angular.module('egCatZ3950Search',
6 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod', 'egZ3950Mod', 'egMarcMod'])
8 .config(function($routeProvider, $locationProvider, $compileProvider) {
9 $locationProvider.html5Mode(true);
10 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
12 var resolver = {delay : function(egStartup) {return egStartup.go()}};
14 // search page shows the list view by default
15 $routeProvider.when('/cat/z3950/search', {
16 templateUrl: './cat/z3950/t_list',
17 controller: 'Z3950SearchCtrl',
21 // default page / bucket view
22 $routeProvider.otherwise({redirectTo : '/cat/z3950/search'});
26 * List view - grid stuff
28 .controller('Z3950SearchCtrl',
29 ['$scope','$q','$location','$timeout','$window','egCore','egGridDataProvider','egZ3950TargetSvc','$modal',
30 function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvider, egZ3950TargetSvc, $modal) {
32 // get list of targets
33 egZ3950TargetSvc.loadTargets();
34 egZ3950TargetSvc.loadActiveSearchFields();
36 $scope.field_strip_groups = [];
37 egCore.startup.go().then(function() {
38 // and list of field strip groups; need to ensure
39 // that enough of the startup has happened so that
40 // we have the user WS
41 egCore.pcrud.search('vibtg',
49 transform : 'actor.org_unit_ancestors',
55 id : egCore.auth.user().ws_ou()
60 { order_by : { vibtq : ['label'] } }
61 ).then(null, null, function(strip_group) {
62 strip_group.selected = false;
63 $scope.field_strip_groups.push(strip_group);
67 $scope.total_hits = 0;
69 var provider = egGridDataProvider.instance({});
71 provider.get = function(offset, count) {
72 var deferred = $q.defer();
74 var query = egZ3950TargetSvc.currentQuery();
75 if (!query.raw_search && Object.keys(query.search).length == 0) {
79 var method = query.raw_search ?
80 'open-ils.search.z3950.search_service' :
81 'open-ils.search.z3950.search_class';
83 if (query.raw_search) {
84 query.query = query.raw_search;
85 delete query['search'];
86 delete query['raw_search'];
87 query.service = query.service[0];
88 query.username = query.username[0];
89 query.password = query.password[0];
92 query['limit'] = count;
93 query['offset'] = offset;
95 var resultIndex = offset;
96 $scope.total_hits = 0;
97 $scope.searchInProgress = true;
104 function() { $scope.searchInProgress = false; deferred.resolve() },
107 // FIXME when the search offset is > 0, the
108 // total hits count can be wrong if one of the
109 // Z39.50 targets has fewer than $offset hits; in that
110 // case, result.count is not supplied.
111 $scope.total_hits += (result.count || 0);
112 for (var i in result.records) {
113 result.records[i].mvr['service'] = result.service;
114 result.records[i].mvr['index'] = resultIndex++;
115 result.records[i].mvr['marcxml'] = result.records[i].marcxml;
116 deferred.notify(result.records[i].mvr);
121 return deferred.promise;
124 $scope.z3950SearchGridProvider = provider;
125 $scope.gridControls = {};
127 $scope.search = function() {
128 $scope.z3950SearchGridProvider.refresh();
130 $scope.clearForm = function() {
131 egZ3950TargetSvc.clearSearchFields();
134 var display_form = true;
135 $scope.show_search_form = function() {
138 $scope.toggle_search_form = function() {
139 display_form = !display_form;
142 $scope.raw_search_impossible = function() {
143 return egZ3950TargetSvc.rawSearchImpossible();
145 $scope.showRawSearchForm = function() {
147 templateUrl: './cat/z3950/t_raw_search',
150 ['$scope', '$modalInstance', function($scope, $modalInstance) {
151 egZ3950TargetSvc.setRawSearch('');
152 $scope.focusMe = true;
153 $scope.ok = function(args) { $modalInstance.close(args) }
154 $scope.cancel = function () { $modalInstance.dismiss() }
156 }).result.then(function (args) {
157 if (!args || !args.raw_search) return;
159 egZ3950TargetSvc.setRawSearch(args.raw_search);
160 $scope.z3950SearchGridProvider.refresh();
164 $scope.showInCatalog = function() {
165 var items = $scope.gridControls.selectedItems();
166 // relying on cant_showInCatalog to protect us
167 var url = egCore.env.basePath +
168 'cat/catalog/record/' + items[0].tcn();
169 $timeout(function() { $window.open(url, '_blank') });
171 $scope.cant_showInCatalog = function() {
172 var items = $scope.gridControls.selectedItems();
173 if (items.length != 1) return true;
174 if (items[0]['service'] == 'native-evergreen-catalog') return false;
178 $scope.local_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0;
179 $scope.mark_as_overlay_target = function() {
180 var items = $scope.gridControls.selectedItems();
181 if ($scope.local_overlay_target == items[0].tcn()) {
182 $scope.local_overlay_target = 0;
184 $scope.local_overlay_target = items[0].tcn();
186 egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.local_overlay_target);
188 $scope.cant_overlay = function() {
189 if (!$scope.local_overlay_target) return true;
190 var items = $scope.gridControls.selectedItems();
191 if (items.length != 1) return true;
193 items[0]['service'] == 'native-evergreen-catalog' &&
194 items[0].tcn() == $scope.local_overlay_target
199 $scope.selectFieldStripGroups = function() {
201 angular.forEach($scope.field_strip_groups, function(grp, idx) {
203 groups.push(grp.id());
208 $scope.import = function() {
209 var deferred = $q.defer();
210 var items = $scope.gridControls.selectedItems();
213 'open-ils.cat.biblio.record.xml.import',
216 null, // FIXME bib source
219 $scope.selectFieldStripGroups()
221 function() { deferred.resolve() },
224 console.debug('imported');
228 return deferred.promise;
230 $scope.need_one_selected = function() {
231 var items = $scope.gridControls.selectedItems();
232 if (items.length == 1) return false;
236 $scope.spawn_editor = function() {
237 var items = $scope.gridControls.selectedItems();
239 templateUrl: './cat/z3950/t_marc_edit',
242 ['$scope', '$modalInstance', function($scope, $modalInstance) {
243 $scope.focusMe = true;
244 $scope.record_id = 0;
245 $scope.dirty_flag = false;
246 $scope.marc_xml = items[0]['marcxml'];
247 $scope.ok = function(args) { $modalInstance.close(args) }
248 $scope.cancel = function () { $modalInstance.dismiss() }
250 }).result.then(function (args) {
251 if (!args || !args.name) return;
255 $scope.view_marc = function() {
256 var items = $scope.gridControls.selectedItems();
258 templateUrl: './cat/z3950/t_marc_html',
261 ['$scope', '$modalInstance', function($scope, $modalInstance) {
262 $scope.focusMe = true;
263 $scope.marc_xml = items[0]['marcxml'];
264 $scope.isbn = (items[0].isbn() || '').replace(/ .*/, '');
265 $scope.ok = function(args) { $modalInstance.close(args) }
266 $scope.cancel = function () { $modalInstance.dismiss() }
268 }).result.then(function (args) {
269 if (!args || !args.name) return;
273 $scope.overlay_record = function() {
274 var items = $scope.gridControls.selectedItems();
275 var overlay_target = $scope.local_overlay_target;
277 'marc_xml' : items[0]['marcxml']
280 templateUrl: './cat/z3950/t_overlay',
283 ['$scope', '$modalInstance', function($scope, $modalInstance) {
284 $scope.focusMe = true;
285 $scope.overlay_target = overlay_target;
287 $scope.ok = function(args) { $modalInstance.close(args) };
288 $scope.cancel = function () { $modalInstance.dismiss() };
289 $scope.editOverlayRecord = function() {
291 templateUrl: './cat/z3950/t_edit_overlay_record',
294 ['$scope', '$modalInstance', function($scope, $modalInstance) {
295 $scope.focusMe = true;
296 $scope.record_id = 0;
297 $scope.dirty_flag = false;
299 $scope.ok = function(args) { $modalInstance.close(args) }
300 $scope.cancel = function () { $modalInstance.dismiss() }
302 }).result.then(function (args) {
303 if (!args || !args.name) return;
307 }).result.then(function (args) {
310 'open-ils.cat.biblio.record.marc.replace',
314 null, // FIXME bib source
316 $scope.selectFieldStripGroups()
319 console.debug('overlay complete');