generating slimmer js for basic web stuff and extended js for my opac, etc.
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Aug 2005 20:51:37 +0000 (20:51 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Aug 2005 20:51:37 +0000 (20:51 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1651 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/fieldmapper.pl

index 4d312f7..bd2deeb 100755 (executable)
@@ -7,67 +7,30 @@ my $map = $Fieldmapper::fieldmap;
 
 # if a true value is provided, we generate the web (light) version of the fieldmapper
 my $web = $ARGV[0];
+if(!$web) { $web = ""; }
+
 # List of classes needed by the opac
-my @web_hints = qw/ex mvr au aou aout asv asva asvr asvq 
-               circ acp acpl acn ccs perm_ex ahn ahr aua ac 
+my @web_hints = qw/asv asva asvr asvq 
+               circ acp acpl acn ccs ahn ahr aua ac 
                actscecm crcd crmf crrf mus mbts aoc aus/;
 
-print <<JS;
-
-//  ----------------------------------------------------------------
-// Autogenerated by fieldmapper.pl
-// Requires JSON.js
-//  ----------------------------------------------------------------
-
-function Fieldmapper() {}
-
-var errorstr = "Attempt to build fieldmapper object with non-array";
-
-Fieldmapper.prototype.clone = function() {
-       var obj = new this.constructor();
-
-       for( var i in this.a ) {
-               var thing = this.a[i];
-               if(thing == null) continue;
-
-               if( thing._isfieldmapper ) {
-                       obj.a[i] = thing.clone();
-               } else {
-
-                       if(instanceOf(thing, Array)) {
-                               obj.a[i] = new Array();
-
-                               for( var j in thing ) {
-
-                                       if( thing[j]._isfieldmapper )
-                                               obj.a[i][j] = thing[j].clone();
-                                       else
-                                               obj.a[i][j] = thing[j];
-                               }
-                       } else {
-                               obj.a[i] = thing;
-                       }
-               }
-       }
-       return obj;
-}
-Fieldmapper.prototype.isnew = function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; }
-Fieldmapper.prototype.ischanged = function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; }
-Fieldmapper.prototype.isdeleted = function(a) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; }
-function FMEX(message) { this.message = message; }
-FMEX.toString = function() { return "FieldmapperException: " + this.message + "\\n"; }
+my @web_core = qw/ aou au perm_ex ex aout mvr /;
 
-var _c = {};
 
-JS
+print "var _c = {};\n";
 
 for my $object (keys %$map) {
 
-       if($web) {
+       if($web eq "web") {
                my $hint = $map->{$object}->{hint};
                next unless (grep { $_ eq $hint } @web_hints );
        }
 
+       if($web eq "web_core") {
+               my $hint = $map->{$object}->{hint};
+               next unless (grep { $_ eq $hint } @web_core );
+       }
+
        my $short_name = $map->{$object}->{hint};
 
        my @fields;
@@ -82,37 +45,9 @@ for my $object (keys %$map) {
                        print "\"$f\","; 
                }
        }
-       print "];\n"
-
+       print "];\n";
 
+       print "fmclasses = _c;\n";
 
 }
 
-print <<JS;
-
-       var string = "";
-       for( var cl in _c ) {
-               string += cl + ".prototype = new Fieldmapper(); " + 
-                                                       cl + ".prototype.constructor = " + cl + ";" +
-                                                       cl + ".baseClass = Fieldmapper.constructor;" +
-                                                       "function " + cl + "(a) { " +
-                                                               "this.classname = \\\"" + cl + "\\\";" +
-                                                               "this._isfieldmapper = true;" +
-                                                               "if(a) { if(a.constructor == Array) this.a = a; else throw new FMEX(errorstr);} else this.a = []}"; 
-
-               string += cl + "._isfieldmapper=true;";
-
-               for( var pos in _c[cl] ) {
-                       var p = parseInt(pos) + 3;
-                       var field = _c[cl][pos];
-                       string += cl + ".prototype." + field + 
-                               "=function(n){if(arguments.length == 1)this.a[" + 
-                               p + "]=n;return this.a[" + p + "];};";
-               }
-
-       }
-
-       eval(string);
-
-JS
-