From: miker Date: Thu, 29 Oct 2009 01:01:44 +0000 (+0000) Subject: simplify fieldmapper class building and reduce duplicated code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d149c6c4ca0543c61a434026383284e2f1543318;p=contrib%2FConifer.git simplify fieldmapper class building and reduce duplicated code git-svn-id: svn://svn.open-ils.org/ILS/trunk@14661 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js index 82ebb42e04..1d7963652e 100644 --- a/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js +++ b/Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js @@ -69,15 +69,84 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ } } 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 @@ if(!dojo._hasResource["fieldmapper.Fieldmapper"]){ 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 ]