]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/z3950/app.js
webstaff: Z39.50 search and import interface
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / z3950 / app.js
1 /*
2  * Z39.50 search and import
3  */
4
5 angular.module('egCatZ3950Search',
6     ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod', 'egZ3950Mod'])
7
8 .config(function($routeProvider, $locationProvider, $compileProvider) {
9     $locationProvider.html5Mode(true);
10     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
11
12     var resolver = {delay : function(egStartup) {return egStartup.go()}};
13
14     // search page shows the list view by default
15     $routeProvider.when('/cat/z3950/search', {
16         templateUrl: './cat/z3950/t_list',
17         controller: 'Z3950SearchCtrl',
18         resolve : resolver
19     });
20
21     // default page / bucket view
22     $routeProvider.otherwise({redirectTo : '/cat/z3950/search'});
23 })
24
25 /**
26  * List view - grid stuff
27  */
28 .controller('Z3950SearchCtrl',
29        ['$scope','$q','$location','$timeout','$window','egCore','egGridDataProvider','egZ3950TargetSvc',
30 function($scope , $q , $location , $timeout , $window,  egCore , egGridDataProvider,  egZ3950TargetSvc ) {
31
32     // get list of targets
33     egZ3950TargetSvc.loadTargets();
34     egZ3950TargetSvc.loadActiveSearchFields();
35
36     var provider = egGridDataProvider.instance({});
37
38     provider.get = function(offset, count) {
39         var deferred = $q.defer();
40
41         var query = egZ3950TargetSvc.currentQuery();
42         if (Object.keys(query.search).length == 0) {
43             return $q.when();
44         }
45
46         query['limit'] = count;
47         query['offset'] = offset;
48
49         var resultIndex = offset;
50         egCore.net.request(
51             'open-ils.search',
52             'open-ils.search.z3950.search_class',
53             egCore.auth.token(),
54             query
55         ).then(
56             function() { deferred.resolve() },
57             null, // onerror
58             function(result) {
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);
64                 }
65             }
66         );
67
68         return deferred.promise;
69     };
70
71     $scope.z3950SearchGridProvider = provider;
72     $scope.gridControls = {};
73
74     $scope.search = function() {
75         $scope.z3950SearchGridProvider.refresh();
76     };
77     $scope.clearForm = function() {
78         egZ3950TargetSvc.clearSearchFields();
79     };
80
81     $scope.showInCatalog = function() {
82         var items = $scope.gridControls.selectedItems();
83         // relying on cant_showInCatalog to protect us
84         var url = egCore.env.basePath +
85                   'cat/catalog/record/' + items[0].tcn();
86         $timeout(function() { $window.open(url, '_blank') });        
87     };
88     $scope.cant_showInCatalog = function() {
89         var items = $scope.gridControls.selectedItems();
90         if (items.length != 1) return true;
91         if (items[0]['service'] == 'native-evergreen-catalog') return false;
92         return true;
93     };
94
95     $scope.import = function() {
96         var deferred = $q.defer();
97         var items = $scope.gridControls.selectedItems();
98         egCore.net.request(
99             'open-ils.cat',
100             'open-ils.cat.biblio.record.xml.import',
101             egCore.auth.token(),
102             items[0]['marcxml']
103             // FIXME and more
104         ).then(
105             function() { deferred.resolve() },
106             null, // onerror
107             function(result) {
108                 console.debug('imported');
109             }
110         );
111
112         return deferred.promise;
113     };
114     $scope.cant_import = function() {
115         var items = $scope.gridControls.selectedItems();
116         if (items.length == 1) return false;
117         return true;
118     };
119 }])