]
}
})
+
+/**
+ * Utility functions for translating bib record display fields into
+ * various formats / structures.
+ *
+ * Note that 'mwde' objects (which are proper IDL objects) only contain
+ * the prescribed fields from the IDL (and database view), while the
+ * 'mfde' hash-based objects contain all configured display fields,
+ * including local/custom fields.
+ */
+.factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
+ var service = {};
+
+ /**
+ * Converts JSON-encoded values within a mwde object to Javascript
+ * native strings, numbers, and arrays.
+ */
+ service.mwdeJSONToJS = function(entry) {
+ angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
+ if (f.virtual) return;
+ entry[f.name](JSON.parse(entry[f.name]()));
+ });
+ }
+
+ /**
+ * Converts a list of 'mfde' entry objects to a simple key=>value hash.
+ * Non-multi values are strings or numbers.
+ * Multi values are arrays of strings or numbers.
+ */
+ service.mfdeToHash = function(entries) {
+ var hash = service.mfdeToMetaHash(entries);
+ angular.forEach(hash,
+ function(sub_hash, name) { hash[name] = sub_hash.value });
+ return hash;
+ }
+
+ /**
+ * Converts a list of 'mfde' entry objects to a nested hash like so:
+ * {name => field_name, label => field_label, value => scalar_or_array}
+ * The scalar_or_array value is a string/number or an array of
+ * string/numbers
+ */
+ service.mfdeToMetaHash = function(entries) {
+ var hash = {};
+ angular.forEach(entries, function(entry) {
+
+ if (!hash[entry.name()]) {
+ hash[entry.name()] = {
+ name : entry.name(),
+ label : entry.label(),
+ multi : entry.multi() == 't',
+ value : entry.multi() == 't' ? [] : null
+ }
+ }
+
+ if (entry.multi() == 't') {
+ hash[entry.name()].value.push(entry.value());
+ } else {
+ hash[entry.name()].value = entry.value();
+ }
+ });
+
+ return hash;
+ }
+
+ return service;
+}])
.controller('PatronItemsOutCtrl',
['$scope','$q','$routeParams','$timeout','egCore','egUser','patronSvc','$location',
'egGridDataProvider','$uibModal','egCirc','egConfirmDialog','egBilling','$window',
+ 'egBibDisplay',
function($scope, $q, $routeParams, $timeout, egCore , egUser, patronSvc , $location,
- egGridDataProvider , $uibModal , egCirc , egConfirmDialog , egBilling , $window) {
+ egGridDataProvider , $uibModal , egCirc , egConfirmDialog , egBilling , $window,
+ egBibDisplay) {
// list of noncatatloged circulations. Define before initTab to
// avoid any possibility of race condition, since they are loaded
}).then(null, null, function(circ) {
circ.circ_lib(egCore.org.get(circ.circ_lib())); // local fleshing
- // TODO: move to shared service
- // Un-JSON-ify display field data
- var wde = circ.target_copy().call_number().record().wide_display_entry();
- angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
- if (f.virtual) return;
- wde[f.name](JSON.parse(wde[f.name]()));
- });
+ egBibDisplay.mwdeJSONToJS(
+ circ.target_copy().call_number().record().wide_display_entry());
if (circ.target_copy().call_number().id() == -1) {
// dummy-up a record for precat items