From 0254cc45786a89a288ebcf22e398bc0307abbb0e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 4 Nov 2013 14:12:24 -0500 Subject: [PATCH] port list code to egList Signed-off-by: Bill Erickson --- .../src/templates/staff/fulfillment/t_actions.tt2 | 2 +- .../templates/staff/fulfillment/t_item_table.tt2 | 4 +- .../src/templates/staff/fulfillment/t_pending.tt2 | 6 +- .../web/js/ui/default/staff/fulfillment/app.js | 307 ++++++++++----------- 4 files changed, 145 insertions(+), 174 deletions(-) diff --git a/Open-ILS/src/templates/staff/fulfillment/t_actions.tt2 b/Open-ILS/src/templates/staff/fulfillment/t_actions.tt2 index f2aa2e9b3b..a5224096a7 100644 --- a/Open-ILS/src/templates/staff/fulfillment/t_actions.tt2 +++ b/Open-ILS/src/templates/staff/fulfillment/t_actions.tt2 @@ -14,7 +14,7 @@
diff --git a/Open-ILS/src/templates/staff/fulfillment/t_item_table.tt2 b/Open-ILS/src/templates/staff/fulfillment/t_item_table.tt2 index a8971c3ed5..167ca2b409 100644 --- a/Open-ILS/src/templates/staff/fulfillment/t_item_table.tt2 +++ b/Open-ILS/src/templates/staff/fulfillment/t_item_table.tt2 @@ -1,11 +1,11 @@ -
+
[% l('No Items To Display') %]
- +
diff --git a/Open-ILS/src/templates/staff/fulfillment/t_pending.tt2 b/Open-ILS/src/templates/staff/fulfillment/t_pending.tt2 index aa6fca52f1..19f2c446a7 100644 --- a/Open-ILS/src/templates/staff/fulfillment/t_pending.tt2 +++ b/Open-ILS/src/templates/staff/fulfillment/t_pending.tt2 @@ -21,13 +21,13 @@
-
+
[% l('No Items To Display') %]
-
+
@@ -44,7 +44,7 @@ - + diff --git a/Open-ILS/web/js/ui/default/staff/fulfillment/app.js b/Open-ILS/web/js/ui/default/staff/fulfillment/app.js index db860deb0e..3358169135 100644 --- a/Open-ILS/web/js/ui/default/staff/fulfillment/app.js +++ b/Open-ILS/web/js/ui/default/staff/fulfillment/app.js @@ -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 -- 2.11.0
{{item.id}} {{item.request_time | date}} {{item.expire_time | date}}