]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/cat/services/record.js
6975b273b7a1a80d9dae9be3f1908f70b42482b2
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / cat / services / record.js
1 /**
2  * Simple directive for rending the HTML view of a bib record.
3  *
4  * <eg-record-html record-id="myRecordIdScopeVariable"></eg-record-id>
5  *
6  * The value of myRecordIdScopeVariable is watched internally and the 
7  * record is updated to match.
8  */
9 angular.module('egCoreMod')
10
11 .directive('egRecordHtml', function() {
12     return {
13         restrict : 'AE',
14         scope : {recordId : '='},
15         link : function(scope, element, attrs) {
16             scope.element = angular.element(element);
17
18             // kill refs to destroyed DOM elements
19             element.bind("$destroy", function() {
20                 delete scope.element;
21             });
22         },
23         controller : 
24                    ['$scope','egCore',
25             function($scope , egCore) {
26
27                 function loadRecordHtml() {
28                     egCore.net.request(
29                         'open-ils.search',
30                         'open-ils.search.biblio.record.html',
31                         $scope.recordId
32                     ).then(function(html) {
33                         if (!html) return;
34
35                         // Remove those pesky non-i8n labels / actions.
36                         // Note: for printing, use the browser print page
37                         // option.  The end result is the same.
38                         html = html.replace(
39                             /<button onclick="window.print(.*?)<\/button>/,'');
40                         html = html.replace(/<title>(.*?)<\/title>/,'');
41
42                         // remove reference to nonexistant CSS file
43                         html = html.replace(/<link(.*?)\/>/,'');
44
45                         $scope.element.html(html);
46                     });
47                 }
48
49                 $scope.$watch('recordId', 
50                     function(newVal, oldVal) {
51                         if (newVal && newVal !== oldVal) {
52                             loadRecordHtml();
53                         }
54                     }
55                 );
56
57                 if ($scope.recordId) 
58                     loadRecordHtml();
59             }
60         ]
61     }
62 })
63
64 /*
65  * A record='foo' attribute is required as a storage location of the 
66  * retrieved record
67  */
68 .directive('egRecordSummary', function() {
69     return {
70         restrict : 'AE',
71         scope : {
72             recordId : '=',
73             record : '='
74         },
75         templateUrl : './cat/share/t_record_summary',
76         controller : 
77                    ['$scope','egCore',
78             function($scope , egCore) {
79
80                 function loadRecord() {
81                     egCore.pcrud.retrieve('bre', $scope.recordId, {
82                         flesh : 1,
83                         flesh_fields : {
84                             bre : ['simple_record','creator','editor']
85                         }
86                     }).then(function(rec) {
87                         rec.owner(egCore.org.get(rec.owner()));
88                         $scope.record = rec;
89                     });
90                 }
91
92                 $scope.$watch('recordId', 
93                     function(newVal, oldVal) {
94                         if (newVal && newVal !== oldVal) {
95                             loadRecord();
96                         }
97                     }
98                 );
99
100
101                 if ($scope.recordId) 
102                     loadRecord();
103             }
104         ]
105     }
106 })