From: Jason Etheridge Date: Thu, 1 Oct 2015 11:23:44 +0000 (-0400) Subject: webstaff: Transit List X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=18d727b3dccbbfdaee1b890d3a51d2bd8162a181;p=working%2FEvergreen.git webstaff: Transit List under Administration -> Local Administration Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/templates/staff/circ/share/t_abort_transit_dialog.tt2 b/Open-ILS/src/templates/staff/circ/share/t_abort_transit_dialog.tt2 new file mode 100644 index 0000000000..7490e533d2 --- /dev/null +++ b/Open-ILS/src/templates/staff/circ/share/t_abort_transit_dialog.tt2 @@ -0,0 +1,32 @@ +
+ + + diff --git a/Open-ILS/src/templates/staff/circ/transits/list.tt2 b/Open-ILS/src/templates/staff/circ/transits/list.tt2 new file mode 100644 index 0000000000..950a57e17d --- /dev/null +++ b/Open-ILS/src/templates/staff/circ/transits/list.tt2 @@ -0,0 +1,18 @@ +[% + WRAPPER "staff/base.tt2"; + ctx.page_title = l("Transit List"); + ctx.page_app = "egTransitListApp"; +%] + +[% BLOCK APP_JS %] + + + + + + +[% END %] + +
+ +[% END %] diff --git a/Open-ILS/src/templates/staff/circ/transits/t_list.tt2 b/Open-ILS/src/templates/staff/circ/transits/t_list.tt2 new file mode 100644 index 0000000000..47b9b01ce5 --- /dev/null +++ b/Open-ILS/src/templates/staff/circ/transits/t_list.tt2 @@ -0,0 +1,50 @@ +
+
+ [% l('Transit List') %] +
+
+ + + +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/web/js/ui/default/staff/circ/services/transits.js b/Open-ILS/web/js/ui/default/staff/circ/services/transits.js new file mode 100644 index 0000000000..e2019eb13b --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/circ/services/transits.js @@ -0,0 +1,68 @@ +/** + * Transits, yo + */ + +angular.module('egCoreMod') + +.factory('egTransits', + + ['$modal','$q','egCore','egConfirmDialog','egAlertDialog', +function($modal , $q , egCore , egConfirmDialog , egAlertDialog) { + + var service = {}; + + service.abort_transits = function(transits,callback) { + + return $modal.open({ + templateUrl : './circ/share/t_abort_transit_dialog', + controller : + ['$scope', '$modalInstance', + function($scope, $modalInstance) { + + $scope.num_transits = transits.length; + $scope.num_hold_transits = 0; + angular.forEach(transits, function(t) { + if (t.hold_transit_copy()) { + $scope.num_hold_transits++; + } + }); + + $scope.cancel = function($event) { + $modalInstance.dismiss(); + $event.preventDefault(); + } + + $scope.ok = function() { + + function abort_one() { + var transit = transits.pop(); + if (!transit) { + $modalInstance.close(); + return; + } + egCore.net.request( + 'open-ils.circ', 'open-ils.circ.transit.abort', + egCore.auth.token(), { 'transitid' : transit.id() } + ).then(function(resp) { + if (evt = egCore.evt.parse(resp)) { + console.error('unable to abort transit: ' + + evt.toString()); + } + abort_one(); + }); + } + + abort_one(); + } + } + ] + }).result.then( + function() { + callback(); + } + ); + } + + return service; +}]) +; diff --git a/Open-ILS/web/js/ui/default/staff/circ/transits/list.js b/Open-ILS/web/js/ui/default/staff/circ/transits/list.js new file mode 100644 index 0000000000..b3634c42be --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/circ/transits/list.js @@ -0,0 +1,154 @@ +angular.module('egTransitListApp', + ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod']) + +.config(function($routeProvider, $locationProvider, $compileProvider) { + $locationProvider.html5Mode(true); + $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export + + var resolver = {delay : + ['egStartup', function(egStartup) {return egStartup.go()}]} + + $routeProvider.when('/circ/transits/list', { + templateUrl: './circ/transits/t_list', + controller: 'TransitListCtrl', + resolve : resolver + }); + + $routeProvider.otherwise({redirectTo : '/circ/transits/list'}); +}) + +.controller('TransitListCtrl', + ['$scope','$q','$routeParams','$window','$location','egCore','egTransits','egGridDataProvider', +function($scope , $q , $routeParams , $window , $location , egCore , egTransits , egGridDataProvider) { + + var transits = []; + var provider = egGridDataProvider.instance({}); + $scope.grid_data_provider = provider; + $scope.transit_direction = 'to'; + + function init_dates() { + // setup date filters + var start = new Date(); // midnight this morning + start.setHours(0); + start.setMinutes(0); + var end = new Date(); // near midnight tonight + end.setHours(23); + end.setMinutes(59); + $scope.dates = { + start_date : start, + end_date : new Date() + } + } + init_dates(); + + function date_range() { + if ($scope.dates.start_date > $scope.dates.end_date) { + var tmp = $scope.dates.start_date; + $scope.dates.start_date = $scope.dates.end_date; + $scope.dates.end_date = tmp; + } + $scope.dates.start_date.setHours(0); + $scope.dates.start_date.setMinutes(0); + $scope.dates.end_date.setHours(23); + $scope.dates.end_date.setMinutes(59); + try { + var start = $scope.dates.start_date.toISOString().replace(/T.*/,''); + var end = $scope.dates.end_date.toISOString().replace(/T.*/,''); + } catch(E) { // handling empty date widgets; maybe dangerous if something else can happen + init_dates(); + return date_range(); + } + var today = new Date().toISOString().replace(/T.*/,''); + if (end == today) end = 'now'; + return [start, end]; + } + + function load_item(transits) { + if (!transits) return; + if (!angular.isArray(transits)) transits = [transits]; + angular.forEach(transits, function(transit) { + $window.open( + $location.path( + '/cat/item/' + transit.target_copy().id() + ).absUrl(), + '_blank' + ).focus(); + }); + } + + $scope.load_item = function(action, data, transits) { + load_item(transits); + } + + function abort_transit(transits) { + if (!transits) return; + if (!angular.isArray(transits)) transits = [transits]; + if (transits.length == 0) return; + egTransits.abort_transits( transits, refresh_page ); + } + + $scope.abort_transit = function(action, date, transits) { + abort_transit(transits); + } + + $scope.grid_controls = { + activateItem : load_item + } + + function refresh_page() { + transits = []; + provider.refresh(); + } + + provider.get = function(offset, count) { + var deferred = $q.defer(); + var recv_index = 0; + + var filter = { + 'source_send_time' : { 'between' : date_range() } + }; + if ($scope.transit_direction == 'to') { filter['dest'] = $scope.context_org.id(); } + if ($scope.transit_direction == 'from') { filter['source'] = $scope.context_org.id(); } + + egCore.pcrud.search('atc', + filter, { + 'flesh' : 5, + // atc -> target_copy -> call_number -> record -> simple_record + // atc -> hold_transit_copy -> hold -> usr -> card + 'flesh_fields' : { + 'atc' : ['target_copy','dest','source','hold_transit_copy'], + 'acp' : ['call_number','location','circ_lib'], + 'acn' : ['record'], + 'bre' : ['simple_record'], + 'ahtc' : ['hold'], + 'ahr' : ['usr'], + 'au' : ['card'] + }, + 'select' : { 'bre' : ['id'] } + } + ).then( + deferred.resolve, null, + function(transit) { + transits[offset + recv_index++] = transit; + deferred.notify(transit); + } + ); + + return deferred.promise; + } + + $scope.context_org = egCore.org.get(egCore.auth.user().ws_ou()); + $scope.$watch('context_org', function(newVal, oldVal) { + if (newVal && newVal != oldVal) refresh_page(); + }); + $scope.$watch('transit_direction', function(newVal, oldVal) { + if (newVal && newVal != oldVal) refresh_page(); + }); + $scope.$watch('dates.start_date', function(newVal, oldVal) { + if (newVal && newVal != oldVal) refresh_page(); + }); + $scope.$watch('dates.end_date', function(newVal, oldVal) { + if (newVal && newVal != oldVal) refresh_page(); + }); +}]) +