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',
147 function($scope , egCore , $sce) {
149 function loadRecord() {
150 egCore.pcrud.retrieve('bre', $scope.recordId, {
153 bre : ['creator','editor']
155 }).then(function(rec) {
156 rec.owner(egCore.org.get(rec.owner()));
161 'open-ils.search.biblio.record.mods_slim.retrieve.authoritative',
163 ).then(function(mvr) {
166 $scope.bib_cn = null;
167 $scope.bib_cn_tooltip = '';
170 label_class = egCore.env.aous['cat.default_classification_scheme'] || 1;
173 'open-ils.cat.biblio.record.marc_cn.retrieve',
176 ).then(function(cn_array) {
178 if (cn_array.length > 0) {
179 for (var field in cn_array[0]) {
180 $scope.bib_cn = cn_array[0][field];
182 for (var i in cn_array) {
183 for (var field in cn_array[i]) {
185 field + ' : ' + cn_array[i][field] + '<br>';
188 $scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
193 $scope.$watch('recordId',
194 function(newVal, oldVal) {
195 if (newVal && newVal !== oldVal) {
205 $scope.toggle_expand_summary = function() {
206 if ($scope.collapseRecordSummary) {
207 $scope.collapseRecordSummary = false;
208 egCore.hatch.removeItem('eg.cat.record.summary.collapse');
210 $scope.collapseRecordSummary = true;
211 egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
215 $scope.collapse_summary = function() {
216 return $scope.collapseRecordSummary;
219 egCore.hatch.getItem('eg.cat.record.summary.collapse')
220 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
228 * Utility functions for translating bib record display fields into
229 * various formats / structures.
231 * Note that 'mwde' objects (which are proper IDL objects) only contain
232 * the prescribed fields from the IDL (and database view), while the
233 * 'mfde' hash-based objects contain all configured display fields,
234 * including local/custom fields.
239 * // Display well-known fields
241 * $scope.record = copy.call_number().record();
243 * // translate wide display entry values inline
244 * egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
247 * <div>{{record.wide_display_entry().title()}}</div>
250 * // Display any field using known keys
252 * $scope.all_display_fields =
253 * egBibDisplay.mfdeToHash(record.flat_display_entries());
256 * <div>{{all_display_fields.title}}</div>
259 * // Display all fields dynamically, using confgured labels
261 * $scope.all_display_fields_with_meta =
262 * egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
264 * <div ng-repeat="(key, content) in all_display_fields_with_meta">
265 * <div>Field Label</div><div>{{content.label}}</div>
266 * <div ng-if="content.multi == 't'">
267 * <div ng-repeat="val in content.value">
268 * <div>Field Value</div><div>{{val}}</div>
271 * <div ng-if="content.multi == 'f'">
272 * <div>Field Value</div><div>{{content.value}}</div>
277 .factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
281 * Converts JSON-encoded values within a mwde object to Javascript
282 * native strings, numbers, and arrays.
284 * @collapseMulti collapse array (multi) fields down to a single string
285 * with values separated by a comma+space. Useful for quickly
286 * building displays (e.g. grids) without having to first munge
287 * the array into a string.
289 service.mwdeJSONToJS = function(entry, collapseMulti) {
290 angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
291 if (f.virtual) return;
292 var val = JSON.parse(entry[f.name]());
293 if (collapseMulti && angular.isArray(val))
294 val = val.join(', ');
300 * Converts a list of 'mfde' entry objects to a simple key=>value hash.
301 * Non-multi values are strings or numbers.
302 * Multi values are arrays of strings or numbers.
304 * @collapseMulti See service.mwdeJSONToJS()
306 service.mfdeToHash = function(entries, collapseMulti) {
307 var hash = service.mfdeToMetaHash(entries, collapseMulti);
308 angular.forEach(hash,
309 function(sub_hash, name) { hash[name] = sub_hash.value });
314 * Converts a list of 'mfde' entry objects to a nested hash like so:
315 * {name => field_name, label => field_label, value => scalar_or_array}
316 * The scalar_or_array value is a string/number or an array of
319 * @collapseMulti See service.mwdeJSONToJS()
321 service.mfdeToMetaHash = function(entries, collapseMulti) {
323 angular.forEach(entries, function(entry) {
325 if (!hash[entry.name()]) {
326 hash[entry.name()] = {
328 label : entry.label(),
329 multi : entry.multi() == 't',
330 value : entry.multi() == 't' ? [] : null
334 if (entry.multi() == 't') {
336 if (angular.isArray(hash[entry.name()].value)) {
337 // new collapsed string
338 hash[entry.name()].value = entry.value();
340 // append to collapsed string
341 hash[entry.name()].value += ', ' + entry.value();
344 hash[entry.name()].value.push(entry.value());
347 hash[entry.name()].value = entry.value();