2 * Simple directive for rending the HTML view of a MARC record.
4 * <eg-record-html record-id="myRecordIdScopeVariable"></eg-record-id>
6 * <eg-record-html marc-xml="myMarcXmlVariable"></eg-record-html>
8 * The value of myRecordIdScopeVariable is watched internally and the
9 * record is updated to match.
11 angular.module('egCoreMod')
13 .directive('egRecordHtml', function() {
20 link : function(scope, element, attrs) {
21 scope.element = angular.element(element);
23 // kill refs to destroyed DOM elements
24 element.bind("$destroy", function() {
30 function($scope , egCore) {
32 function loadRecordHtml() {
35 'open-ils.search.biblio.record.html',
39 ).then(function(html) {
42 // Remove those pesky non-i8n labels / actions.
43 // Note: for printing, use the browser print page
44 // option. The end result is the same.
46 /<button onclick="window.print(.*?)<\/button>/,'');
47 html = html.replace(/<title>(.*?)<\/title>/,'');
49 // remove reference to nonexistant CSS file
50 html = html.replace(/<link(.*?)\/>/,'');
52 $scope.element.html(html);
56 $scope.$watch('recordId',
57 function(newVal, oldVal) {
58 if (newVal && newVal !== oldVal) {
63 $scope.$watch('marcXml',
64 function(newVal, oldVal) {
65 if (newVal && newVal !== oldVal) {
71 if ($scope.recordId || $scope.marcXml)
78 .directive('egRecordBreaker', function() {
81 template : '<pre>{{breaker}}</pre>',
86 link : function(scope, element, attrs) {
87 scope.element = angular.element(element);
89 // kill refs to destroyed DOM elements
90 element.bind("$destroy", function() {
96 function($scope , egCore) {
98 function loadRecordBreaker() {
100 if ($scope.marcXml) {
101 $scope.breaker = new MARC21.Record({ marcxml : $scope.marcXml }).toBreaker();
103 egCore.pcrud.retrieve('bre', $scope.recordId)
104 .then(function(rec) {
105 $scope.breaker = new MARC21.Record({ marcxml : rec.marc() }).toBreaker();
110 $scope.$watch('recordId',
111 function(newVal, oldVal) {
112 if (newVal && newVal !== oldVal) {
117 $scope.$watch('marcXml',
118 function(newVal, oldVal) {
119 if (newVal && newVal !== oldVal) {
125 if ($scope.recordId || $scope.marcXml)
133 * A record='foo' attribute is required as a storage location of the
136 .directive('egRecordSummary', function() {
144 templateUrl : './cat/share/t_record_summary',
146 ['$scope','egCore','$sce','egBibDisplay',
147 function($scope , egCore , $sce , egBibDisplay) {
149 function loadRecord() {
150 egCore.pcrud.retrieve('bre', $scope.recordId, {
153 bre : ['creator','editor','flat_display_entries']
155 }).then(function(rec) {
156 rec.owner(egCore.org.get(rec.owner()));
159 egBibDisplay.mfdeToHash(rec.flat_display_entries());
161 $scope.bib_cn = null;
162 $scope.bib_cn_tooltip = '';
165 label_class = egCore.env.aous['cat.default_classification_scheme'] || 1;
168 'open-ils.cat.biblio.record.marc_cn.retrieve',
171 ).then(function(cn_array) {
173 if (cn_array.length > 0) {
174 for (var field in cn_array[0]) {
175 $scope.bib_cn = cn_array[0][field];
177 for (var i in cn_array) {
178 for (var field in cn_array[i]) {
180 field + ' : ' + cn_array[i][field] + '<br>';
183 $scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
188 $scope.$watch('recordId',
189 function(newVal, oldVal) {
190 if (newVal && newVal !== oldVal) {
200 $scope.toggle_expand_summary = function() {
201 if ($scope.collapseRecordSummary) {
202 $scope.collapseRecordSummary = false;
203 egCore.hatch.removeItem('eg.cat.record.summary.collapse');
205 $scope.collapseRecordSummary = true;
206 egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
210 $scope.collapse_summary = function() {
211 return $scope.collapseRecordSummary;
214 egCore.hatch.getItem('eg.cat.record.summary.collapse')
215 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
223 * Utility functions for translating bib record display fields into
224 * various formats / structures.
226 * Note that 'mwde' objects (which are proper IDL objects) only contain
227 * the prescribed fields from the IDL (and database view), while the
228 * 'mfde' hash-based objects contain all configured display fields,
229 * including local/custom fields.
234 * // Display well-known fields
236 * $scope.record = copy.call_number().record();
238 * // translate wide display entry values inline
239 * egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
242 * <div>{{record.wide_display_entry().title()}}</div>
245 * // Display any field using known keys
247 * $scope.all_display_fields =
248 * egBibDisplay.mfdeToHash(record.flat_display_entries());
251 * <div>{{all_display_fields.title}}</div>
254 * // Display all fields dynamically, using confgured labels
256 * $scope.all_display_fields_with_meta =
257 * egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
259 * <div ng-repeat="(key, content) in all_display_fields_with_meta">
260 * <div>Field Label</div><div>{{content.label}}</div>
261 * <div ng-if="content.multi == 't'">
262 * <div ng-repeat="val in content.value">
263 * <div>Field Value</div><div>{{val}}</div>
266 * <div ng-if="content.multi == 'f'">
267 * <div>Field Value</div><div>{{content.value}}</div>
272 .factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
276 * Converts JSON-encoded values within a mwde object to Javascript
277 * native strings, numbers, and arrays.
279 * @collapseMulti collapse array (multi) fields down to a single string
280 * with values separated by a comma+space. Useful for quickly
281 * building displays (e.g. grids) without having to first munge
282 * the array into a string.
284 service.mwdeJSONToJS = function(entry, collapseMulti) {
285 angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
286 if (f.virtual) return;
287 var val = JSON.parse(entry[f.name]());
288 if (collapseMulti && angular.isArray(val))
289 val = val.join(', ');
295 * Converts a list of 'mfde' entry objects to a simple key=>value hash.
296 * Non-multi values are strings or numbers.
297 * Multi values are arrays of strings or numbers.
299 * @collapseMulti See service.mwdeJSONToJS()
301 service.mfdeToHash = function(entries, collapseMulti) {
302 var hash = service.mfdeToMetaHash(entries, collapseMulti);
303 angular.forEach(hash,
304 function(sub_hash, name) { hash[name] = sub_hash.value });
309 * Converts a list of 'mfde' entry objects to a nested hash like so:
310 * {name => field_name, label => field_label, value => scalar_or_array}
311 * The scalar_or_array value is a string/number or an array of
314 * @collapseMulti See service.mwdeJSONToJS()
316 service.mfdeToMetaHash = function(entries, collapseMulti) {
318 angular.forEach(entries, function(entry) {
320 if (!hash[entry.name()]) {
321 hash[entry.name()] = {
323 label : entry.label(),
324 multi : entry.multi() == 't',
325 value : entry.multi() == 't' ? [] : null
329 if (entry.multi() == 't') {
331 if (angular.isArray(hash[entry.name()].value)) {
332 // new collapsed string
333 hash[entry.name()].value = entry.value();
335 // append to collapsed string
336 hash[entry.name()].value += ', ' + entry.value();
339 hash[entry.name()].value.push(entry.value());
342 hash[entry.name()].value = entry.value();