]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/local/circ/neg_balance_users.js
LP#1642378 Webstaff negative balance UI progress dialog
[working/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',
7         'egGridDataProvider','egProgressDialog',
8 function($scope , $q , $timeout , $location , $window , egCore , 
9          egGridDataProvider , egProgressDialog) {
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         egProgressDialog.open();
17
18         var deferred = $q.defer();
19
20         egCore.net.request(
21             'open-ils.actor',
22             'open-ils.actor.users.negative_balance',
23             egCore.auth.token(), $scope.context_org.id())
24         .then(deferred.resolve, null, function(blob) {
25             egProgressDialog.increment();
26             // Give the grid a top-level identifier field
27             blob.usr_id = blob.usr.id();
28             deferred.notify(blob)
29         }).finally(egProgressDialog.close);
30
31         return deferred.promise;
32     }
33
34     $scope.org_changed = function(org) {
35         $scope.grid_provider.refresh();
36     }
37
38     $scope.disable_org = function(org_id) {
39         if (!org_id) return true;
40         return egCore.org.get(org_id).ou_type().can_have_users() != 't';
41     }
42
43     // NOTE: Chrome only allows one tab/window to open per user
44     // action.  Only the first patron will be displayed.
45     $scope.get_user = function(selected) {
46         if (!selected.length) return;
47         angular.forEach(selected, function(data) {
48             $timeout(function() {
49                 var url = $location.absUrl().replace(
50                     /admin\/local\/.*/,
51                     'circ/patron/' + data.usr.id() + '/checkout');
52                 $window.open(url, '_blank')
53             });
54         });
55     }
56
57     $scope.grid_controls = {
58         activateItem : function(selected) { 
59             // activateItem returns a single row.
60             $scope.get_user([selected]) 
61         }
62     }
63
64 }])