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) {
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.add_copies_to_bucket = function(transits) {
95 angular.forEach($scope.grid_controls.selectedItems(), function(transit) {
96 copy_list.push(transit.target_copy().id());
98 if (copy_list.length == 0) return;
100 // FIXME what follows ought to be refactored into a factory
101 return $uibModal.open({
102 templateUrl: './cat/catalog/t_add_to_bucket',
106 ['$scope','$uibModalInstance',
107 function($scope , $uibModalInstance) {
109 $scope.bucket_id = 0;
110 $scope.newBucketName = '';
111 $scope.allBuckets = [];
115 'open-ils.actor.container.retrieve_by_class.authoritative',
116 egCore.auth.token(), egCore.auth.user().id(),
117 'copy', 'staff_client'
118 ).then(function(buckets) { $scope.allBuckets = buckets; });
120 $scope.add_to_bucket = function() {
122 angular.forEach(copy_list, function (cp) {
123 var item = new egCore.idl.ccbi()
124 item.bucket($scope.bucket_id);
125 item.target_copy(cp);
129 'open-ils.actor.container.item.create',
130 egCore.auth.token(), 'copy', item
134 return $q.all(promises).then(function() {
135 $uibModalInstance.close();
140 $scope.add_to_new_bucket = function() {
141 var bucket = new egCore.idl.ccb();
142 bucket.owner(egCore.auth.user().id());
143 bucket.name($scope.newBucketName);
144 bucket.description('');
145 bucket.btype('staff_client');
147 return egCore.net.request(
149 'open-ils.actor.container.create',
150 egCore.auth.token(), 'copy', bucket
151 ).then(function(bucket) {
152 $scope.bucket_id = bucket;
153 $scope.add_to_bucket();
157 $scope.cancel = function() {
158 $uibModalInstance.dismiss();
165 function gatherSelectedRecordIds () {
168 $scope.grid_controls.selectedItems(),
170 if (rid_list.indexOf(item.target_copy().call_number().record().simple_record().id()) == -1)
171 rid_list.push(item.target_copy().call_number().record().simple_record().id());
176 function gatherSelectedHoldingsIds (rid) {
179 $scope.grid_controls.selectedItems(),
181 if (rid && item.target_copy().call_number().record().simple_record().id() != rid) return;
182 cp_id_list.push(item.target_copy().id());
188 var spawnHoldingsEdit = function (hide_vols, hide_copies){
189 angular.forEach(gatherSelectedRecordIds(), function (r) {
192 'open-ils.actor.anon_cache.set_value',
193 null, 'edit-these-copies', {
195 copies: gatherSelectedHoldingsIds(r),
197 hide_vols : hide_vols,
198 hide_copies : hide_copies
200 ).then(function(key) {
202 var url = egCore.env.basePath + 'cat/volcopy/' + key;
203 $timeout(function() { $window.open(url, '_blank') });
205 alert('Could not create anonymous cache key!');
211 $scope.edit_copies = function() {
212 spawnHoldingsEdit(true, false);
215 $scope.grid_controls = {
216 activateItem : load_item
219 function refresh_page() {
224 provider.get = function(offset, count) {
225 var deferred = $q.defer();
229 'source_send_time' : { 'between' : date_range() },
230 'dest_recv_time' : null
232 if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); }
233 if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); }
235 egCore.pcrud.search('atc',
238 // atc -> target_copy -> call_number -> record -> simple_record
239 // atc -> hold_transit_copy -> hold -> usr -> card
241 'atc' : ['target_copy','dest','source','hold_transit_copy'],
242 'acp' : ['call_number','location','circ_lib'],
244 'bre' : ['simple_record'],
249 'select' : { 'bre' : ['id'] },
250 order_by : { atc : 'source_send_time' },
255 deferred.resolve, null,
257 transits[offset + recv_index++] = transit;
258 deferred.notify(transit);
262 return deferred.promise;
265 $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou());
266 $scope.$watch('context_org', function(newVal, oldVal) {
267 if (newVal && newVal != oldVal) refresh_page();
269 $scope.$watch('transit_direction', function(newVal, oldVal) {
270 if (newVal && newVal != oldVal) refresh_page();
272 $scope.$watch('dates.start_date', function(newVal, oldVal) {
273 if (newVal && newVal != oldVal) refresh_page();
275 $scope.$watch('dates.end_date', function(newVal, oldVal) {
276 if (newVal && newVal != oldVal) refresh_page();