]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/fieldmapper.pl
our little opac is growing up
[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 = qw/ex mvr au aou aout asv asva asvr asvq 
12                 circ acp acpl acn ccs perm_ex ahn ahr aua ac 
13                 actscecm crcd crmf crrf/;
14
15 print <<JS;
16
17 //  ----------------------------------------------------------------
18 // Autogenerated by fieldmapper.pl
19 // Requires JSON.js
20 //  ----------------------------------------------------------------
21
22 function Fieldmapper() {}
23
24 Fieldmapper.prototype.clone = function() {
25         var obj = new this.constructor();
26
27         for( var i in this.a ) {
28                 var thing = this.a[i];
29                 if(thing == null) continue;
30
31                 if( thing._isfieldmapper ) {
32                         obj.a[i] = thing.clone();
33                 } else {
34
35                         if(instanceOf(thing, Array)) {
36                                 obj.a[i] = new Array();
37
38                                 for( var j in thing ) {
39
40                                         if( thing[j]._isfieldmapper )
41                                                 obj.a[i][j] = thing[j].clone();
42                                         else
43                                                 obj.a[i][j] = thing[j];
44                                 }
45                         } else {
46                                 obj.a[i] = thing;
47                         }
48                 }
49         }
50         return obj;
51 }
52
53
54
55 function FieldmapperException(message) {
56         this.message = message;
57 }
58
59 FieldmapperException.toString = function() {
60         return "FieldmapperException: " + this.message + "\\n";
61
62 }
63
64
65 JS
66
67 for my $object (keys %$map) {
68
69         if($web) {
70                 my $hint = $map->{$object}->{hint};
71                 next unless (grep { $_ eq $hint } @web_hints );
72                 #next unless( $hint eq "mvr" or $hint eq "aou" or $hint eq "aout" );
73         }
74
75 my $short_name = $map->{$object}->{hint};
76
77 print   <<JS;
78 $short_name.prototype                                   = new Fieldmapper();
79 $short_name.prototype.constructor       = $short_name;
80 $short_name.baseClass                                   = Fieldmapper.constructor;
81
82 function $short_name(a) {
83         this.classname = "$short_name";
84         this._isfieldmapper = true;
85         if(a) { 
86                 if( a.constructor == Array) 
87                         this.a = a;  
88                 else
89                         throw new FieldmapperException(
90                                 "Attempt to build fieldmapper object with non-array");
91         } else this.a = [];
92 }
93
94 $short_name._isfieldmapper = true;
95 JS
96
97 for my $field (keys %{$map->{$object}->{fields}}) {
98
99 my $position = $map->{$object}->{fields}->{$field}->{position};
100
101 print <<JS;
102 $short_name.prototype.$field = function(n) {if(arguments.length == 1) this.a[$position] = n; return this.a[$position]; }
103 JS
104
105 }
106 }
107