* 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)
+ });
+ }
}])
/**
// 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()));
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]());
-
- }
- );
});
}
});
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;