This commit breaks compatibility with OpenSRF 0.9.
[Evergreen.git] / Open-ILS / src / javascript / backend / catalog / record_type.js
1 // Constants ...
2 load_lib('phys_char.js');
3 load_lib('fixed_fields.js');
4 load_lib('JSON_v1.js');
5
6 function recordType (rec) {
7
8         var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
9         var _l = rec.marcns::leader.toString();
10
11         var _t = _l.substr(ff_pos.Type.ldr.BKS.start, ff_pos.Type.ldr.BKS.len);
12         var _b = _l.substr(ff_pos.BLvl.ldr.BKS.start, ff_pos.BLvl.ldr.BKS.len);
13
14         for (var t in rec_type) {
15                 if (_t.match(rec_type[t].Type) && _b.match(rec_type[t].BLvl)) {
16                         return t;
17                 }
18         }
19 }
20
21 function videorecordingFormatName (rec) {
22         var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
23         var _7 = rec.marcns::controlfield.(@tag.match(/007/)).text().toString();
24
25         if (_7.match(/^v/)) {
26                 var _v_e = _7.substr(
27                         physical_characteristics.v.subfields.e.start,
28                         physical_characteristics.v.subfields.e.len
29                 );
30
31                 return physical_characteristics.v.subfields.e.values[ _v_e ];
32         }
33
34         return null;
35 }
36
37 function videorecordingFormatCode (rec) {
38         var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
39         var _7 = rec.marcns::controlfield.(@tag.match(/007/)).text().toString();
40
41         if (_7.match(/^v/)) {
42                 return _7.substr(
43                         physical_characteristics.v.subfields.e.start,
44                         physical_characteristics.v.subfields.e.len
45                 );
46         }
47
48         return null;
49 }
50
51
52 function extractFixedField (rec, field) {
53
54         var marcns = new Namespace("http://www.loc.gov/MARC21/slim");
55         var _l = rec.marcns::leader.toString();
56         var _8 = rec.marcns::controlfield.(@tag.match(/008/)).text().toString();
57         var _6 = rec.marcns::controlfield.(@tag.match(/006/)).text().toString();
58
59         var rtype = recordType(rec);
60
61         var val;
62
63         if (ff_pos[field].ldr) {
64                 if (ff_pos[field].ldr[rtype]) {
65                         val = _l.substr(
66                                 ff_pos[field].ldr[rtype].start,
67                                 ff_pos[field].ldr[rtype].len
68                         );
69                 }
70         } else if (ff_pos[field]._8) {
71                 if (ff_pos[field]._8[rtype]) {
72                         val = _8.substr(
73                                 ff_pos[field]._8[rtype].start,
74                                 ff_pos[field]._8[rtype].len
75                         );
76                 }
77         }
78
79         if (!val && ff_pos[field]._6) {
80                 if (ff_pos[field]._6[rtype]) {
81                         val = _6.substr(
82                                 ff_pos[field]._6[rtype].start,
83                                 ff_pos[field]._6[rtype].len
84                         );
85                 }
86         }
87                 
88         return val;
89 }
90