1 angular.module('egTransitListApp',
2 ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
4 .config(function($routeProvider, $locationProvider, $compileProvider) {
5 $locationProvider.html5Mode(true);
6 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
8 var resolver = {delay :
9 ['egStartup', function(egStartup) {return egStartup.go()}]}
11 $routeProvider.when('/circ/transits/list', {
12 templateUrl: './circ/transits/t_list',
13 controller: 'TransitListCtrl',
17 $routeProvider.otherwise({redirectTo : '/circ/transits/list'});
20 .controller('TransitListCtrl',
21 ['$scope','$q','$routeParams','$window','egCore','egTransits','egGridDataProvider',
22 function($scope , $q , $routeParams , $window , egCore , egTransits , egGridDataProvider) {
25 var provider = egGridDataProvider.instance({});
26 $scope.grid_data_provider = provider;
27 $scope.transit_direction = 'to';
29 function init_dates() {
31 var start = new Date(); // midnight this morning
34 var end = new Date(); // near midnight tonight
44 function date_range() {
45 if ($scope.dates.start_date > $scope.dates.end_date) {
46 var tmp = $scope.dates.start_date;
47 $scope.dates.start_date = $scope.dates.end_date;
48 $scope.dates.end_date = tmp;
50 $scope.dates.start_date.setHours(0);
51 $scope.dates.start_date.setMinutes(0);
52 $scope.dates.end_date.setHours(23);
53 $scope.dates.end_date.setMinutes(59);
55 var start = $scope.dates.start_date.toISOString().replace(/T.*/,'');
56 var end = $scope.dates.end_date.toISOString().replace(/T.*/,'');
57 } catch(E) { // handling empty date widgets; maybe dangerous if something else can happen
61 var today = new Date().toISOString().replace(/T.*/,'');
62 if (end == today) end = 'now';
66 function load_item(transits) {
67 if (!transits) return;
68 if (!angular.isArray(transits)) transits = [transits];
69 angular.forEach(transits, function(transit) {
71 egCore.env.basePath + '/cat/item/' +
72 transit.target_copy().id(),
78 $scope.load_item = function(action, data, transits) {
82 function abort_transit(transits) {
83 if (!transits) return;
84 if (!angular.isArray(transits)) transits = [transits];
85 if (transits.length == 0) return;
86 egTransits.abort_transits( transits, refresh_page );
89 $scope.abort_transit = function(action, date, transits) {
90 abort_transit(transits);
93 $scope.grid_controls = {
94 activateItem : load_item
97 function refresh_page() {
102 provider.get = function(offset, count) {
103 var deferred = $q.defer();
107 'source_send_time' : { 'between' : date_range() },
108 'dest_recv_time' : null
110 if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); }
111 if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); }
113 egCore.pcrud.search('atc',
116 // atc -> target_copy -> call_number -> record -> simple_record
117 // atc -> hold_transit_copy -> hold -> usr -> card
119 'atc' : ['target_copy','dest','source','hold_transit_copy'],
120 'acp' : ['call_number','location','circ_lib'],
122 'bre' : ['simple_record'],
127 'select' : { 'bre' : ['id'] }
130 deferred.resolve, null,
132 transits[offset + recv_index++] = transit;
133 deferred.notify(transit);
137 return deferred.promise;
140 $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou());
141 $scope.$watch('context_org', function(newVal, oldVal) {
142 if (newVal && newVal != oldVal) refresh_page();
144 $scope.$watch('transit_direction', function(newVal, oldVal) {
145 if (newVal && newVal != oldVal) refresh_page();
147 $scope.$watch('dates.start_date', function(newVal, oldVal) {
148 if (newVal && newVal != oldVal) refresh_page();
150 $scope.$watch('dates.end_date', function(newVal, oldVal) {
151 if (newVal && newVal != oldVal) refresh_page();