1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2009 Equinox Software, Inc.
3 * Mike Rylander <miker@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
17 if(!dojo._hasResource["MARC.Field"]) {
19 dojo._hasResource["MARC.Field"] = true;
20 dojo.provide("MARC.Field");
21 dojo.declare('MARC.Field', null, {
23 error : false, // MARC record pointer
24 record : null, // MARC record pointer
26 ind1 : ' ', // MARC indicator 1
27 ind2 : ' ', // MARC indicator 2
28 data : '', // MARC data for a controlfield element
29 subfields : [], // list of MARC subfields for a datafield element
31 constructor : function(kwargs) {
32 this.record = kwargs.record;
33 this.tag = kwargs.tag;
34 this.ind1 = kwargs.ind1 || ' ';
35 this.ind2 = kwargs.ind2 || ' ';
36 this.data = kwargs.data;
37 if (kwargs.subfields) this.subfields = kwargs.subfields;
38 else this.subfields = [];
41 subfield : function (code) {
42 var list = dojo.filter( this.subfields, function (s) {
43 if (s[0] == code) return true; return false;
45 if (list.length == 1) return list[0];
49 addSubfields : function () {
50 for (var i = 0; i < arguments.length; i++) {
51 var code = arguments[i];
52 var value = arguments[++i];
53 this.subfields.push( [ code, value ] );
57 deleteSubfields : function (c) {
58 return this.deleteSubfield( { code : c } );
61 deleteSubfield : function (args) {
63 if (!dojo.isArray( args.code )) {
64 args.code = [ args.code ];
67 if (args.pos && !dojo.isArray( args.pos )) {
68 args.pos = [ args.pos ];
71 for (var i = 0; i < args.code.length; i++) {
73 for (var j = 0; j < me.subfields; j++) {
74 if (me.subfields[j][0] == args.code[i]) {
76 if (!sub_pos[args.code[i]]) sub_pos[args.code[j]] = 0;
77 else sub_pos[args.code[i]]++;
80 for (var k = 0; k < args.pos.length; k++) {
81 if (sub_pos[args.code[i]] == args.pos[k]) me.subfields.splice(j,1);
83 } else if (args.match && me.subfields[j][1].match( args.match )) {
84 me.subfields.splice(j,1);
86 me.subfields.splice(j,1);
93 update : function ( args ) {
94 if (this.isControlfield()) {
97 if (args.ind1) this.ind1 = args.ind1;
98 if (args.ind2) this.ind2 = args.ind2;
99 if (args.tag) this.tag = args.tag;
101 for (var i in args) {
102 if (i == 'tag' || i == 'ind1' || i == 'ind2') continue;
104 dojo.forEach( this.subfields, function (f) {
105 if (!done && f[0] == i) {
114 isControlfield : function () {
115 return this.tag < '010' ? true : false;
118 indicator : function (num, value) {
120 if (num == 1) this.ind1 = value;
121 else if (num == 2) this.ind2 = value;
122 else { this.error = true; return null; }
124 if (num == 1) return this.ind1;
125 else if (num == 2) return this.ind2;
126 else { this.error = true; return null; }