script to build fieldmapper.js file for using fieldmapper objects in javascript
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 25 Mar 2005 15:51:46 +0000 (15:51 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 25 Mar 2005 15:51:46 +0000 (15:51 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@249 9efc2488-bf62-4759-914b-345cdb29e865

src/extras/fieldmapper.pl [new file with mode: 0644]

diff --git a/src/extras/fieldmapper.pl b/src/extras/fieldmapper.pl
new file mode 100644 (file)
index 0000000..0c0aa1f
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+use strict; use warnings;
+
+use Data::Dumper; 
+use OpenILS::Utils::Fieldmapper;  
+
+my $map = $Fieldmapper::fieldmap;
+
+print <<JS;
+
+//  ----------------------------------------------------------------
+// Autogenerated by fieldmapper.pl
+//  ----------------------------------------------------------------
+
+JS
+
+for my $object (keys %$map) {
+
+my $short_name = $map->{$object}->{hint};
+
+print <<JS;
+
+//  ----------------------------------------------------------------
+// Class: $short_name
+//  ----------------------------------------------------------------
+
+JS
+
+print  <<JS;
+function $short_name(array) {
+       if(array) { this.array = array; } 
+       else { this.array = []; }
+}
+
+$short_name.prototype._is_array = function() {
+       return true;
+}
+JS
+
+for my $field (keys %{$map->{$object}->{fields}}) {
+
+my $position = $map->{$object}->{fields}->{$field}->{position};
+
+print <<JS;
+$short_name.prototype.$field = function(new_value) {
+       if(new_value) { this.array[$position] = new_value; }
+       return this.array[$position];
+}
+JS
+
+}
+}
+