From 6ed5e2e821bc2fc38f6b2432e84b8eaa8670c130 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 6 Oct 2015 17:28:58 +0000 Subject: [PATCH 1/1] webstaff: add egRecordBreaker directive This directive takes a blob of MARCXML or a bib record ID and renders the record in "breaker" format. Example usage: Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- .../ui/default/staff/cat/services/record.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/record.js b/Open-ILS/web/js/ui/default/staff/cat/services/record.js index 4adfe6cf3c..c54bc951d2 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/record.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/record.js @@ -75,6 +75,60 @@ angular.module('egCoreMod') } }) +.directive('egRecordBreaker', function() { + return { + restrict : 'AE', + template : '
{{breaker}}
', + scope : { + recordId : '=', + marcXml : '@', + }, + link : function(scope, element, attrs) { + scope.element = angular.element(element); + + // kill refs to destroyed DOM elements + element.bind("$destroy", function() { + delete scope.element; + }); + }, + controller : + ['$scope','egCore', + function($scope , egCore) { + + function loadRecordBreaker() { + var xml; + if ($scope.marcXml) { + $scope.breaker = new MARC21.Record({ marcxml : $scope.marcXml }).toBreaker(); + } else { + egCore.pcrud.retrieve('bre', $scope.recordId) + .then(function(rec) { + $scope.breaker = new MARC21.Record({ marcxml : rec.marc() }).toBreaker(); + }); + } + } + + $scope.$watch('recordId', + function(newVal, oldVal) { + if (newVal && newVal !== oldVal) { + loadRecordBreaker(); + } + } + ); + $scope.$watch('marcXml', + function(newVal, oldVal) { + if (newVal && newVal !== oldVal) { + loadRecordBreaker(); + } + } + ); + + if ($scope.recordId || $scope.marcXml) + loadRecordBreaker(); + } + ] + } +}) + /* * A record='foo' attribute is required as a storage location of the * retrieved record -- 2.43.2