]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/fieldmapper.pl
*** empty log message ***
[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 = ("mvr", "au", "aou","aout", "asv", "asva", "asvr", "asvq");
12
13 print <<JS;
14
15 //  ----------------------------------------------------------------
16 // Autogenerated by fieldmapper.pl
17 // Requires JSON.js
18 //  ----------------------------------------------------------------
19
20 function FieldmapperException(message) {
21         this.message = message;
22 }
23 FieldmapperException.toString = function() {
24         return "FieldmapperException: " + this.message + "\\n";
25 }
26
27
28 JS
29
30 for my $object (keys %$map) {
31
32         if($web) {
33                 my $hint = $map->{$object}->{hint};
34                 next unless (grep { $_ eq $hint } @web_hints );
35                 #next unless( $hint eq "mvr" or $hint eq "aou" or $hint eq "aout" );
36         }
37
38 my $short_name = $map->{$object}->{hint};
39
40 print <<JS;
41
42 //  ----------------------------------------------------------------
43 // Class: $short_name
44 //  ----------------------------------------------------------------
45
46 JS
47
48 print   <<JS;
49
50 function $short_name(array) {
51
52         this.classname = "$short_name";
53         this._isfieldmapper = true;
54
55         if(array) { 
56                 if( array.constructor == Array) 
57                         this.array = array;  
58
59                 else
60                         throw new FieldmapperException(
61                                 "Attempt to build fieldmapper object with non-array");
62
63         } else { this.array = []; }
64
65 }
66
67 $short_name._isfieldmapper = true;
68
69
70 JS
71
72 for my $field (keys %{$map->{$object}->{fields}}) {
73
74 my $position = $map->{$object}->{fields}->{$field}->{position};
75
76 print <<JS;
77 $short_name.prototype.$field = function(new_value) {
78         if(new_value) { this.array[$position] = new_value; }
79         return this.array[$position];
80 }
81 JS
82
83 }
84 }
85