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',
103 ['$scope','$uibModalInstance',
104 function($scope , $uibModalInstance) {
106 $scope.bucket_id = 0;
107 $scope.newBucketName = '';
108 $scope.allBuckets = [];
112 'open-ils.actor.container.retrieve_by_class.authoritative',
113 egCore.auth.token(), egCore.auth.user().id(),
114 'copy', 'staff_client'
115 ).then(function(buckets) { $scope.allBuckets = buckets; });
117 $scope.add_to_bucket = function() {
119 angular.forEach(copy_list, function (cp) {
120 var item = new egCore.idl.ccbi()
121 item.bucket($scope.bucket_id);
122 item.target_copy(cp);
126 'open-ils.actor.container.item.create',
127 egCore.auth.token(), 'copy', item
131 return $q.all(promises).then(function() {
132 $uibModalInstance.close();
137 $scope.add_to_new_bucket = function() {
138 var bucket = new egCore.idl.ccb();
139 bucket.owner(egCore.auth.user().id());
140 bucket.name($scope.newBucketName);
141 bucket.description('');
142 bucket.btype('staff_client');
144 return egCore.net.request(
146 'open-ils.actor.container.create',
147 egCore.auth.token(), 'copy', bucket
148 ).then(function(bucket) {
149 $scope.bucket_id = bucket;
150 $scope.add_to_bucket();
154 $scope.cancel = function() {
155 $uibModalInstance.dismiss();
162 function gatherSelectedRecordIds () {
165 $scope.grid_controls.selectedItems(),
167 if (rid_list.indexOf(item['target_copy.call_number.record.simple_record.id']) == -1)
168 rid_list.push(item['target_copy.call_number.record.simple_record.id']);
173 function gatherSelectedHoldingsIds (rid) {
176 $scope.grid_controls.selectedItems(),
178 if (rid && item['target_copy.call_number.record.simple_record.id'] != rid) return;
179 cp_id_list.push(item['target_copy.id']);
185 var spawnHoldingsEdit = function (hide_vols, hide_copies){
186 angular.forEach(gatherSelectedRecordIds(), function (r) {
189 'open-ils.actor.anon_cache.set_value',
190 null, 'edit-these-copies', {
192 copies: gatherSelectedHoldingsIds(r),
194 hide_vols : hide_vols,
195 hide_copies : hide_copies
197 ).then(function(key) {
199 var url = egCore.env.basePath + 'cat/volcopy/' + key;
200 $timeout(function() { $window.open(url, '_blank') });
202 alert('Could not create anonymous cache key!');
208 $scope.edit_copies = function() {
209 spawnHoldingsEdit(true, false);
212 function current_query() {
214 'source_send_time' : { 'between' : date_range() },
215 'dest_recv_time' : null
217 if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); }
218 if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); }
222 $scope.grid_controls = {
223 activateItem : load_item,
224 setQuery : current_query
227 function refresh_page() {
228 $scope.grid_controls.setQuery(current_query());
229 $scope.grid_controls.refresh();
232 $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou());
233 $scope.$watch('context_org', function(newVal, oldVal) {
234 if (newVal && newVal != oldVal) refresh_page();
236 $scope.$watch('transit_direction', function(newVal, oldVal) {
237 if (newVal && newVal != oldVal) refresh_page();
239 $scope.$watch('dates.start_date', function(newVal, oldVal) {
240 if (newVal && newVal != oldVal) refresh_page();
242 $scope.$watch('dates.end_date', function(newVal, oldVal) {
243 if (newVal && newVal != oldVal) refresh_page();