]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/local/circ/neg_balance_users.js
d8acde1325c655b798bf58ee4e432302dd245175
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / local / circ / neg_balance_users.js
1
2 angular.module('egAdminCirc',
3     ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod'])
4
5 .controller('NegBalances',
6        ['$scope','$q','$timeout','$location','$window','egCore','egGridDataProvider',
7 function($scope , $q , $timeout , $location , $window , egCore , egGridDataProvider) {
8
9     egCore.startup.go(); // standalone mode requires manual startup
10
11     $scope.grid_provider = egGridDataProvider.instance({});
12
13     // API does not currenlty support paging, so it's all or none.
14     $scope.grid_provider.get = function(offset, count) {
15         if (!$scope.context_org) return $q.when();
16
17         var deferred = $q.defer();
18
19         egCore.net.request(
20             'open-ils.actor',
21             'open-ils.actor.users.negative_balance',
22             egCore.auth.token(), $scope.context_org.id())
23         .then(deferred.resolve, null, function(blob) {
24             // Give the grid a top-level identifier field
25             blob.usr_id = blob.usr.id();
26             deferred.notify(blob)
27         });
28
29         return deferred.promise;
30     }
31
32     $scope.org_changed = function(org) {
33         $scope.context_org = org; // hmm, why necessary.
34         $scope.grid_provider.refresh();
35     }
36
37     // NOTE: Chrome only allows one tab/window to open per user
38     // action.  Only the first patron will be displayed.
39     $scope.get_user = function(selected) {
40         if (!selected.length) return;
41         angular.forEach(selected, function(data) {
42             $timeout(function() {
43                 var url = $location.absUrl().replace(
44                     /admin\/local\/.*/,
45                     'circ/patron/' + data.usr.id() + '/checkout');
46                 $window.open(url, '_blank')
47             });
48         });
49     }
50 }])