]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/workstation/log.js
Web Client: Make Patron Email Clickable
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / workstation / log.js
1 angular.module('egWorkLogApp', 
2     ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
3
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5     $locationProvider.html5Mode(true);
6     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
7         
8     var resolver = {delay : 
9         ['egStartup', function(egStartup) {return egStartup.go()}]}
10
11     $routeProvider.when('/admin/workstation/log', {
12         templateUrl: './admin/workstation/t_log',
13         controller: 'WorkLogCtrl',
14         resolve : resolver
15     });
16
17     $routeProvider.otherwise({redirectTo : '/admin/workstation/log'});
18 })
19
20 .controller('WorkLogCtrl',
21        ['$scope','$q','$routeParams','$window','$timeout','egCore','egGridDataProvider','egWorkLog',
22 function($scope , $q , $routeParams , $window , $timeout , egCore , egGridDataProvider , egWorkLog ) {
23
24     var work_log_entries = [];
25     var patron_log_entries = [];
26
27     var work_log_provider = egGridDataProvider.instance({});
28     var patron_log_provider = egGridDataProvider.instance({});
29     $scope.grid_work_log_provider = work_log_provider;
30     $scope.grid_patron_log_provider = patron_log_provider;
31
32     function load_item(log_entries) {
33         if (!log_entries) return;
34         if (!angular.isArray(log_entries)) log_entries = [log_entries];
35         angular.forEach(log_entries, function(log_entry) {
36             $window.open(
37                 egCore.env.basePath + '/cat/item/' + log_entry.item_id,
38                 '_blank'
39             ).focus();
40         });
41     }
42
43     $scope.load_item = function(action, data, entries) {
44         load_item(entries);
45     }
46
47     function load_patron(log_entries) {
48         if (!log_entries) return;
49         if (!angular.isArray(log_entries)) log_entries = [log_entries];
50         angular.forEach(log_entries, function(log_entry) {
51             $window.open(
52                 egCore.env.basePath +
53                 '/circ/patron/' + log_entry.patron_id + '/checkout',
54                 '_blank'
55             ).focus();
56         });
57     }
58
59     $scope.load_patron = function(action, data, entries) {
60         load_patron(entries);
61     }
62
63     $scope.grid_controls = {
64         activateItem : load_patron
65     }
66
67     $scope.refresh_ui = function() {
68         work_log_entries = [];
69         patron_log_entries = [];
70         work_log_provider.refresh();
71         patron_log_provider.refresh();
72     }
73
74     function fetch_hold(deferred,entry) {
75         return egCore.pcrud.search('ahr',
76             { 'id' : entry.hold_id }, {
77                 'flesh' : 2,
78                 'flesh_fields' : {
79                     'ahr' : ['usr','current_copy'],
80                 },
81             }
82         ).then(
83             function(hold) {
84                 entry.patron_id = hold.usr().id();
85                 entry.user = hold.usr().family_name();
86                 if (hold.current_copy()) {
87                     entry.item = hold.current_copy().barcode();
88                 }
89             }
90         );
91     }
92
93     function fetch_patron(deferred,entry) {
94         return egCore.pcrud.search('au',
95             { 'id' : entry.patron_id }, {}
96         ).then(
97             function(usr) {
98                 entry.user = usr.family_name();
99             }
100         );
101     }
102
103     work_log_provider.get = function(offset, count) {
104         var log_entries = egWorkLog.retrieve_all();
105         console.log(log_entries);
106         var deferred = $q.defer();
107
108         var promises = [];
109         var entries = count ?
110                       log_entries.work_log.slice(offset, offset + count) :
111                       log_entries.work_log;
112         entries.forEach(
113             function(el,idx) {
114                 el.id = idx;
115                 // notify right away and in order; fetch_* will
116                 // fill in entry later if necessary
117                 promises.push($timeout(function() { deferred.notify(el) }));
118                 if (el.action == 'requested_hold') {
119                     promises.push(fetch_hold(deferred,el));
120                 } else if (el.action == 'registered_patron') {
121                     promises.push(fetch_patron(deferred,el));
122                 } else if (el.action == 'edited_patron') {
123                     promises.push(fetch_patron(deferred,el));
124                 } else if (el.action == 'paid_bill') {
125                     promises.push(fetch_patron(deferred,el));
126                 }
127             }
128         );
129         $q.all(promises).then(deferred.resolve);
130
131         return deferred.promise;
132     }
133
134     patron_log_provider.get = function(offset, count) {
135         var log_entries = egWorkLog.retrieve_all();
136         console.log(log_entries);
137         var deferred = $q.defer();
138
139         var promises = [];
140         var entries = count ?
141                       log_entries.patron_log.slice(offset, offset + count) :
142                       log_entries.patron_log;
143         log_entries.patron_log.forEach(
144             function(el,idx) {
145                 el.id = idx;
146                 // notify right away and in order; fetch_* will
147                 // fill in entry later if necessary
148                 promises.push($timeout(function() { deferred.notify(el) }));
149                 if (el.action == 'requested_hold') {
150                     promises.push(fetch_hold(deferred,el));
151                 } else if (el.action == 'registered_patron') {
152                     promises.push(fetch_patron(deferred,el));
153                 } else if (el.action == 'edited_patron') {
154                     promises.push(fetch_patron(deferred,el));
155                 } else if (el.action == 'paid_bill') {
156                     promises.push(fetch_patron(deferred,el));
157                 }
158             }
159         );
160         $q.all(promises).then(deferred.resolve);
161
162         return deferred.promise;
163     }
164
165 }])
166