port list code to egList
authorBill Erickson <berick@esilibrary.com>
Mon, 4 Nov 2013 19:12:24 +0000 (14:12 -0500)
committerBill Erickson <berick@esilibrary.com>
Mon, 4 Nov 2013 19:13:57 +0000 (14:13 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/fulfillment/t_actions.tt2
Open-ILS/src/templates/staff/fulfillment/t_item_table.tt2
Open-ILS/src/templates/staff/fulfillment/t_pending.tt2
Open-ILS/web/js/ui/default/staff/fulfillment/app.js

index f2aa2e9..a522409 100644 (file)
@@ -14,7 +14,7 @@
   <!-- todo: paging needs a total count value to be fully functional -->
   <button type="button" class="btn btn-default" 
     ng-class="{disabled : action_pending}"
-    ng-show="itemList.items.length == itemList.limit" 
+    ng-show="itemList.hasNextPage()"
     ng-click="nextPage()">&raquo;</button>
 
   <div class="btn-group">
index a8971c3..167ca2b 100644 (file)
@@ -1,11 +1,11 @@
 
-<div class="row" ng-hide="itemList.items.length">
+<div class="row" ng-hide="itemList.count()">
     <div class="col-lg-10 col-lg-offset-1">
       <div class="alert alert-info">[% l('No Items To Display') %]</div>
   </div>
 </div>
 
-<table class="table table-striped table-hover table-condensed" ng-show="itemList.items.length">
+<table class="table table-striped table-hover table-condensed" ng-show="itemList.count()">
   <thead>
     <tr>
       <th><a href="javascript:;" ng-click="itemList.selectAll()">&#x2713;</a></th>
index aa6fca5..19f2c44 100644 (file)
 
   <br/>
 
-  <div class="row" ng-hide="itemList.items.length">
+  <div class="row" ng-hide="itemList.count()">
     <div class="col-lg-10 col-lg-offset-1">
       <div class="alert alert-info">[% l('No Items To Display') %]</div>
     </div>
   </div>
 
-  <table class="table table-striped table-hover table-condensed" ng-show="itemList.items.length">
+  <table class="table table-striped table-hover table-condensed" ng-show="itemList.count()">
     <thead>
       <tr>
         <th><a href="javascript:;" ng-click="itemList.selectAll()">&#x2713;</a></th>
@@ -44,7 +44,7 @@
     </thead>
     <tbody>
       <tr ng-repeat="item in itemList.items">
-        <td><input type='checkbox' ng-model="itemList.selected[item.index]"/></td>
+        <td><input type='checkbox' ng-model="itemList.selectedRows[item.index]"/></td>
         <td>{{item.id}}</td>
         <td>{{item.request_time | date}}</td>
         <td>{{item.expire_time | date}}</td>
index db860de..3358169 100644 (file)
@@ -9,7 +9,7 @@
 
 
 angular.module('ffMain', 
-['ngRoute', 'egCoreMod', 'egUiMod', 'egUserMod'])
+['ngRoute', 'egCoreMod', 'egUiMod', 'egUserMod', 'egListMod'])
 
 .config(function($routeProvider, $locationProvider) {
 
@@ -126,9 +126,9 @@ function ($scope,  $route,  egStartup,  orgSelector,  egAuth,  egUser) {
  */
 .controller('ILLCtrl', 
         ['$scope','$q','$compile','$timeout','$rootScope','$location', 
-         '$route','$routeParams','egNet','egAuth','orgSelector','egOrg',
+         '$route','$routeParams','egNet','egAuth','orgSelector','egOrg','egList',
 function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location, 
-          $route,  $routeParams,  egNet,  egAuth,  orgSelector,  egOrg) {
+          $route,  $routeParams,  egNet,  egAuth,  orgSelector,  egOrg,  egList) {
 
     $scope.tabname = $routeParams.tab;
     $scope.orientation = $routeParams.orientation;
@@ -143,164 +143,142 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
     // so our child controllers can access our route info
     $scope.illRouteParams = $routeParams;
 
-    // This bit of scope is used directly by all child scopes.
-    // Inherited scopes use shallow copies, hence the nested object.
-    $scope.itemList = {
-        items : [],
-        selected : {},
-        limit : 10, // TODO UI
-        offset : 0, // TODO UI
-
-        // select all rows in the list.  if any are 
-        // already selected, de-select all.
-        selectAll : function() {
-            var action = true;
-            angular.forEach($scope.itemList.selected, function(val) {
-                if (val) action = false;
-            });
-            angular.forEach($scope.itemList.items, function(item) {
-                if (action) {
-                    $scope.itemList.selected[item.index] = action;
-                } else {
-                    delete $scope.itemList.selected[item.index];
-                }
-            });
-        },
-
-        addItem : function(item) {
-            // TODO: id version
-            item.index = $scope.itemList.items.length;
-            $scope.itemList.items.push(item);
-            egNet.request(
-                'open-ils.circ',
-                'open-ils.circ.item.transaction.disposition',
-                egAuth.token(), 
-                orgSelector.current().id(), 
-                item.barcode
-            ).then(function(items) {
-                if (items[0]) {
-                    $scope.itemList.flattenItem(item, items[0]);
-                } else {
-                   $scope.itemList.items.pop().not_found = true;
-                }
-            });
-        },
-
-        // given an item disposition blob, flatten it for display
-        flattenItem : function(item, item_data) {
-            /*
-             * TODO: most of this is unnecessary, since we can access
-             * fields directly in the template.  Consider pairing
-             * this down to fields that need munging only
-             */
-            var copy = item_data.copy;
-            var transit = item_data.transit;
-            var circ = item_data.circ;
-            var hold = item_data.hold;
-            if (hold) {
-                if (!transit && hold.transit()) {
-                    transit = item_data.hold.transit();
-                }
-            } else if (transit && transit.hold_transit_copy()) {
-                hold = transit.hold_transit_copy().hold();
+    $scope.itemList = egList.create({limit : 10}); // limit TBD
+
+    // apply some local list additions
+    $scope.itemList.addItem = function(item) {
+        // TODO: id version
+        item.index = $scope.itemList.count()
+        $scope.itemList.items.push(item);
+        egNet.request(
+            'open-ils.circ',
+            'open-ils.circ.item.transaction.disposition',
+            egAuth.token(), 
+            orgSelector.current().id(), 
+            item.barcode
+        ).then(function(items) {
+            if (items[0]) {
+                $scope.itemList.flattenItem(item, items[0]);
+            } else {
+               $scope.itemList.items.pop().not_found = true;
             }
+        });
+    }
 
-            item.copy = item_data.copy;
-            item.item_barcode = copy.barcode();
-            item.item_barcode_enc = encodeURIComponent(copy.barcode());
-            item.source_lib = egOrg.get(copy.source_lib()).shortname();
-            item.circ_lib = egOrg.get(copy.circ_lib()).shortname();
-            item.title = copy.call_number().record().simple_record().title();
-            item.author = copy.call_number().record().simple_record().author();
-            item.call_number = copy.call_number().label();
-            item.bib_id = copy.call_number().record().id();
-            item.remote_bib_id = copy.call_number().record().remote_id();
-            item.next_action = item_data.next_action;
-            item.can_cancel_hold = (item_data.can_cancel_hold == 1);
-            item.can_retarget_hold = (item_data.can_retarget_hold == 1);
-
-            switch(item_data.next_action) {
-                // capture lender copy for hold
-                case 'ill-home-capture' :
-                    item.needs_capture = true;
-                    break; 
-                // receive item at borrower
-                case 'ill-foreign-receive':
-                // receive lender copy back home
-                case 'transit-home-receive':
-                // transit item for cancelled hold back home (or next hold)
-                case 'transit-foreign-return':
-                    item.needs_receive = true;
-                    break; 
-                // complete borrower circ, transit item back home
-                case 'ill-foreign-checkin':
-                    item.needs_checkin = true;
-                    break;
-                // check out item to borrowing patron
-                case 'ill-foreign-checkout':
-                    item.needs_checkout = true;
-                    break;
+    // given an item disposition blob, flatten it for display
+    $scope.itemList.flattenItem = function(item, item_data) {
+        /*
+         * TODO: most of this is unnecessary, since we can access
+         * fields directly in the template.  Consider pairing
+         * this down to fields that need munging only
+         */
+        var copy = item_data.copy;
+        var transit = item_data.transit;
+        var circ = item_data.circ;
+        var hold = item_data.hold;
+        if (hold) {
+            if (!transit && hold.transit()) {
+                transit = item_data.hold.transit();
             }
+        } else if (transit && transit.hold_transit_copy()) {
+            hold = transit.hold_transit_copy().hold();
+        }
 
-            item.status_str = copy.status().name();
-            if (copy.status().id() == 8 /* holds shelf */ &&
-                hold &&
-                hold.transit() &&
-                hold.transit().dest_recv_time()) {
-                item.status_str += ' @ ' + egOrg.get(hold.transit().dest()).shortname();
-            } else if (copy.status().id() == 1 /* checked out */ && circ) {
-                item.status_str += ' @ ' + egOrg.get(circ.circ_lib()).shortname();
-            }
+        item.copy = item_data.copy;
+        item.item_barcode = copy.barcode();
+        item.item_barcode_enc = encodeURIComponent(copy.barcode());
+        item.source_lib = egOrg.get(copy.source_lib()).shortname();
+        item.circ_lib = egOrg.get(copy.circ_lib()).shortname();
+        item.title = copy.call_number().record().simple_record().title();
+        item.author = copy.call_number().record().simple_record().author();
+        item.call_number = copy.call_number().label();
+        item.bib_id = copy.call_number().record().id();
+        item.remote_bib_id = copy.call_number().record().remote_id();
+        item.next_action = item_data.next_action;
+        item.can_cancel_hold = (item_data.can_cancel_hold == 1);
+        item.can_retarget_hold = (item_data.can_retarget_hold == 1);
+
+        switch(item_data.next_action) {
+            // capture lender copy for hold
+            case 'ill-home-capture' :
+                item.needs_capture = true;
+                break; 
+            // receive item at borrower
+            case 'ill-foreign-receive':
+            // receive lender copy back home
+            case 'transit-home-receive':
+            // transit item for cancelled hold back home (or next hold)
+            case 'transit-foreign-return':
+                item.needs_receive = true;
+                break; 
+            // complete borrower circ, transit item back home
+            case 'ill-foreign-checkin':
+                item.needs_checkin = true;
+                break;
+            // check out item to borrowing patron
+            case 'ill-foreign-checkout':
+                item.needs_checkout = true;
+                break;
+        }
 
-            item.copy_status_warning = (copy.status().holdable() == 'f');
+        item.status_str = copy.status().name();
+        if (copy.status().id() == 8 /* holds shelf */ &&
+            hold &&
+            hold.transit() &&
+            hold.transit().dest_recv_time()) {
+            item.status_str += ' @ ' + egOrg.get(hold.transit().dest()).shortname();
+        } else if (copy.status().id() == 1 /* checked out */ && circ) {
+            item.status_str += ' @ ' + egOrg.get(circ.circ_lib()).shortname();
+        }
 
-            if (transit) {
-                item.transit = transit;
-                item.transit_source = transit.source().shortname();
-                item.transit_dest = transit.dest().shortname();
-                item.transit_time = transit.source_send_time();
-                item.transit_recv_time = transit.dest_recv_time();
-                item.open_transit = !Boolean(transit.dest_recv_time());
-            }
+        item.copy_status_warning = (copy.status().holdable() == 'f');
 
-            if (circ) {
-                item.circ = circ;
-                item.due_date = circ.due_date();
-                item.circ_circ_lib = egOrg.get(circ.circ_lib()).shortname();
-                item.circ_xact_start = circ.xact_start();
-                item.circ_stop_fines = circ.stop_fines();
-                // FF patrons will all have cards, but some test logins may not
-                item.patron_card = circ.usr().card() ? 
-                    circ.usr().card().barcode() : circ.usr().usrname();
-                item.patron_name = circ.usr().first_given_name() + ' ' + circ.usr().family_name() // i18n
-                item.can_mark_lost = (item.circ && item.copy.status().id() == 1); // checked out
-            }
+        if (transit) {
+            item.transit = transit;
+            item.transit_source = transit.source().shortname();
+            item.transit_dest = transit.dest().shortname();
+            item.transit_time = transit.source_send_time();
+            item.transit_recv_time = transit.dest_recv_time();
+            item.open_transit = !Boolean(transit.dest_recv_time());
+        }
 
-            if (hold) {
-                item.hold = hold;
-                item.patron_card = hold.usr().card() ? 
-                    hold.usr().card().barcode() : hold.usr().usrname();
-                item.patron_name = hold.usr().first_given_name() + ' ' + hold.usr().family_name() // i18n
-                item.hold_request_lib = egOrg.get(hold.request_lib()).shortname();
-                item.hold_pickup_lib = egOrg.get(hold.pickup_lib()).shortname();
-                item.hold_request_time = hold.request_time();
-                item.hold_capture_time = hold.capture_time();
-                item.hold_shelf_time = hold.shelf_time();
-                if (hold.cancel_time()) {
-                    item.hold_cancel_time = hold.cancel_time();
-                    if (hold.cancel_cause()) {
-                        item.hold_cancel_cause = hold.cancel_cause().label();
-                    }
+        if (circ) {
+            item.circ = circ;
+            item.due_date = circ.due_date();
+            item.circ_circ_lib = egOrg.get(circ.circ_lib()).shortname();
+            item.circ_xact_start = circ.xact_start();
+            item.circ_stop_fines = circ.stop_fines();
+            // FF patrons will all have cards, but some test logins may not
+            item.patron_card = circ.usr().card() ? 
+                circ.usr().card().barcode() : circ.usr().usrname();
+            item.patron_name = circ.usr().first_given_name() + ' ' + circ.usr().family_name() // i18n
+            item.can_mark_lost = (item.circ && item.copy.status().id() == 1); // checked out
+        }
+
+        if (hold) {
+            item.hold = hold;
+            item.patron_card = hold.usr().card() ? 
+                hold.usr().card().barcode() : hold.usr().usrname();
+            item.patron_name = hold.usr().first_given_name() + ' ' + hold.usr().family_name() // i18n
+            item.hold_request_lib = egOrg.get(hold.request_lib()).shortname();
+            item.hold_pickup_lib = egOrg.get(hold.pickup_lib()).shortname();
+            item.hold_request_time = hold.request_time();
+            item.hold_capture_time = hold.capture_time();
+            item.hold_shelf_time = hold.shelf_time();
+            if (hold.cancel_time()) {
+                item.hold_cancel_time = hold.cancel_time();
+                if (hold.cancel_cause()) {
+                    item.hold_cancel_cause = hold.cancel_cause().label();
                 }
             }
-
-            // TODO: another unnecessary layer of data munging,
-            // this time to fit the print templates.  Can be unified.
-            item.barcode = item.item_barcode;
-            item.status = item.status_str;
-            item.item_circ_lib = item.circ_lib;
         }
-    };
+
+        // TODO: another unnecessary layer of data munging,
+        // this time to fit the print templates.  Can be unified.
+        item.barcode = item.item_barcode;
+        item.status = item.status_str;
+        item.item_circ_lib = item.circ_lib;
+    }
 
     /* Actions
      * Performed on flattened items (see above)
@@ -369,9 +347,8 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
             var deferred = $q.defer();
             $scope.action_pending = true;
             egNet.request(
-              'open-ils.circ',
-              'open-ils.circ.hold.cancel',
-              egAuth.token(), item.hold.id()
+                'open-ils.circ', 'open-ils.circ.hold.cancel',
+                egAuth.token(), item.hold.id()
             ).then(function() {
                 $scope.action_pending = false;
                 deferred.resolve();
@@ -383,8 +360,7 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
             var deferred = $q.defer();
             $scope.action_pending = true;
             egNet.request(
-              'open-ils.circ',
-              'open-ils.circ.hold.reset',
+              'open-ils.circ', 'open-ils.circ.hold.reset',
               egAuth.token(), item.hold.id()
             ).then(function() {
                 $scope.action_pending = false;
@@ -397,10 +373,8 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
             var deferred = $q.defer();
             $scope.action_pending = true;
             egNet.request(
-                'open-ils.circ', 
-                'open-ils.circ.transit.abort',
-                egAuth.token(), 
-                {transitid : item.transit.id()}
+                'open-ils.circ', 'open-ils.circ.transit.abort',
+                egAuth.token(), {transitid : item.transit.id()}
             ).then(function() {
                 $scope.action_pending = false;
                 deferred.resolve();
@@ -412,8 +386,7 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
             var deferred = $q.defer();
             $scope.action_pending = true;
             egNet.request(
-                'open-ils.circ',
-                'open-ils.circ.circulation.set_lost',
+                'open-ils.circ', 'open-ils.circ.circulation.set_lost',
                 egAuth.token(), {barcode : item.item_barcode}
             ).then(function(resp) {
                 $scope.action_pending = false;
@@ -485,14 +458,12 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
         function(action) {
             $scope[action] = function() {
                 var total = Object.keys($scope.itemList.selected).length;
-                angular.forEach(
-                    $scope.itemList.selected,
+                angular.forEach($scope.itemList.selected,
                     function(val, idx) {
                         var item = $scope.itemList.items.filter(
                             function(i) {return i.index == idx})[0];
                         console.debug(item.index + ' => ' + action);
-                        $scope.actions[action](item)
-                        .then(
+                        $scope.actions[action](item).then(
                             // when all items are done processing, reload the route
                             function(resp) {
                                 console.debug(item.index + ' => ' + action + ' : done');
@@ -523,12 +494,12 @@ function ($scope,  $q,  $compile,  $timeout,  $rootScope, $location,
     };
 
     $scope.nextPage = function() {
-        $scope.itemList.offset += $scope.itemList.limit;
+        $scope.itemList.incrementPage();
         $scope.collector();
     };
 
     $scope.prevPage = function() {
-        $scope.itemList.offset -= $scope.itemList.limit;
+        $scope.itemList.decrementPage();
         $scope.collector();
     };
 
@@ -828,7 +799,7 @@ function ($scope,  $q,  $route,  egNet,  egAuth,  egPCRUD,  egOrg,  orgSelector)
             angular.forEach(holds, function(hold) {
                 var display = {
                     id : hold.id(),
-                    index : $scope.itemList.items.length
+                    index : $scope.itemList.count()
                 };
                 // we don't use itemList.addItem(), 
                 // since it fetches data differently