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