2 * Retrieve, cache, and query MARC tag tables
4 angular.module('egCoreMod')
6 ['$q', 'egCore', 'egAuth',
7 function($q, egCore, egAuth) {
10 defaultTagTableSelector : {
11 marcFormat : 'marc21',
12 marcRecordType : 'biblio',
17 // allow 'bre' and 'biblio' to be synonyms, etc.
18 service.normalizeRecordType = function(recordType) {
19 if (recordType === 'sre') {
21 } else if (recordType === 'bre') {
23 } else if (recordType === 'are') {
30 service.loadTagTable = function(args) {
31 var fields = service.defaultTagTableSelector;
33 if (args.marcFormat) {
34 fields.marcFormat = args.marcFormat;
36 if (args.marcRecordType) {
37 fields.marcFormat = service.normalizeRecordType(args.marcFormat);
40 var tt_key = 'current_tag_table_' + fields.marcFormat + '_' +
41 fields.marcRecordType;
42 egCore.hatch.getItem(tt_key).then(function(tt) {
46 service.loadRemoteTagTable(fields, tt_key);
51 service.loadRemoteTagTable = function(fields, tt_key) {
54 'open-ils.cat.tag_table.all.retrieve.local',
55 egAuth.token(), fields.marcFormat, fields.marcRecordType
58 egCore.hatch.setItem(tt_key, service.fields);
60 function (err) { console.err('error fetch tag table: ' + err) },
63 service.fields[field.tag] = field;
68 service.getFieldTags = function() {
70 angular.forEach(service.fields, function(value, key) {
73 label: key + ': ' + value.name
79 service.getSubfieldCodes = function(tag) {
82 if (!service.fields[tag]) return;
83 angular.forEach(service.fields[tag].subfields, function(value) {
86 label: value.code + ': ' + value.description
92 service.getIndicatorValues = function(tag, pos) {
94 if (!tag) return list;
95 if (!service.fields[tag]) return;
96 if (!service.fields[tag]["ind" + pos]) return;
97 angular.forEach(service.fields[tag]["ind" + pos], function(value) {
100 label: value.code + ': ' + value.value