]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/extras/fieldmapper.pl
defcd7348bec60299a9652dab728124e1fe6844e
[OpenSRF.git] / src / extras / fieldmapper.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3
4 use Data::Dumper; 
5 use OpenILS::Utils::Fieldmapper;  
6
7 my $map = $Fieldmapper::fieldmap;
8
9 print <<JS;
10
11 //  ----------------------------------------------------------------
12 // Autogenerated by fieldmapper.pl
13 // Requires JSON.js
14 //  ----------------------------------------------------------------
15
16 function FieldmapperException(message) {
17         this.message = message;
18 }
19 FieldmapperException.toString = function() {
20         return "FieldmapperException: " + this.message + "\\n";
21 }
22
23
24 JS
25
26 for my $object (keys %$map) {
27
28 my $short_name = $map->{$object}->{hint};
29
30 print <<JS;
31
32 //  ----------------------------------------------------------------
33 // Class: $short_name
34 //  ----------------------------------------------------------------
35
36 JS
37
38 print   <<JS;
39
40 function $short_name(array) {
41
42         this.classname = "$short_name";
43         this._isfieldmapper = true;
44
45         if(array) { 
46                 if( array.constructor == Array) 
47                         this.array = array;  
48
49                 else
50                         throw new FieldmapperException(
51                                 "Attempt to build fieldmapper object with non-array");
52
53         } else { this.array = []; }
54
55 }
56
57 $short_name._isfieldmapper = true;
58
59
60 JS
61
62 for my $field (keys %{$map->{$object}->{fields}}) {
63
64 my $position = $map->{$object}->{fields}->{$field}->{position};
65
66 print <<JS;
67 $short_name.prototype.$field = function(new_value) {
68         if(new_value) { this.array[$position] = new_value; }
69         return this.array[$position];
70 }
71 JS
72
73 }
74 }
75