]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/fieldmapper.pl
added web "aua" and "ac"
[Evergreen.git] / Open-ILS / src / extras / fieldmapper.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3 use Data::Dumper; 
4 use OpenILS::Utils::Fieldmapper;  
5
6 my $map = $Fieldmapper::fieldmap;
7
8 # if a true value is provided, we generate the web (light) version of the fieldmapper
9 my $web = $ARGV[0];
10 # List of classes needed by the opac
11 my @web_hints = ("ex", "mvr", "au", "aou",
12                 "aout", "asv", "asva", "asvr", "asvq", 
13                 "circ", "acp", "acpl", "acn", "ccs", 
14                 "perm_ex", "ahn", "aua", "ac");
15
16 print <<JS;
17
18 //  ----------------------------------------------------------------
19 // Autogenerated by fieldmapper.pl
20 // Requires JSON.js
21 //  ----------------------------------------------------------------
22
23 function Fieldmapper() {}
24
25 Fieldmapper.prototype.clone = function() {
26         var obj = new this.constructor();
27
28         for( var i in this.array ) {
29                 var thing = this.array[i];
30                 if(thing == null) continue;
31
32                 if( thing._isfieldmapper ) {
33                         obj.array[i] = thing.clone();
34                 } else {
35
36                         if(instanceOf(thing, Array)) {
37                                 obj.array[i] = new Array();
38
39                                 for( var j in thing ) {
40
41                                         if( thing[j]._isfieldmapper )
42                                                 obj.array[i][j] = thing[j].clone();
43                                         else
44                                                 obj.array[i][j] = thing[j];
45                                 }
46                         } else {
47                                 obj.array[i] = thing;
48                         }
49                 }
50         }
51         return obj;
52 }
53
54
55
56 function FieldmapperException(message) {
57         this.message = message;
58 }
59
60 FieldmapperException.toString = function() {
61         return "FieldmapperException: " + this.message + "\\n";
62
63 }
64
65
66 JS
67
68 for my $object (keys %$map) {
69
70         if($web) {
71                 my $hint = $map->{$object}->{hint};
72                 next unless (grep { $_ eq $hint } @web_hints );
73                 #next unless( $hint eq "mvr" or $hint eq "aou" or $hint eq "aout" );
74         }
75
76 my $short_name = $map->{$object}->{hint};
77
78 print <<JS;
79
80 //  ----------------------------------------------------------------
81 // Class: $short_name
82 //  ----------------------------------------------------------------
83
84 JS
85
86 print   <<JS;
87
88 $short_name.prototype                                   = new Fieldmapper();
89 $short_name.prototype.constructor       = $short_name;
90 $short_name.baseClass                                   = Fieldmapper.constructor;
91
92 function $short_name(array) {
93
94         this.classname = "$short_name";
95         this._isfieldmapper = true;
96
97         if(array) { 
98                 if( array.constructor == Array) 
99                         this.array = array;  
100
101                 else
102                         throw new FieldmapperException(
103                                 "Attempt to build fieldmapper object with non-array");
104
105         } else { this.array = []; }
106
107 }
108
109 $short_name._isfieldmapper = true;
110
111
112 JS
113
114 for my $field (keys %{$map->{$object}->{fields}}) {
115
116 my $position = $map->{$object}->{fields}->{$field}->{position};
117
118 print <<JS;
119 $short_name.prototype.$field = function(new_value) {
120         if(arguments.length == 1) { this.array[$position] = new_value; }
121         return this.array[$position];
122 }
123 JS
124
125 }
126 }
127