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 custom fields.
231 * MWDE objects are best suited to cases where the available set of
232 * display fields must be auto-generated from the IDL. They work well
233 * with egGrids because it can automatically determine from the IDL
234 * which fields should be added to the column picker.
236 * MFDE lists are well suited to cases where the set of fields to
237 * display is known in advance (e.g. hard-coded in the template) or when
238 * the caller needs data for custom fields. FWIW, MFDE data is slightly
239 * leaner for retrieval in that it does not require the JSON round-trip
245 * // MVR-style canned fields
247 * $scope.record = copy.call_number().record();
249 * // translate wide display entry values inline
250 * egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
253 * <div>{{record.wide_display_entry().title()}}</div>
256 * // Display any field using known keys
258 * $scope.all_display_fields =
259 * egBibDisplay.mfdeToHash(record.flat_display_entries());
262 * <div>{{all_display_fields.title}}</div>
265 * // Display all fields dynamically, using confgured labels
267 * $scope.all_display_fields_with_meta =
268 * egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
270 * <div ng-repeat="(key, content) in all_display_fields_with_meta">
271 * <div>Field Label</div><div>{{content.label}}</div>
272 * <div ng-if="content.multi == 't'">
273 * <div ng-repeat="val in content.value">
274 * <div>Field Value</div><div>{{val}}</div>
277 * <div ng-if="content.multi == 'f'">
278 * <div>Field Value</div><div>{{content.value}}</div>
283 .factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
287 * Converts JSON-encoded values within a mwde object to Javascript
288 * native strings, numbers, and arrays.
290 * @collapseMulti collapse multi=true array values down to a single
291 * comma-separated string. This is useful for quickly building
292 * displays (e.g. grids) without having to first munge the array
295 service.mwdeJSONToJS = function(entry, collapseMulti) {
296 angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
297 if (f.virtual) return;
298 var val = JSON.parse(entry[f.name]());
299 if (collapseMulti && angular.isArray(val))
300 val = val.join(', ');
306 * Converts a list of 'mfde' entry objects to a simple key=>value hash.
307 * Non-multi values are strings or numbers.
308 * Multi values are arrays of strings or numbers.
310 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
312 service.mfdeToHash = function(entries, collapseMulti) {
313 var hash = service.mfdeToMetaHash(entries, collapseMulti);
314 angular.forEach(hash,
315 function(sub_hash, name) { hash[name] = sub_hash.value });
320 * Converts a list of 'mfde' entry objects to a nested hash like so:
321 * {name => field_name, label => field_label, value => scalar_or_array}
322 * The scalar_or_array value is a string/number or an array of
325 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
327 service.mfdeToMetaHash = function(entries, collapseMulti) {
329 angular.forEach(entries, function(entry) {
331 if (!hash[entry.name()]) {
332 hash[entry.name()] = {
334 label : entry.label(),
335 multi : entry.multi() == 't',
336 value : entry.multi() == 't' ? [] : null
340 if (entry.multi() == 't') {
342 if (angular.isArray(hash[entry.name()].value)) {
343 // start a new collapsed string
344 hash[entry.name()].value = entry.value();
346 // append to collapsed string in progress
347 hash[entry.name()].value += ', ' + entry.value();
350 hash[entry.name()].value.push(entry.value());
353 hash[entry.name()].value = entry.value();