]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/services/record.js
webstaff: teach eg-record-html how to initialize itself from MARCXML
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / services / record.js
1 /**
2  * Simple directive for rending the HTML view of a MARC record.
3  *
4  * <eg-record-html record-id="myRecordIdScopeVariable"></eg-record-id>
5  * OR
6  * <eg-record-html marc-xml="myMarcXmlVariable"></eg-record-html>
7  *
8  * The value of myRecordIdScopeVariable is watched internally and the 
9  * record is updated to match.
10  */
11 angular.module('egCoreMod')
12
13 .directive('egRecordHtml', function() {
14     return {
15         restrict : 'AE',
16         scope : {
17             recordId : '=',
18             marcXml  : '@',
19         },
20         link : function(scope, element, attrs) {
21             scope.element = angular.element(element);
22
23             // kill refs to destroyed DOM elements
24             element.bind("$destroy", function() {
25                 delete scope.element;
26             });
27         },
28         controller : 
29                    ['$scope','egCore',
30             function($scope , egCore) {
31
32                 function loadRecordHtml() {
33                     egCore.net.request(
34                         'open-ils.search',
35                         'open-ils.search.biblio.record.html',
36                         $scope.recordId,
37                         false,
38                         $scope.marcXml
39                     ).then(function(html) {
40                         if (!html) return;
41
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.
45                         html = html.replace(
46                             /<button onclick="window.print(.*?)<\/button>/,'');
47                         html = html.replace(/<title>(.*?)<\/title>/,'');
48
49                         // remove reference to nonexistant CSS file
50                         html = html.replace(/<link(.*?)\/>/,'');
51
52                         $scope.element.html(html);
53                     });
54                 }
55
56                 $scope.$watch('recordId', 
57                     function(newVal, oldVal) {
58                         if (newVal && newVal !== oldVal) {
59                             loadRecordHtml();
60                         }
61                     }
62                 );
63
64                 if ($scope.recordId || $scope.marcXml) 
65                     loadRecordHtml();
66             }
67         ]
68     }
69 })
70
71 /*
72  * A record='foo' attribute is required as a storage location of the 
73  * retrieved record
74  */
75 .directive('egRecordSummary', function() {
76     return {
77         restrict : 'AE',
78         scope : {
79             recordId : '=',
80             record : '=',
81             noMarcLink : '@'
82         },
83         templateUrl : './cat/share/t_record_summary',
84         controller : 
85                    ['$scope','egCore',
86             function($scope , egCore) {
87
88                 function loadRecord() {
89                     egCore.pcrud.retrieve('bre', $scope.recordId, {
90                         flesh : 1,
91                         flesh_fields : {
92                             bre : ['simple_record','creator','editor']
93                         }
94                     }).then(function(rec) {
95                         rec.owner(egCore.org.get(rec.owner()));
96                         $scope.record = rec;
97                     });
98                 }
99
100                 $scope.$watch('recordId', 
101                     function(newVal, oldVal) {
102                         if (newVal && newVal !== oldVal) {
103                             loadRecord();
104                         }
105                     }
106                 );
107
108
109                 if ($scope.recordId) 
110                     loadRecord();
111
112                 $scope.toggle_expand_summary = function() {
113                     if ($scope.collapseRecordSummary) {
114                         $scope.collapseRecordSummary = false;
115                         egCore.hatch.removeItem('eg.cat.record.summary.collapse');
116                     } else {
117                         $scope.collapseRecordSummary = true;
118                         egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
119                     }
120                 }
121             
122                 $scope.collapse_summary = function() {
123                     return $scope.collapseRecordSummary;
124                 }
125             
126                 egCore.hatch.getItem('eg.cat.record.summary.collapse')
127                 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
128
129             }
130         ]
131     }
132 })