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','$uibModal','$timeout',
22 function($scope , $q , $routeParams , $window , egCore , egTransits , egGridDataProvider , $uibModal , $timeout) {
24 $scope.transit_direction = 'to';
26 function init_dates() {
28 var start = new Date(); // midnight this morning
31 var end = new Date(); // near midnight tonight
41 function date_range() {
42 if ($scope.dates.start_date > $scope.dates.end_date) {
43 var tmp = $scope.dates.start_date;
44 $scope.dates.start_date = $scope.dates.end_date;
45 $scope.dates.end_date = tmp;
47 $scope.dates.start_date.setHours(0);
48 $scope.dates.start_date.setMinutes(0);
49 $scope.dates.end_date.setHours(23);
50 $scope.dates.end_date.setMinutes(59);
52 var start = $scope.dates.start_date.toISOString().replace(/T.*/,'');
53 var end = $scope.dates.end_date.toISOString().replace(/T.*/,'');
54 } catch(E) { // handling empty date widgets; maybe dangerous if something else can happen
58 var today = new Date().toISOString().replace(/T.*/,'');
59 if (end == today) end = 'now';
63 function load_item(transits) {
64 if (!transits) return;
65 if (!angular.isArray(transits)) transits = [transits];
66 angular.forEach(transits, function(transit) {
68 egCore.env.basePath + '/cat/item/' +
69 transit.target_copy().id(),
75 $scope.load_item = function(action, data, transits) {
79 function abort_transit(transits) {
80 if (!transits) return;
81 if (!angular.isArray(transits)) transits = [transits];
82 if (transits.length == 0) return;
83 egTransits.abort_transits( transits, refresh_page );
86 $scope.abort_transit = function(action, date, transits) {
87 abort_transit(transits);
90 $scope.add_copies_to_bucket = function() {
92 angular.forEach($scope.grid_controls.selectedItems(), function(transit) {
93 copy_list.push(transit['target_copy.id']);
95 if (copy_list.length == 0) return;
97 // FIXME what follows ought to be refactored into a factory
98 return $uibModal.open({
99 templateUrl: './cat/catalog/t_add_to_bucket',
104 ['$scope','$uibModalInstance',
105 function($scope , $uibModalInstance) {
107 $scope.bucket_id = 0;
108 $scope.newBucketName = '';
109 $scope.allBuckets = [];
113 'open-ils.actor.container.retrieve_by_class.authoritative',
114 egCore.auth.token(), egCore.auth.user().id(),
115 'copy', 'staff_client'
116 ).then(function(buckets) { $scope.allBuckets = buckets; });
118 $scope.add_to_bucket = function() {
120 angular.forEach(copy_list, function (cp) {
121 var item = new egCore.idl.ccbi()
122 item.bucket($scope.bucket_id);
123 item.target_copy(cp);
127 'open-ils.actor.container.item.create',
128 egCore.auth.token(), 'copy', item
132 return $q.all(promises).then(function() {
133 $uibModalInstance.close();
138 $scope.add_to_new_bucket = function() {
139 var bucket = new egCore.idl.ccb();
140 bucket.owner(egCore.auth.user().id());
141 bucket.name($scope.newBucketName);
142 bucket.description('');
143 bucket.btype('staff_client');
145 return egCore.net.request(
147 'open-ils.actor.container.create',
148 egCore.auth.token(), 'copy', bucket
149 ).then(function(bucket) {
150 $scope.bucket_id = bucket;
151 $scope.add_to_bucket();
155 $scope.cancel = function() {
156 $uibModalInstance.dismiss();
163 function gatherSelectedRecordIds () {
166 $scope.grid_controls.selectedItems(),
168 if (rid_list.indexOf(item['target_copy.call_number.record.simple_record.id']) == -1)
169 rid_list.push(item['target_copy.call_number.record.simple_record.id']);
174 function gatherSelectedHoldingsIds (rid) {
177 $scope.grid_controls.selectedItems(),
179 if (rid && item['target_copy.call_number.record.simple_record.id'] != rid) return;
180 cp_id_list.push(item['target_copy.id']);
186 var spawnHoldingsEdit = function (hide_vols, hide_copies){
187 angular.forEach(gatherSelectedRecordIds(), function (r) {
190 'open-ils.actor.anon_cache.set_value',
191 null, 'edit-these-copies', {
193 copies: gatherSelectedHoldingsIds(r),
195 hide_vols : hide_vols,
196 hide_copies : hide_copies
198 ).then(function(key) {
200 var url = egCore.env.basePath + 'cat/volcopy/' + key;
201 $timeout(function() { $window.open(url, '_blank') });
203 alert('Could not create anonymous cache key!');
209 $scope.edit_copies = function() {
210 spawnHoldingsEdit(true, false);
213 function current_query() {
215 'source_send_time' : { 'between' : date_range() },
216 'dest_recv_time' : null,
219 if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); }
220 if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); }
224 $scope.grid_controls = {
225 activateItem : load_item,
226 setQuery : current_query
229 function refresh_page() {
230 $scope.grid_controls.setQuery(current_query());
231 $scope.grid_controls.refresh();
234 $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou());
235 $scope.$watch('context_org', function(newVal, oldVal) {
236 if (newVal && newVal != oldVal) refresh_page();
238 $scope.$watch('transit_direction', function(newVal, oldVal) {
239 if (newVal && newVal != oldVal) refresh_page();
241 $scope.$watch('dates.start_date', function(newVal, oldVal) {
242 if (newVal && newVal != oldVal) refresh_page();
244 $scope.$watch('dates.end_date', function(newVal, oldVal) {
245 if (newVal && newVal != oldVal) refresh_page();
248 function fetch_all_matching_transits(transits) {
249 var deferred = $q.defer();
250 var filter = current_query();
251 egCore.pcrud.search('atc',
254 // atc -> target_copy -> call_number -> record -> simple_record
255 // atc -> hold_transit_copy -> hold -> usr -> card
257 'atc' : ['target_copy','dest','source','hold_transit_copy'],
258 'acp' : ['call_number','location','circ_lib'],
259 'acn' : ['record', 'prefix', 'suffix'],
260 'bre' : ['simple_record'],
265 'select' : { 'bre' : ['id'] },
266 order_by : { atc : 'source_send_time' },
269 deferred.resolve, null,
271 transits.push(egCore.idl.toHash(transit));
274 return deferred.promise;
277 $scope.print_full_list = function() {
278 var print_data = { transits : [] };
280 return fetch_all_matching_transits(print_data.transits).then(function() {
281 if (print_data.transits.length == 0) return $q.when();
282 return egCore.print.print({
283 template : 'transit_list',