[open-ils-commits] r14661 - trunk/Open-ILS/web/js/dojo/fieldmapper (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Oct 28 21:01:45 EDT 2009
Author: miker
Date: 2009-10-28 21:01:44 -0400 (Wed, 28 Oct 2009)
New Revision: 14661
Modified:
trunk/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
Log:
simplify fieldmapper class building and reduce duplicated code
Modified: trunk/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js 2009-10-29 01:00:26 UTC (rev 14660)
+++ trunk/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js 2009-10-29 01:01:44 UTC (rev 14661)
@@ -69,15 +69,84 @@
}
}
return obj;
- },
+ }
+
/*
isnew : function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; },
ischanged : function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; },
isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
*/
+
});
+ fieldmapper.vivicateClass = function (cl) {
+ dojo.provide( cl );
+ dojo.declare( cl , fieldmapper.Fieldmapper, {
+ constructor : function () {
+ if (!this.a) this.a = [];
+ this.classname = this.declaredClass;
+ this._fields = [];
+
+ if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
+ this.Structure = fieldmapper.IDL.fmclasses[this.classname]
+
+ for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
+ var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
+ var p = field.array_position;
+ this._fields.push( field.name );
+ this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
+ }
+ } else {
+ this._fields = fmclasses[this.classname];
+
+ for( var pos = 0; pos < this._fields.length; pos++ ) {
+ var p = parseInt(pos);
+ var f = this._fields[pos];
+ this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
+ }
+ }
+
+ }
+ });
+ fieldmapper[cl] = window[cl]; // alias into place
+ if (fieldmapper.IDL && fieldmapper.IDL.loaded) fieldmapper[cl].Identifier = fieldmapper.IDL.fmclasses[cl].pkey;
+ };
+
+ if (!window.fmclasses) dojo.require("fieldmapper.fmall", true);
+ for( var cl in fieldmapper.IDL.fmclasses ) {
+ fieldmapper.vivicateClass(cl);
+ }
+
+ // if we were NOT called by the IDL loader ...
+ // XXX This is now deprecated in preference to fieldmapper.AutoIDL
+ if ( !(fieldmapper.IDL && fieldmapper.IDL.loaded) ) {
+
+ fieldmapper.i18n_l.Identifier = 'code';
+ fieldmapper.ccpbt.Identifier = 'code';
+ fieldmapper.ccnbt.Identifier = 'code';
+ fieldmapper.cbrebt.Identifier = 'code';
+ fieldmapper.cubt.Identifier = 'code';
+ fieldmapper.ccm.Identifier = 'code';
+ fieldmapper.cvrfm.Identifier = 'code';
+ fieldmapper.clm.Identifier = 'code';
+ fieldmapper.cam.Identifier = 'code';
+ fieldmapper.cifm.Identifier = 'code';
+ fieldmapper.citm.Identifier = 'code';
+ fieldmapper.cblvl.Identifier = 'code';
+ fieldmapper.clfm.Identifier = 'code';
+ fieldmapper.mous.Identifier = 'usr';
+ fieldmapper.moucs.Identifier = 'usr';
+ fieldmapper.mucs.Identifier = 'usr';
+ fieldmapper.mus.Identifier = 'usr';
+ fieldmapper.rxbt.Identifier = 'xact';
+ fieldmapper.rxpt.Identifier = 'xact';
+ fieldmapper.cxt.Identifier = 'name';
+ fieldmapper.amtr.Identifier = 'matchpoint';
+ fieldmapper.coust.Identifier = 'name';
+
+ }
+
fieldmapper._request = function ( meth, staff, params ) {
var ses = OpenSRF.CachedClientSession( meth[0] );
if (!ses) return null;
@@ -138,79 +207,6 @@
fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
- // if we were called by the IDL loader ...
- if ( fieldmapper.IDL && fieldmapper.IDL.loaded ) {
- for( var cl in fieldmapper.IDL.fmclasses ) {
- dojo.provide( cl );
- dojo.declare( cl , fieldmapper.Fieldmapper, {
- constructor : function () {
- if (!this.a) this.a = [];
- this.classname = this.declaredClass;
- this._fields = [];
- this.Structure = fieldmapper.IDL.fmclasses[this.classname]
-
- for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
- var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
- var p = field.array_position;
- this._fields.push( field.name );
- this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
- }
- }
- });
- fieldmapper[cl] = window[cl]; // alias into place
- fieldmapper[cl].Identifier = fieldmapper.IDL.fmclasses[cl].pkey;
- }
-
- // ... otherwise we need to get the oldschool fmall.js stuff, which will lack .structure
- // XXX This is now deprecated in preference to fieldmapper.AutoIDL
- } else {
- if (!window.fmclasses)
- dojo.require("fieldmapper.fmall", true);
-
- for( var cl in fmclasses ) {
- dojo.provide( cl );
- dojo.declare( cl , fieldmapper.Fieldmapper, {
- constructor : function () {
- if (!this.a) this.a = [];
- this.classname = this.declaredClass;
- this._fields = fmclasses[this.classname];
- this._fields.push('isnew', 'ischanged', 'isdeleted');
- for( var pos = 0; pos < this._fields.length; pos++ ) {
- var p = parseInt(pos);
- var f = this._fields[pos];
- this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
- }
- }
- });
- fieldmapper[cl] = window[cl]; // alias into place
- fieldmapper[cl].Identifier = 'id'; // alias into place
- }
-
- fieldmapper.i18n_l.Identifier = 'code';
- fieldmapper.ccpbt.Identifier = 'code';
- fieldmapper.ccnbt.Identifier = 'code';
- fieldmapper.cbrebt.Identifier = 'code';
- fieldmapper.cubt.Identifier = 'code';
- fieldmapper.ccm.Identifier = 'code';
- fieldmapper.cvrfm.Identifier = 'code';
- fieldmapper.clm.Identifier = 'code';
- fieldmapper.cam.Identifier = 'code';
- fieldmapper.cifm.Identifier = 'code';
- fieldmapper.citm.Identifier = 'code';
- fieldmapper.cblvl.Identifier = 'code';
- fieldmapper.clfm.Identifier = 'code';
- fieldmapper.mous.Identifier = 'usr';
- fieldmapper.moucs.Identifier = 'usr';
- fieldmapper.mucs.Identifier = 'usr';
- fieldmapper.mus.Identifier = 'usr';
- fieldmapper.rxbt.Identifier = 'xact';
- fieldmapper.rxpt.Identifier = 'xact';
- fieldmapper.cxt.Identifier = 'name';
- fieldmapper.amtr.Identifier = 'matchpoint';
- fieldmapper.coust.Identifier = 'name';
-
- }
-
fieldmapper.OpenSRF = {};
/* Methods are defined as [ service, method, have_staff ]
More information about the open-ils-commits
mailing list