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 = '';
164 egCore.org.settings(['cat.default_classification_scheme'])
166 var scheme = s['cat.default_classification_scheme'];
167 label_class = scheme || 1;
169 return egCore.net.request(
171 'open-ils.cat.biblio.record.marc_cn.retrieve',
175 }).then(function(cn_array) {
177 if (cn_array.length > 0) {
178 for (var field in cn_array[0]) {
179 $scope.bib_cn = cn_array[0][field];
181 for (var i in cn_array) {
182 for (var field in cn_array[i]) {
184 field + ' : ' + cn_array[i][field] + '<br>';
187 $scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
192 $scope.$watch('recordId',
193 function(newVal, oldVal) {
194 if (newVal && newVal !== oldVal) {
204 $scope.toggle_expand_summary = function() {
205 if ($scope.collapseRecordSummary) {
206 $scope.collapseRecordSummary = false;
207 egCore.hatch.removeItem('eg.cat.record.summary.collapse');
209 $scope.collapseRecordSummary = true;
210 egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
214 $scope.collapse_summary = function() {
215 return $scope.collapseRecordSummary;
218 egCore.hatch.getItem('eg.cat.record.summary.collapse')
219 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
227 * Utility functions for translating bib record display fields into
228 * various formats / structures.
230 * Note that 'mwde' objects (which are proper IDL objects) only contain
231 * the prescribed fields from the IDL (and database view), while the
232 * 'mfde' hash-based objects contain all configured display fields,
233 * including custom fields.
235 * MWDE objects are best suited to cases where the available set of
236 * display fields must be auto-generated from the IDL. They work well
237 * with egGrids because it can automatically determine from the IDL
238 * which fields should be added to the column picker.
240 * MFDE lists are well suited to cases where the set of fields to
241 * display is known in advance (e.g. hard-coded in the template) or when
242 * the caller needs data for custom fields. FWIW, MFDE data is slightly
243 * leaner for retrieval in that it does not require the JSON round-trip
249 * // MVR-style canned fields
251 * $scope.record = copy.call_number().record();
253 * // translate wide display entry values inline
254 * egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
257 * <div>{{record.wide_display_entry().title()}}</div>
260 * // Display any field using known keys
262 * $scope.all_display_fields =
263 * egBibDisplay.mfdeToHash(record.flat_display_entries());
266 * <div>{{all_display_fields.title}}</div>
269 * // Display all fields dynamically, using confgured labels
271 * $scope.all_display_fields_with_meta =
272 * egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
274 * <div ng-repeat="(key, content) in all_display_fields_with_meta">
275 * <div>Field Label</div><div>{{content.label}}</div>
276 * <div ng-if="content.multi == 't'">
277 * <div ng-repeat="val in content.value">
278 * <div>Field Value</div><div>{{val}}</div>
281 * <div ng-if="content.multi == 'f'">
282 * <div>Field Value</div><div>{{content.value}}</div>
287 .factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
291 * Converts JSON-encoded values within a mwde object to Javascript
292 * native strings, numbers, and arrays.
294 * @collapseMulti collapse multi=true array values down to a single
295 * comma-separated string. This is useful for quickly building
296 * displays (e.g. grids) without having to first munge the array
299 service.mwdeJSONToJS = function(entry, collapseMulti) {
300 angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
301 if (f.virtual) return;
302 var val = JSON.parse(entry[f.name]());
303 if (collapseMulti && angular.isArray(val))
304 val = val.join(', ');
310 * Converts a list of 'mfde' entry objects to a simple key=>value hash.
311 * Non-multi values are strings or numbers.
312 * Multi values are arrays of strings or numbers.
314 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
316 service.mfdeToHash = function(entries, collapseMulti) {
317 var hash = service.mfdeToMetaHash(entries, collapseMulti);
318 angular.forEach(hash,
319 function(sub_hash, name) { hash[name] = sub_hash.value });
324 * Converts a list of 'mfde' entry objects to a nested hash like so:
325 * {name => field_name, label => field_label, value => scalar_or_array}
326 * The scalar_or_array value is a string/number or an array of
329 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
331 service.mfdeToMetaHash = function(entries, collapseMulti) {
333 angular.forEach(entries, function(entry) {
335 if (!hash[entry.name()]) {
336 hash[entry.name()] = {
338 label : entry.label(),
339 multi : entry.multi() == 't',
340 value : entry.multi() == 't' ? [] : null
344 if (entry.multi() == 't') {
346 if (angular.isArray(hash[entry.name()].value)) {
347 // start a new collapsed string
348 hash[entry.name()].value = entry.value();
350 // append to collapsed string in progress
351 hash[entry.name()].value += ', ' + entry.value();
354 hash[entry.name()].value.push(entry.value());
357 hash[entry.name()].value = entry.value();