webstaff: fetch MVR to help build record summary
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / services / record.js
index 19e86ad..853a046 100644 (file)
@@ -1,7 +1,9 @@
 /**
- * Simple directive for rending the HTML view of a bib record.
+ * Simple directive for rending the HTML view of a MARC record.
  *
  * <eg-record-html record-id="myRecordIdScopeVariable"></eg-record-id>
+ * OR
+ * <eg-record-html marc-xml="myMarcXmlVariable"></eg-record-html>
  *
  * The value of myRecordIdScopeVariable is watched internally and the 
  * record is updated to match.
@@ -11,7 +13,10 @@ angular.module('egCoreMod')
 .directive('egRecordHtml', function() {
     return {
         restrict : 'AE',
-        scope : {recordId : '='},
+        scope : {
+            recordId : '=',
+            marcXml  : '@',
+        },
         link : function(scope, element, attrs) {
             scope.element = angular.element(element);
 
@@ -28,7 +33,9 @@ angular.module('egCoreMod')
                     egCore.net.request(
                         'open-ils.search',
                         'open-ils.search.biblio.record.html',
-                        $scope.recordId
+                        $scope.recordId,
+                        false,
+                        $scope.marcXml
                     ).then(function(html) {
                         if (!html) return;
 
@@ -53,14 +60,75 @@ angular.module('egCoreMod')
                         }
                     }
                 );
+                $scope.$watch('marcXml', 
+                    function(newVal, oldVal) {
+                        if (newVal && newVal !== oldVal) {
+                            loadRecordHtml();
+                        }
+                    }
+                );
 
-                if ($scope.recordId) 
+                if ($scope.recordId || $scope.marcXml
                     loadRecordHtml();
             }
         ]
     }
 })
 
+.directive('egRecordBreaker', function() {
+    return {
+        restrict : 'AE',
+        template : '<pre>{{breaker}}</pre>',
+        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
@@ -70,23 +138,54 @@ angular.module('egCoreMod')
         restrict : 'AE',
         scope : {
             recordId : '=',
-            record : '='
+            record : '=',
+            noMarcLink : '@'
         },
         templateUrl : './cat/share/t_record_summary',
         controller : 
-                   ['$scope','egCore',
-            function($scope , egCore) {
+                   ['$scope','egCore','$sce',
+            function($scope , egCore , $sce) {
 
                 function loadRecord() {
                     egCore.pcrud.retrieve('bre', $scope.recordId, {
                         flesh : 1,
                         flesh_fields : {
-                            bre : ['simple_record','creator','editor']
+                            bre : ['creator','editor']
                         }
                     }).then(function(rec) {
                         rec.owner(egCore.org.get(rec.owner()));
                         $scope.record = rec;
                     });
+                    egCore.net.request(
+                        'open-ils.search',
+                        'open-ils.search.biblio.record.mods_slim.retrieve.authoritative',
+                        $scope.recordId
+                    ).then(function(mvr) {
+                        $scope.mvr = mvr;
+                    });
+                    $scope.bib_cn = null;
+                    $scope.bib_cn_tooltip = '';
+                    var label_class = egCore.env.aous['cat.default_classification_scheme'] || 1;
+                    egCore.net.request(
+                        'open-ils.cat',
+                        'open-ils.cat.biblio.record.marc_cn.retrieve',
+                        $scope.recordId,
+                        label_class
+                    ).then(function(cn_array) {
+                        var tooltip = '';
+                        if (cn_array.length > 0) {
+                            for (var field in cn_array[0]) {
+                                $scope.bib_cn = cn_array[0][field];
+                            }
+                            for (var i in cn_array) {
+                                for (var field in cn_array[i]) {
+                                    tooltip += 
+                                        field + ' : ' + cn_array[i][field] + '<br>';
+                                }
+                            }
+                            $scope.bib_cn_tooltip = $sce.trustAsHtml(tooltip);
+                        }
+                    });
                 }
 
                 $scope.$watch('recordId',