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() {
145 templateUrl : function(element, attrs) {
146 if (attrs.mode == "slim") {
147 return './cat/share/t_record_summary_slim';
149 return './cat/share/t_record_summary';
152 ['$scope','egCore','$sce','egBibDisplay',
153 function($scope , egCore , $sce , egBibDisplay) {
155 function loadRecord() {
156 egCore.pcrud.retrieve('bre', $scope.recordId, {
159 bre : ['creator','editor','flat_display_entries']
161 }).then(function(rec) {
162 rec.owner(egCore.org.get(rec.owner()));
165 egBibDisplay.mfdeToHash(rec.flat_display_entries());
167 $scope.bib_cn = null;
168 $scope.bib_cn_tooltip = '';
170 egCore.org.settings(['cat.default_classification_scheme'])
172 var scheme = s['cat.default_classification_scheme'];
173 label_class = scheme || 1;
175 return egCore.net.request(
177 'open-ils.cat.biblio.record.marc_cn.retrieve',
181 }).then(function(cn_array) {
183 if (cn_array.length > 0) {
184 for (var field in cn_array[0]) {
185 $scope.bib_cn = cn_array[0][field];
187 for (var i in cn_array) {
188 for (var field in cn_array[i]) {
190 field + ' : ' + cn_array[i][field] + '<br>';
193 $scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
198 $scope.$watch('recordId',
199 function(newVal, oldVal) {
200 if (newVal && newVal !== oldVal) {
210 $scope.toggle_expand_summary = function() {
211 if ($scope.collapseRecordSummary) {
212 $scope.collapseRecordSummary = false;
213 egCore.hatch.removeItem('eg.cat.record.summary.collapse');
215 $scope.collapseRecordSummary = true;
216 egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
220 $scope.collapse_summary = function() {
221 return $scope.collapseRecordSummary;
224 egCore.hatch.getItem('eg.cat.record.summary.collapse')
225 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
233 * Utility functions for translating bib record display fields into
234 * various formats / structures.
236 * Note that 'mwde' objects (which are proper IDL objects) only contain
237 * the prescribed fields from the IDL (and database view), while the
238 * 'mfde' hash-based objects contain all configured display fields,
239 * including custom fields.
241 * MWDE objects are best suited to cases where the available set of
242 * display fields must be auto-generated from the IDL. They work well
243 * with egGrids because it can automatically determine from the IDL
244 * which fields should be added to the column picker.
246 * MFDE lists are well suited to cases where the set of fields to
247 * display is known in advance (e.g. hard-coded in the template) or when
248 * the caller needs data for custom fields. FWIW, MFDE data is slightly
249 * leaner for retrieval in that it does not require the JSON round-trip
255 * // MVR-style canned fields
257 * $scope.record = copy.call_number().record();
259 * // translate wide display entry values inline
260 * egBibDisplay.mwdeJSONToJS($scope.record.wide_display_entry());
263 * <div>{{record.wide_display_entry().title()}}</div>
266 * // Display any field using known keys
268 * $scope.all_display_fields =
269 * egBibDisplay.mfdeToHash(record.flat_display_entries());
272 * <div>{{all_display_fields.title}}</div>
275 * // Display all fields dynamically, using confgured labels
277 * $scope.all_display_fields_with_meta =
278 * egBibDisplay.mfdeToMetaHash(record.flat_display_entries());
280 * <div ng-repeat="(key, content) in all_display_fields_with_meta">
281 * <div>Field Label</div><div>{{content.label}}</div>
282 * <div ng-if="content.multi == 't'">
283 * <div ng-repeat="val in content.value">
284 * <div>Field Value</div><div>{{val}}</div>
287 * <div ng-if="content.multi == 'f'">
288 * <div>Field Value</div><div>{{content.value}}</div>
293 .factory('egBibDisplay', ['$q', 'egCore', function($q, egCore) {
297 * Converts JSON-encoded values within a mwde object to Javascript
298 * native strings, numbers, and arrays.
300 * @collapseMulti collapse multi=true array values down to a single
301 * comma-separated string. This is useful for quickly building
302 * displays (e.g. grids) without having to first munge the array
305 service.mwdeJSONToJS = function(entry, collapseMulti) {
306 angular.forEach(egCore.idl.classes.mwde.fields, function(f) {
307 if (f.virtual) return;
308 var val = JSON.parse(entry[f.name]());
309 if (collapseMulti && angular.isArray(val))
310 val = val.join(', ');
316 * Converts a list of 'mfde' entry objects to a simple key=>value hash.
317 * Non-multi values are strings or numbers.
318 * Multi values are arrays of strings or numbers.
320 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
322 service.mfdeToHash = function(entries, collapseMulti) {
323 var hash = service.mfdeToMetaHash(entries, collapseMulti);
324 angular.forEach(hash,
325 function(sub_hash, name) { hash[name] = sub_hash.value });
330 * Converts a list of 'mfde' entry objects to a nested hash like so:
331 * {name => field_name, label => field_label, value => scalar_or_array}
332 * The scalar_or_array value is a string/number or an array of
335 * @collapseMulti See egBibDisplay.mwdeJSONToJS()
337 service.mfdeToMetaHash = function(entries, collapseMulti) {
339 angular.forEach(entries, function(entry) {
341 if (!hash[entry.name()]) {
342 hash[entry.name()] = {
344 label : entry.label(),
345 multi : entry.multi() == 't',
346 value : entry.multi() == 't' ? [] : null
350 if (entry.multi() == 't') {
352 if (angular.isArray(hash[entry.name()].value)) {
353 // start a new collapsed string
354 hash[entry.name()].value = entry.value();
356 // append to collapsed string in progress
357 hash[entry.name()].value += ', ' + entry.value();
360 hash[entry.name()].value.push(entry.value());
363 hash[entry.name()].value = entry.value();