// support functions var IE = false; var unit_test = false; function instanceOf(object, constructorFunction) { if(!IE) { while (object != null) { if (object == constructorFunction.prototype) return true; object = object.__proto__; } } else { while(object != null) { if( object instanceof constructorFunction ) return true; object = object.__proto__; } } return false; } // Top level superclass function Fieldmapper(array) { this.array = []; if(array) { if (array.constructor == Array) { this.array = array; } else if ( instanceOf( array, String ) || instanceOf( array, Number ) ) { var obj = null; if (this.cacheable) { try { obj = this.baseClass.obj_cache[this.classname][array]; } catch (E) {}; } if (!obj) { obj = user_request( 'open-ils.proxy', 'open-ils.proxy.proxy', [ mw.G.auth_ses[0], 'open-ils.storage', 'open-ils.storage.direct.' + this.db_type + '.retrieve', array ] )[0]; if (this.cacheable) { if (this.baseClass.obj_cache[this.classname] == null) this.baseClass.obj_cache[this.classname] = {}; this.baseClass.obj_cache[this.classname][obj.id()] = obj; } } this.array = obj.array; } else { throw new FieldmapperException( "Attempt to build fieldmapper object with something wierd"); } } } Fieldmapper.prototype.baseClass = Fieldmapper; Fieldmapper.prototype.obj_cache = {}; Fieldmapper.prototype.search function (type,field,value) { var list = user_request( 'open-ils.proxy', 'open-ils.proxy.proxy', [ mw.G.auth_ses[0], 'open-ils.storage', 'open-ils.storage.direct.' + type.db_type + '.search.' + field, array ] )[0]; if (type.cacheable) { if (type.baseClass.obj_cache[type.classname] == null) type.baseClass.obj_cache[type.classname] = {}; for (var i in list) { type.baseClass.obj_cache[type.classname][list[i].id()] = list[i]; } } return list; } Fieldmapper.prototype.clone = function() { var obj = new this.constructor(); for( var i in this.array ) { var thing = this.array[i]; if(thing == null) continue; if( thing._isfieldmapper ) { obj.array[i] = thing.clone(); } else { if(instanceOf(thing, Array)) { obj.array[i] = new Array(); for( var j in thing ) { if( thing[j]._isfieldmapper ) obj.array[i][j] = thing[j].clone(); else obj.array[i][j] = thing[j]; } } else { obj.array[i] = thing; } } } return obj; } function FieldmapperException(message) { this.message = message; } FieldmapperException.toString = function() { return "FieldmapperException: " + this.message + "\n"; } // Class definition for "" function (array) { if (!instanceOf(this, )) return new (array); this.baseClass.call(this,array); this.classname = ""; this._isfieldmapper = true; this.uber = .baseClass.prototype; } .prototype = new (); .prototype.constructor = ; .baseClass = ; .prototype.cachable = true; .prototype.fields = []; .last_real_field = 2; .prototype.db_type = ""; .prototype.isnew = function(new_value) { if(arguments.length == 1) { this.array[0] = new_value; } return this.array[0]; } .prototype.ischanged = function(new_value) { if(arguments.length == 1) { this.array[1] = new_value; } return this.array[1]; } .prototype.isdeleted = function(new_value) { if(arguments.length == 1) { this.array[2] = new_value; } return this.array[2]; } // Accessor/mutator for .: .last_real_field++; .prototype.fields.push(""); .prototype. = function (new_value) { if(arguments.length == 1) { this.array[] = new_value; } var val = this.array[]; if (!instanceOf(this.array[], )) { if (this.array[] != null) { this.array[] = new (val); } } return this.array[]; } // accessor for : .prototype. = function () { var _pos = .last_real_field + ; if (!instanceOf(this.array[_pos], Array)) { this.array[_pos] = []; if (this.array[_pos].length == 0) { /* get the real thing. * search where .() * equals this.(); */ this.array[_pos] = this.uber.search( , "", this.() ); } return this.array[_pos]; }