]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/services/record.js
4adfe6cf3c394267608588e30ddaafdea35020df
[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                 $scope.$watch('marcXml', 
64                     function(newVal, oldVal) {
65                         if (newVal && newVal !== oldVal) {
66                             loadRecordHtml();
67                         }
68                     }
69                 );
70
71                 if ($scope.recordId || $scope.marcXml) 
72                     loadRecordHtml();
73             }
74         ]
75     }
76 })
77
78 /*
79  * A record='foo' attribute is required as a storage location of the 
80  * retrieved record
81  */
82 .directive('egRecordSummary', function() {
83     return {
84         restrict : 'AE',
85         scope : {
86             recordId : '=',
87             record : '=',
88             noMarcLink : '@'
89         },
90         templateUrl : './cat/share/t_record_summary',
91         controller : 
92                    ['$scope','egCore',
93             function($scope , egCore) {
94
95                 function loadRecord() {
96                     egCore.pcrud.retrieve('bre', $scope.recordId, {
97                         flesh : 1,
98                         flesh_fields : {
99                             bre : ['simple_record','creator','editor']
100                         }
101                     }).then(function(rec) {
102                         rec.owner(egCore.org.get(rec.owner()));
103                         $scope.record = rec;
104                     });
105                 }
106
107                 $scope.$watch('recordId', 
108                     function(newVal, oldVal) {
109                         if (newVal && newVal !== oldVal) {
110                             loadRecord();
111                         }
112                     }
113                 );
114
115
116                 if ($scope.recordId) 
117                     loadRecord();
118
119                 $scope.toggle_expand_summary = function() {
120                     if ($scope.collapseRecordSummary) {
121                         $scope.collapseRecordSummary = false;
122                         egCore.hatch.removeItem('eg.cat.record.summary.collapse');
123                     } else {
124                         $scope.collapseRecordSummary = true;
125                         egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
126                     }
127                 }
128             
129                 $scope.collapse_summary = function() {
130                     return $scope.collapseRecordSummary;
131                 }
132             
133                 egCore.hatch.getItem('eg.cat.record.summary.collapse')
134                 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
135
136             }
137         ]
138     }
139 })