webstaff: Use tabs instead of Actions For this Record
[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             noMarcLink : '@'
75         },
76         templateUrl : './cat/share/t_record_summary',
77         controller : 
78                    ['$scope','egCore',
79             function($scope , egCore) {
80
81                 function loadRecord() {
82                     egCore.pcrud.retrieve('bre', $scope.recordId, {
83                         flesh : 1,
84                         flesh_fields : {
85                             bre : ['simple_record','creator','editor']
86                         }
87                     }).then(function(rec) {
88                         rec.owner(egCore.org.get(rec.owner()));
89                         $scope.record = rec;
90                     });
91                 }
92
93                 $scope.$watch('recordId', 
94                     function(newVal, oldVal) {
95                         if (newVal && newVal !== oldVal) {
96                             loadRecord();
97                         }
98                     }
99                 );
100
101
102                 if ($scope.recordId) 
103                     loadRecord();
104
105                 $scope.toggle_expand_summary = function() {
106                     if ($scope.collapseRecordSummary) {
107                         $scope.collapseRecordSummary = false;
108                         egCore.hatch.removeItem('eg.cat.record.summary.collapse');
109                     } else {
110                         $scope.collapseRecordSummary = true;
111                         egCore.hatch.setItem('eg.cat.record.summary.collapse', true);
112                     }
113                 }
114             
115                 $scope.collapse_summary = function() {
116                     return $scope.collapseRecordSummary;
117                 }
118             
119                 egCore.hatch.getItem('eg.cat.record.summary.collapse')
120                 .then(function(val) {$scope.collapseRecordSummary = Boolean(val)});
121
122             }
123         ]
124     }
125 })