0) {
for (var field in cn_array[0]) {
$scope.bib_cn = cn_array[0][field];
}
for (var i in cn_array) {
for (var field in cn_array[i]) {
tooltip +=
field + ' : ' + cn_array[i][field] + ' ';
}
}
$scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
}
});
}
$scope.$watch('recordId',
function(newVal, oldVal) {
if (newVal && newVal !== oldVal) {
loadRecord();
}
}
);
if ($scope.recordId)
loadRecord();
$scope.toggle_expand_summary = function() {
if ($scope.collapseRecordSummary) {
$scope.collapseRecordSummary = false;
egCore.hatch.removeItem('eg.cat.record.summary.collapse');
} else {
$scope.collapseRecordSummary = true;
egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
}
}
$scope.collapse_summary = function() {
return $scope.collapseRecordSummary;
}
egCore.hatch.getItem('eg.cat.record.summary.collapse')
.then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
}
]
}
})
/**
* 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 custom fields.
*
* MWDE objects are best suited to cases where the available set of
* display fields must be auto-generated from the IDL. They work well
* with egGrids because it can automatically determine from the IDL
* which fields should be added to the column picker.
*
* MFDE lists are well suited to cases where the set of fields to
* display is known in advance (e.g. hard-coded in the template) or when
* the caller needs data for custom fields. FWIW, MFDE data is slightly
* leaner for retrieval in that it does not require the JSON round-trip
* for delivery.
*
* Example:
*
* --
* // MVR-style canned fields
*
* $scope.record = copy.call_number().record();
*
* // translate wide display entry values inline
* egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
*
* Title:
* {{record.wide_display_entry().title()}}
*
* ---
* // Display any field using known keys
*
* $scope.all_display_fields =
* egBibDisplay.mfdeToHash(record.flat_display_entries());
*
* Title:
* {{all_display_fields.title}}
*
* ---
* // Display all fields dynamically, using confgured labels
*
* $scope.all_display_fields_with_meta =
* egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
*
*
*
Field Label
{{content.label}}
*
*
*
Field Value
{{content.value}}
*
*
*
*/
.factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
var service = {};
/**
* Converts JSON-encoded values within a mwde object to Javascript
* native strings, numbers, and arrays.
*
* @collapseMulti collapse multi=true array values down to a single
* comma-separated string. This is useful for quickly building
* displays (e.g. grids) without having to first munge the array
* into a string.
*/
service.mwdeJSONToJS = function(entry, collapseMulti) {
angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
if (f.virtual) return;
var val = JSON.parse(entry[f.name]());
if (collapseMulti && angular.isArray(val))
val = val.join(', ');
entry[f.name](val);
});
}
/**
* 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.
*
* @collapseMulti See egBibDisplay.mwdeJSONToJS()
*/
service.mfdeToHash = function(entries, collapseMulti) {
var hash = service.mfdeToMetaHash(entries, collapseMulti);
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
*
* @collapseMulti See egBibDisplay.mwdeJSONToJS()
*/
service.mfdeToMetaHash = function(entries, collapseMulti) {
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') {
if (collapseMulti) {
if (angular.isArray(hash[entry.name()].value)) {
// start a new collapsed string
hash[entry.name()].value = entry.value();
} else {
// append to collapsed string in progress
hash[entry.name()].value += ', ' + entry.value();
}
} else {
hash[entry.name()].value.push(entry.value());
}
} else {
hash[entry.name()].value = entry.value();
}
});
return hash;
}
return service;
}])