From a0ca794d1cea4302153d5b2134529441d083c6d5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 14 May 2014 22:32:16 -0400 Subject: [PATCH] item status UI continued; broken ATM Signed-off-by: Bill Erickson --- Open-ILS/src/templates/staff/cat/item/index.tt2 | 25 ++++++- Open-ILS/src/templates/staff/cat/item/t_list.tt2 | 14 +++- Open-ILS/web/js/ui/default/staff/cat/item/app.js | 91 ++++++++++++++++-------- Open-ILS/web/js/ui/default/staff/services/idl.js | 34 ++++++++- 4 files changed, 128 insertions(+), 36 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/item/index.tt2 b/Open-ILS/src/templates/staff/cat/item/index.tt2 index 2e99a90f57..7a774df3dc 100644 --- a/Open-ILS/src/templates/staff/cat/item/index.tt2 +++ b/Open-ILS/src/templates/staff/cat/item/index.tt2 @@ -12,7 +12,30 @@ [% END %] -

search bar goes here

+ + +

[% l('Scan Item') %]

+ +
+
+
+
+ + +
+
+
+
diff --git a/Open-ILS/src/templates/staff/cat/item/t_list.tt2 b/Open-ILS/src/templates/staff/cat/item/t_list.tt2 index 7b02743d2e..316a9f022a 100644 --- a/Open-ILS/src/templates/staff/cat/item/t_list.tt2 +++ b/Open-ILS/src/templates/staff/cat/item/t_list.tt2 @@ -1 +1,13 @@ -

LIST

+ + + + + + + diff --git a/Open-ILS/web/js/ui/default/staff/cat/item/app.js b/Open-ILS/web/js/ui/default/staff/cat/item/app.js index 3699fbba7d..c36e6215d9 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/item/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/item/app.js @@ -33,9 +33,63 @@ angular.module('egItemStatus', * Parent scope for list and detail views */ .controller('SearchCtrl', - ['$scope','$location','egCore', -function($scope , $location , egCore) { -// $location.path('/cat/item/view/' + 46879); + ['$scope','$location','egCore','egGridDataProvider', +function($scope , $location , egCore , egGridDataProvider) { + + $scope.focusBarcode = true; + var copies = []; + + var provider = egGridDataProvider.instance({}); + provider.get = function(offset, count) { + return provider.arrayNotifier(copies, offset, count); + } + provider.itemFieldValue = provider.flatItemFieldValue; + $scope.gridDataProvider = provider; + + $scope.searchCopy = function(args) { + $scope.fetchCopy(args.barcode) + .then(function(copy) { + if (copy) { + copies.unshift(egCore.idl.toHash(copy, true)); + provider.increment(); + } else { + $scope.copyNotFound = true; + } + }); + } + + $scope.fetchCopy(barcode, id) { + var flesh = { + flesh : 3, + flesh_fields : { + acp : ['call_number','location','status','location'], + acn : ['record'], + bre : ['simple_record','creator','editor'] + }, + select : { + // avoid fleshing MARC on the bre + // note: don't add simple_record.. not sure why + bre : ['id','tcn_value','creator','editor'], + } + }; + + var promise; + + if (barcode) { + promise = egCore.pcrud.search('acp', + {barcode : barcode, deleted : 'f'}, flesh); + } else { + promise = egCore.pcrud.retrieve('acp', id, flesh); + } + + promise.then(function(copy) { + if (!copy) { + $scope.copyNotFound = true; + return; + } + return egCore.idl.toHash(copy, true) + }); + } }]) /** @@ -60,27 +114,12 @@ function($scope , $location , $routeParams , egCore) { // TODO: cache data per copy function loadCopy() { - - egCore.pcrud.retrieve('acp', copyId, { - flesh : 3, - flesh_fields : { - acp : ['call_number','location','status','location'], - acn : ['record'], - bre : ['simple_record','creator','editor'] - }, - - select : { - // avoid fleshing MARC on the bre - // note: don't add simple_record.. not sure why - bre : ['id','tcn_value','creator','editor'], - } + $scope.fetchCopy(null, copyId) }).then(function(copy) { + if (!copy) return; - if (!copy) { - $scope.copyNotFound = true; - return; - } + // TODO: FLATTEN EVERYTHING // locally flesh org units copy.circ_lib(egCore.org.get(copy.circ_lib())); @@ -130,16 +169,6 @@ function($scope , $location , $routeParams , egCore) { egCore.auth.token(), circ.id() ).then(function(summary) { $scope.circ_summary = summary; - - console.log(js2JSON(summary)); - console.log(summary.last_checkin_workstation()); - - angular.forEach(egCore.idl.classes.accs.field_map, - function(val, key) { - console.log(key + ' => ' + summary[key]()); - - } - ); }); } }); diff --git a/Open-ILS/web/js/ui/default/staff/services/idl.js b/Open-ILS/web/js/ui/default/staff/services/idl.js index f18e60f30c..8ad4b668dd 100644 --- a/Open-ILS/web/js/ui/default/staff/services/idl.js +++ b/Open-ILS/web/js/ui/default/staff/services/idl.js @@ -59,13 +59,41 @@ angular.module('egCoreMod') mkclass(cls, service.classes[cls].fields); }; - service.toHash = function(obj) { + /** + * Generate a hash version of an IDL object. + * + * Flatten determines if nested objects should be squashed into + * the top-level hash. + * + * If 'flatten' is false, e.g.: + * + * {"call_number" : {"label" : "foo"}} + * + * If 'flatten' is true, e.g.: + * + * e.g. {"call_number.label" : "foo"} + */ + service.toHash = function(obj, flatten) { var hash = {}; angular.forEach( service.classes[obj.classname].fields, function(field) { - if (field.virtual) return; - hash[field.name] = obj[field.name]() + var val = obj[field.name](); + if (val === null || val === undefined) return; + + if (angular.isObject(val) && val._isfieldmapper) { + if (flatten) { + var subhash = service.toHash(val, true); + angular.forEach(subhash, function(val, key) { + var fname = field.name + '.' + key; + hash[fname] = val; + }); + } else { + hash[field.name] = service.toHash(val); + } + } else { + hash[field.name] = val; + } } ) return hash; -- 2.11.0