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 var provider = egGridDataProvider.instance({});
38 provider.get = function(offset, count) {
39 var deferred = $q.defer();
41 var query = egZ3950TargetSvc.currentQuery();
42 if (Object.keys(query.search).length == 0) {
46 query['limit'] = count;
47 query['offset'] = offset;
49 var resultIndex = offset;
52 'open-ils.search.z3950.search_class',
56 function() { deferred.resolve() },
59 for (var i in result.records) {
60 result.records[i].mvr['service'] = result.service;
61 result.records[i].mvr['index'] = resultIndex++;
62 result.records[i].mvr['marcxml'] = result.records[i].marcxml;
63 deferred.notify(result.records[i].mvr);
68 return deferred.promise;
71 $scope.z3950SearchGridProvider = provider;
72 $scope.gridControls = {};
74 $scope.search = function() {
75 $scope.z3950SearchGridProvider.refresh();
77 $scope.clearForm = function() {
78 egZ3950TargetSvc.clearSearchFields();
81 var display_form = true;
82 $scope.show_search_form = function() {
85 $scope.toggle_search_form = function() {
86 display_form = !display_form;
89 $scope.showInCatalog = function() {
90 var items = $scope.gridControls.selectedItems();
91 // relying on cant_showInCatalog to protect us
92 var url = egCore.env.basePath +
93 'cat/catalog/record/' + items[0].tcn();
94 $timeout(function() { $window.open(url, '_blank') });
96 $scope.cant_showInCatalog = function() {
97 var items = $scope.gridControls.selectedItems();
98 if (items.length != 1) return true;
99 if (items[0]['service'] == 'native-evergreen-catalog') return false;
103 $scope.import = function() {
104 var deferred = $q.defer();
105 var items = $scope.gridControls.selectedItems();
108 'open-ils.cat.biblio.record.xml.import',
113 function() { deferred.resolve() },
116 console.debug('imported');
120 return deferred.promise;
122 $scope.cant_import = function() {
123 var items = $scope.gridControls.selectedItems();
124 if (items.length == 1) return false;
128 $scope.spawn_editor = function() {
129 var items = $scope.gridControls.selectedItems();
131 templateUrl: './cat/z3950/t_marc_edit',
134 ['$scope', '$modalInstance', function($scope, $modalInstance) {
135 console.debug('calling modal controller');
136 $scope.focusMe = true;
137 $scope.record_id = 0;
138 $scope.dirty_flag = false;
139 $scope.marc_xml = items[0]['marcxml'];
140 $scope.ok = function(args) { $modalInstance.close(args) }
141 $scope.cancel = function () { $modalInstance.dismiss() }
143 }).result.then(function (args) {
144 if (!args || !args.name) return;