+++ /dev/null
-if(!dojo._hasResource['OpenSRF']){
-
- dojo._hasResource['OpenSRF'] = true;
- dojo.provide('OpenSRF');
- dojo.require('opensrf.opensrf', true);
- dojo.require('opensrf.opensrf_xhr', true);
-
- OpenSRF.session_cache = {};
- OpenSRF.CachedClientSession = function ( app ) {
- if (this.session_cache[app]) return this.session_cache[app];
- this.session_cache[app] = new OpenSRF.ClientSession ( app );
- return this.session_cache[app];
- }
-}
+++ /dev/null
-if(!dojo._hasResource["fieldmapper.Fieldmapper"]){
-
-/* generate fieldmapper javascript classes. This expects a global variable
- called 'fmclasses' to be fleshed with the classes we need to build */
-
- function FMEX(message) { this.message = message; }
- FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
-
-
- dojo._hasResource["fieldmapper.Fieldmapper"] = true;
- dojo.provide("fieldmapper.Fieldmapper");
- dojo.require("OpenSRF");
-
- dojo.declare( "fieldmapper.Fieldmapper", null, {
-
- constructor : function (initArray) {
- if (initArray) {
- if (dojo.isArray(initArray)) {
- this.a = initArray;
- } else {
- this.a = [];
- }
- }
- },
-
- _isfieldmapper : true,
- fm_classes : fmclasses,
-
- 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;
- },
-
- 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._request = function ( meth, staff, params ) {
- var ses = OpenSRF.CachedClientSession( meth[0] );
- if (!ses) return null;
-
- var result = null;
- var args = {};
-
- if (dojo.isArray(params)) {
- args.params = params;
- } else {
-
- if (dojo.isObject(params)) {
- args = params;
- } else {
- args.params = arguments.splice(1, arguments.length - 1);
- }
-
- }
-
- if (!args.timeout) args.timeout = 10;
-
- if (!args.onerror) {
- args.error = function (r) {
- throw 'Error encountered! ' + r;
- }
- }
-
- if (!args.oncomplete) {
- args.oncomplete = function (r) {
- var x = r.recv();
- if (x) result = x.content();
- }
- }
-
- args.method = meth[1];
- if (staff && meth[2]) args.method += '.staff';
-
- ses.request(args).send();
-
- return result;
- };
-
- fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
- fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
-
- fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
- fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
-
- 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];
- for( var pos = 0; pos < this._fields.length; pos++ ) {
- var p = parseInt(pos) + 3;
- 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.OpenSRF = {};
-
- /* Methods are defined as [ service, method, have_staff ]
- An optional 3rd component is when a method is followed by true, such methods
- have a staff counterpart and should have ".staff" appended to the method
- before the method is called when in XUL mode */
- fieldmapper.OpenSRF.methods = {
- SEARCH_MRS : ['open-ils.search','open-ils.search.metabib.multiclass',true],
- SEARCH_RS : ['open-ils.search','open-ils.search.biblio.multiclass',true],
- SEARCH_MRS_QUERY : ['open-ils.search','open-ils.search.metabib.multiclass.query',true],
- SEARCH_RS_QUERY : ['open-ils.search','open-ils.search.biblio.multiclass.query',true],
- FETCH_SEARCH_RIDS : ['open-ils.search','open-ils.search.biblio.record.class.search',true],
- FETCH_MRMODS : ['open-ils.search','open-ils.search.biblio.metarecord.mods_slim.retrieve'],
- FETCH_MODS_FROM_COPY : ['open-ils.search','open-ils.search.biblio.mods_from_copy'],
- FETCH_MR_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.metarecord.copy_count',true],
- FETCH_RIDS : ['open-ils.search','open-ils.search.biblio.metarecord_to_records',true],
- FETCH_RMODS : ['open-ils.search','open-ils.search.biblio.record.mods_slim.retrieve'],
- FETCH_R_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.record.copy_count',true],
- FETCH_FLESHED_USER : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve'],
- FETCH_SESSION : ['open-ils.auth','open-ils.auth.session.retrieve'],
- LOGIN_INIT : ['open-ils.auth','open-ils.auth.authenticate.init'],
- LOGIN_COMPLETE : ['open-ils.auth','open-ils.auth.authenticate.complete'],
- LOGIN_DELETE : ['open-ils.auth','open-ils.auth.session.delete'],
- FETCH_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.retrieve'],
- UPDATE_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.update'],
- FETCH_COPY_STATUSES : ['open-ils.search','open-ils.search.config.copy_status.retrieve.all'],
- FETCH_COPY_COUNTS_SUMMARY : ['open-ils.search','open-ils.search.biblio.copy_counts.summary.retrieve'],
- FETCH_MARC_HTML : ['open-ils.search','open-ils.search.biblio.record.html'],
- FETCH_CHECKED_OUT_SUM : ['open-ils.actor','open-ils.actor.user.checked_out'],
- FETCH_HOLDS : ['open-ils.circ','open-ils.circ.holds.retrieve'],
- FETCH_FINES_SUMMARY : ['open-ils.actor','open-ils.actor.user.fines.summary'],
- FETCH_TRANSACTIONS : ['open-ils.actor','open-ils.actor.user.transactions.have_charge.fleshed'],
- FETCH_MONEY_BILLING : ['open-ils.circ','open-ils.circ.money.billing.retrieve.all'],
- FETCH_CROSSREF : ['open-ils.search','open-ils.search.authority.crossref'],
- FETCH_CROSSREF_BATCH : ['open-ils.search','open-ils.search.authority.crossref.batch'],
- CREATE_HOLD : ['open-ils.circ','open-ils.circ.holds.create'],
- CREATE_HOLD_OVERRIDE : ['open-ils.circ','open-ils.circ.holds.create.override'],
- CANCEL_HOLD : ['open-ils.circ','open-ils.circ.hold.cancel'],
- UPDATE_USERNAME : ['open-ils.actor','open-ils.actor.user.username.update'],
- UPDATE_PASSWORD : ['open-ils.actor','open-ils.actor.user.password.update'],
- UPDATE_EMAIL : ['open-ils.actor','open-ils.actor.user.email.update'],
- RENEW_CIRC : ['open-ils.circ','open-ils.circ.renew'],
- CHECK_SPELL : ['open-ils.search','open-ils.search.spellcheck'],
- FETCH_REVIEWS : ['open-ils.search','open-ils.search.added_content.review.retrieve.all'],
- FETCH_TOC : ['open-ils.search','open-ils.search.added_content.toc.retrieve'],
- FETCH_ACONT_SUMMARY : ['open-ils.search','open-ils.search.added_content.summary.retrieve'],
- FETCH_USER_BYBARCODE : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve_by_barcode'],
- FETCH_ADV_MARC_MRIDS : ['open-ils.search','open-ils.search.biblio.marc',true],
- FETCH_ADV_ISBN_RIDS : ['open-ils.search','open-ils.search.biblio.isbn'],
- FETCH_ADV_ISSN_RIDS : ['open-ils.search','open-ils.search.biblio.issn'],
- FETCH_ADV_TCN_RIDS : ['open-ils.search','open-ils.search.biblio.tcn'],
- FETCH_CNBROWSE : ['open-ils.search','open-ils.search.callnumber.browse'],
- FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
- FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
- CREATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.create'],
- DELETE_CONTAINER : ['open-ils.actor','open-ils.actor.container.full_delete'],
- CREATE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.create'],
- DELETE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.delete'],
- FLESH_CONTAINER : ['open-ils.actor','open-ils.actor.container.flesh'],
- FLESH_PUBLIC_CONTAINER : ['open-ils.actor','open-ils.actor.container.public.flesh'],
- UPDATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.update'],
- FETCH_COPY : ['open-ils.search','open-ils.search.asset.copy.retrieve'],
- FETCH_FLESHED_COPY : ['open-ils.search','open-ils.search.asset.copy.fleshed2.retrieve'],
- CHECK_HOLD_POSSIBLE : ['open-ils.circ','open-ils.circ.title_hold.is_possible'],
- UPDATE_HOLD : ['open-ils.circ','open-ils.circ.hold.update'],
- FETCH_COPIES_FROM_VOLUME : ['open-ils.search','open-ils.search.asset.copy.retrieve_by_cn_label',true],
- FETCH_VOLUME_BY_INFO : ['open-ils.search','open-ils.search.call_number.retrieve_by_info'], /* XXX staff method? */
- FETCH_VOLUME : ['open-ils.search','open-ils.search.asset.call_number.retrieve'],
- FETCH_COPY_LOCATIONS : ['open-ils.circ','open-ils.circ.copy_location.retrieve.all'],
- FETCH_COPY_NOTES : ['open-ils.circ','open-ils.circ.copy_note.retrieve.all'],
- FETCH_COPY_STAT_CATS : ['open-ils.circ','open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy'],
- FETCH_LIT_FORMS : ['open-ils.search','open-ils.search.biblio.lit_form_map.retrieve.all'],
- FETCH_ITEM_FORMS : ['open-ils.search','open-ils.search.biblio.item_form_map.retrieve.all'],
- FETCH_ITEM_TYPES : ['open-ils.search','open-ils.search.biblio.item_type_map.retrieve.all'],
- FETCH_AUDIENCES : ['open-ils.search','open-ils.search.biblio.audience_map.retrieve.all'],
- FETCH_HOLD_STATUS : ['open-ils.circ','open-ils.circ.hold.status.retrieve'],
- FETCH_NON_CAT_CIRCS : ['open-ils.circ','open-ils.circ.open_non_cataloged_circulation.user'],
- FETCH_NON_CAT_CIRC : ['open-ils.circ','open-ils.circ.non_cataloged_circulation.retrieve'],
- FETCH_NON_CAT_TYPES : ['open-ils.circ','open-ils.circ.non_cat_types.retrieve.all'],
- FETCH_BRE : ['open-ils.search','open-ils.search.biblio.record_entry.slim.retrieve'],
- CHECK_USERNAME : ['open-ils.actor','open-ils.actor.username.exists'],
- FETCH_CIRC_BY_ID : ['open-ils.circ','open-ils.circ.retrieve'],
- FETCH_MR_DESCRIPTORS : ['open-ils.search','open-ils.search.metabib.record_to_descriptors'],
- FETCH_HIGHEST_PERM_ORG : ['open-ils.actor','open-ils.actor.user.perm.highest_org.batch'],
- FETCH_USER_NOTES : ['open-ils.actor','open-ils.actor.note.retrieve.all'],
- FETCH_ORG_BY_SHORTNAME : ['open-ils.actor','open-ils.actor.org_unit.retrieve_by_shorname'],
- FETCH_BIB_ID_BY_BARCODE : ['open-ils.search','open-ils.search.bib_id.by_barcode'],
- FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default']
- };
-
-}
-
-
-
+++ /dev/null
-if(!dojo._hasResource["fieldmapper.OrgUtils"]){
-
- dojo._hasResource["fieldmapper.OrgUtils"] = true;
- dojo.provide("fieldmapper.OrgUtils");
- dojo.require("fieldmapper.Fieldmapper");
- dojo.require("fieldmapper.OrgTree", true);
-
- fieldmapper.aou.globalOrgTree = {};
- fieldmapper.aou.OrgCache = {};
- fieldmapper.aou.OrgCacheSN = {};
- fieldmapper.aout.OrgTypeCache = {};
-
- fieldmapper.aout.LoadOrgTypes = function () {
- for (var i in fieldmapper.aout.OrgTypeCache) {
- return;
- }
-
- var types = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_types.retrieve']);
-
- for (var i in types) {
- fieldmapper.aout.OrgTypeCache[types[i].id()] = {
- loaded : true,
- type : types[i]
- };
- }
- }
-
- fieldmapper.aou.LoadOrg = function (id, slim_ok) {
- var slim_o = fieldmapper.aou.OrgCache[id];
-
- if (slim_o && (slim_ok || slim_o.loaded))
- return fieldmapper.aou.OrgCache[id].org;
-
- var o = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_unit.retrieve'],[null,id]);
- fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o };
- return o;
- }
- fieldmapper.aou.findOrgUnit = fieldmapper.aou.LoadOrg;
-
- if (window._l) {
- for (var i in _l) {
- fieldmapper.aou.OrgCache[_l[i][0]] = {
- loaded: false,
- org : new fieldmapper.aou().fromHash({
- id : _l[i][0],
- ou_type : _l[i][1],
- parent_ou : _l[i][2],
- name : _l[i][3],
- opac_visible : _l[i][4]
- })
- };
-
- }
-
- for (var i in fieldmapper.aou.OrgCache) {
- var x = fieldmapper.aou.OrgCache[i].org;
- if (x.parent_ou() == null || x.parent_ou() == '') {
- fieldmapper.aou.globalOrgTree = x;
- continue;
- }
-
- var parent = fieldmapper.aou.findOrgUnit(x.parent_ou(),true);
- if (!parent.children()) parent.children([]);
- parent.children().push(x);
- fieldmapper.aou.OrgCache[x.id()].treePtr = x;
- }
-
- for (var i in globalOrgTypes) {
- fieldmapper.aout.OrgTypeCache[globalOrgTypes[i].id()] = {
- loaded : true,
- type : globalOrgTypes[i]
- };
- }
- }
-
-
- /* ---------------------------------------------------------------------- */
-
- fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
- return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, name );
- }
-
- fieldmapper.aout.findOrgType = function (id) {
- fieldmapper.aout.LoadOrgTypes();
- return fieldmapper.aout.OrgTypeCache[id].type;
- }
-
- fieldmapper.aou.prototype.findOrgDepth = function (id) {
- if (!id) id = this.id;
- if (!id) return null;
-
- var org = fieldmapper.aou.findOrgUnit(id);
- return fieldmapper.findOrgType(
- fieldmapper.aou.findOrgUnit(id).ou_type()
- ).depth;
- }
- fieldmapper.aou.findOrgDepth = fieldmapper.aou.prototype.findOrgDepth;
-
- fieldmapper.aout.findOrgTypeFromDepth = function (depth) {
- if( depth == null ) return null;
- fieldmapper.aout.LoadOrgTypes();
- for( var i in fieldmapper.aout.OrgTypeCache ) {
- var t = fieldmapper.aout.OrgTypeCache[i].type;
- if( t.depth() == depth ) return t;
- }
- return null;
- }
-
- fieldmapper.aou.findOrgUnitSN = function (sn) {
- var org = fieldmapper.aou.OrgCacheSN[sn];
- if (!org) {
- for (var i in fieldmapper.aou.OrgCache) {
- var o = fieldmapper.aou.OrgCache[i];
- if (o.loaded && o.org.shortname() == sn) {
- fieldmapper.aou.OrgCacheSN[o.org.shortname()] = o;
- return o.org;
- }
- }
-
- org = fieldmapper.standardRequest(fieldmapper.OpenSRF.methods.FETCH_ORG_BY_SHORTNAME, sn);
-
- fieldmapper.aou.OrgCache[org.id()] = { loaded : true, org : org };
- fieldmapper.aou.OrgCacheSN[org.shortname()] = { loaded : true, org : org };
-
- }
-
- return org;
- }
-
- fieldmapper.aou.prototype.orgNodeTrail = function (node) {
- if (!node) node = this;
- if (!node) return [];
-
- var na = [];
-
- while( node ) {
- na.push(node);
- node = fieldmapper.aou.findOrgUnit(node.parent_ou());
- }
-
- return na.reverse();
- }
- fieldmapper.aou.orgNodeTrail = fieldmapper.aou.prototype.orgNodeTrail;
-
- fieldmapper.aou.prototype.orgIsMine = function (me, org) {
- if (this._isfieldmapper) {
- org = me;
- me = this;
- }
-
- if(!me || !org) return false;
-
- if(me.id() == org.id()) return true;
-
- for( var i in me.children() ) {
- if(me.children()[i].orgIsMine(org)) return true;
- }
- return false;
- }
-
- dojo.addOnUnload( function () {
- for (var i in fieldmapper.aou.OrgCache) {
- x=fieldmapper.aou.OrgCache[i].treePtr;
- if (!x) continue;
-
- x.children(null);
- x.parent_ou(null);
- fieldmapper.aou.OrgCache[i]=null;
- }
- fieldmapper.aou.globalOrgTree = null;
- fieldmapper.aou.OrgCache = null;
- fieldmapper.aou.OrgCacheSN = null;
- fieldmapper.aout.OrgTypeCache = null;
- });
-}
-
-
-
+++ /dev/null
-if(!dojo._hasResource['fieldmapper.dojoData']){
-
- dojo._hasResource['fieldmapper.dojoData'] = true;
- dojo.provide('fieldmapper.dojoData');
- dojo.require('fieldmapper.Fieldmapper');
- dojo.require('fieldmapper.hash');
-
-
- function _fromStoreItem (data) {
- this.fromHash(data);
-
- for (var i in this._ignore_fields)
- this[this._ignore_fields[i]](null);
-
- for ( var i=0; i < this._fields.length; i++) {
- if (dojo.isArray( this[this._fields[i]]() ))
- this[this._fields[i]]( this[this._fields[i]]()[0] );
- }
- return this;
- }
-
- function _toStoreData (list, label, params) {
-
- if (!params) params = {};
- if (!list) list = {};
-
- // a sane default
- if (!params.identifier) params.identifier = 'id';
- if (!label) label = params.label;
- if (!label) label = params.identifier;
-
- var data = { label : label, identifier : params.identifier, items : [] };
-
- for (var i in list) data.items.push( list[i].toHash() );
-
- if (params.children && params.parent) {
- var _hash_list = data.items;
-
- var _find_root = {};
- for (var i in _hash_list) {
- _find_root[_hash_list[i][params.identifier]] = _hash_list[i];
- }
-
- var item_data = [];
- for (var i in _hash_list) {
- var obj = _hash_list[i]
- obj[params.children] = [];
-
- for (var j in _hash_list) {
- var kid = _hash_list[j];
- if (kid[params.parent] == obj[params.identifier]) {
- obj[params.children].push( { _reference : kid[params.identifier] } );
- kid._iskid = true;
- if (_find_root[kid[params.identifier]]) delete _find_root[kid[params.identifier]];
- }
- }
-
- item_data.push( obj );
- }
-
- for (var j in _find_root) {
- _find_root[j]['_top'] = 'true';
- if (!_find_root[j][params.parent])
- _find_root[j]['_trueRoot'] = 'true';
- }
-
- data.items = item_data;
- }
-
- return data;
- }
-
- for (var i in fmclasses) window[i].prototype.fromStoreItem = _fromStoreItem;
-
- aou.prototype._ignore_fields = ['children'];
- aout.prototype._ignore_fields = ['children'];
- pgt.prototype._ignore_fields = ['children'];
-
- // set up the defaults
- for (var i in fmclasses) window[i].toStoreData = _toStoreData;
-
- aou.toStoreData = function (list, label) {
- if (!label) label = 'shortname';
- return _toStoreData(list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
- }
-
- aout.toStoreData = function (list, label) {
- if (!label) label = 'name';
- return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
-
- pgt.toStoreData = function (list, label) {
- if (!label) label = 'name';
- return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
- }
-
- /*
- ppl.toStoreData = function (list, label) {
- if (!label) label = 'code';
- return _toStoreData(list, label, {});
- }
- */
-
-}
+++ /dev/null
-if(!dojo._hasResource['fieldmapper.hash']){
-
- dojo._hasResource['fieldmapper.hash'] = true;
- dojo.provide('fieldmapper.hash');
- dojo.require('fieldmapper.Fieldmapper');
-
- function _fromHash (_hash) {
- for ( var i=0; i < this._fields.length; i++) {
- if (_hash[this._fields[i]] != null)
- this[this._fields[i]]( _hash[this._fields[i]] );
- }
- return this;
- }
-
- function _toHash () {
- var _hash = {};
- for ( var i=0; i < this._fields.length; i++) {
- if (this[this._fields[i]]() != null)
- _hash[this._fields[i]] = '' + this[this._fields[i]]();
- }
- return _hash;
- }
-
- for (var i in fmclasses) {
- window[i].prototype.fromHash = _fromHash;
- window[i].prototype.toHash = _toHash;
- }
-
-}
+++ /dev/null
-/* -----------------------------------------------------------------------
- * Copyright (C) 2008 Georgia Public Library Service
- * Bill Erickson <erickson@esilibrary.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * ----------------------------------------------------------------------- */
-
-/* session states */
-var OSRF_APP_SESSION_CONNECTED = 0;
-var OSRF_APP_SESSION_CONNECTING = 1;
-var OSRF_APP_SESSION_DISCONNECTED = 2;
-
-/* types of transport layers */
-var OSRF_TRANSPORT_TYPE_XHR = 1;
-var OSRF_TRANSPORT_TYPE_XMPP = 2;
-
-/* message types */
-var OSRF_MESSAGE_TYPE_REQUEST = 'REQUEST';
-var OSRF_MESSAGE_TYPE_STATUS = 'STATUS';
-var OSRF_MESSAGE_TYPE_RESULT = 'RESULT';
-var OSRF_MESSAGE_TYPE_CONNECT = 'CONNECT';
-var OSRF_MESSAGE_TYPE_DISCONNECT = 'DISCONNECT';
-
-/* message statuses */
-var OSRF_STATUS_CONTINUE = 100;
-var OSRF_STATUS_OK = 200;
-var OSRF_STATUS_ACCEPTED = 202;
-var OSRF_STATUS_COMPLETE = 205;
-var OSRF_STATUS_REDIRECTED = 307;
-var OSRF_STATUS_BADREQUEST = 400;
-var OSRF_STATUS_UNAUTHORIZED = 401;
-var OSRF_STATUS_FORBIDDEN = 403;
-var OSRF_STATUS_NOTFOUND = 404;
-var OSRF_STATUS_NOTALLOWED = 405;
-var OSRF_STATUS_TIMEOUT = 408;
-var OSRF_STATUS_EXPFAILED = 417;
-var OSRF_STATUS_INTERNALSERVERERROR = 500;
-var OSRF_STATUS_NOTIMPLEMENTED = 501;
-var OSRF_STATUS_VERSIONNOTSUPPORTED = 505;
-
-var OpenSRF = {};
-
-/* makes cls a subclass of pcls */
-OpenSRF.set_subclass = function(cls, pcls) {
- var str = cls+'.prototype = new '+pcls+'();';
- str += cls+'.prototype.constructor = '+cls+';';
- str += cls+'.baseClass = '+pcls+'.prototype.constructor;';
- str += cls+'.prototype.super = '+pcls+'.prototype;';
- eval(str);
-}
-
-
-/* general session superclass */
-OpenSRF.Session = function() {
- this.remote_id = null;
- this.state = OSRF_APP_SESSION_DISCONNECTED;
-}
-
-OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_XHR; /* default to XHR */
-OpenSRF.Session.cache = {};
-OpenSRF.Session.find_session = function(thread_trace) {
- return OpenSRF.Session.cache[thread_trace];
-}
-OpenSRF.Session.prototype.cleanup = function() {
- delete OpenSRF.Session.cache[this.thread];
-}
-
-OpenSRF.Session.prototype.send = function(osrf_msg, args) {
- args = (args) ? args : {};
- switch(OpenSRF.Session.transport) {
- case OSRF_TRANSPORT_TYPE_XHR:
- return this.send_xhr(osrf_msg, args);
- case OSRF_TRANSPORT_TYPE_XMPP:
- return this.send_xmpp(osrf_msg, args);
- }
-}
-
-OpenSRF.Session.prototype.send_xhr = function(osrf_msg, args) {
- args.thread = this.thread;
- args.rcpt = this.remote_id;
- args.rcpt_service = this.service;
- new OpenSRF.XHRequest(osrf_msg, args).send();
-}
-
-OpenSRF.Session.prototype.send_xmpp = function(osrf_msg, args) {
- alert('xmpp transport not yet implemented');
-}
-
-
-/* client sessions make requests */
-OpenSRF.ClientSession = function(service) {
- this.service = service
- this.remote_id = null;
- this.locale = 'en-US';
- this.last_id = 0;
- this.thread = Math.random() + '' + new Date().getTime();
- this.requests = [];
- this.onconnect = null;
- OpenSRF.Session.cache[this.thread] = this;
-}
-OpenSRF.set_subclass('OpenSRF.ClientSession', 'OpenSRF.Session');
-
-
-OpenSRF.ClientSession.prototype.connect = function(args) {
- args = (args) ? args : {};
-
- if(args.onconnect)
- this.onconnect = args.onconnect;
-
- /* if no handler is provided, make this a synchronous call */
- if(!this.onconnect)
- this.timeout = (args.timeout) ? args.timeout : 5;
-
- message = new osrfMessage({
- 'threadTrace' : this.reqid,
- 'type' : OSRF_MESSAGE_TYPE_CONNECT,
- });
-
- this.send(message, {'timeout' : this.timeout});
-
- if(this.onconnect || this.state == OSRF_APP_SESSION_CONNECTED)
- return true;
- return false;
-}
-
-OpenSRF.ClientSession.prototype.disconnect = function(args) {
- this.send(
- new osrfMessage({
- 'threadTrace' : this.reqid,
- 'type' : OSRF_MESSAGE_TYPE_DISCONNECT,
- })
- );
-}
-
-
-OpenSRF.ClientSession.prototype.request = function(args) {
-
- if(typeof args == 'string') {
- params = [];
- for(var i = 1; i < arguments.length; i++)
- params.push(arguments[i]);
-
- args = {
- method : args,
- params : params
- };
- } else {
- if(typeof args == 'undefined')
- args = {};
- }
-
- var req = new OpenSRF.Request(this, this.last_id++, args);
- this.requests.push(req);
- return req;
-}
-
-OpenSRF.ClientSession.prototype.find_request = function(reqid) {
- for(var i = 0; i < this.requests.length; i++) {
- var req = this.requests[i];
- if(req.reqid == reqid)
- return req;
- }
- return null;
-}
-
-OpenSRF.Request = function(session, reqid, args) {
- this.session = session;
- this.reqid = reqid;
-
- /* callbacks */
- this.onresponse = args.onresponse;
- this.oncomplete = args.oncomplete;
- this.onerror = args.onerror;
- this.onmethoderror = args.onmethoderror;
- this.ontransporterror = args.ontransporterror;
-
- this.method = args.method;
- this.params = args.params;
- this.timeout = args.timeout;
- this.response_queue = [];
- this.complete = false;
-}
-
-OpenSRF.Request.prototype.recv = function(timeout) {
- if(this.response_queue.length > 0)
- return this.response_queue.shift();
- return null;
-}
-
-OpenSRF.Request.prototype.send = function() {
- method = new osrfMethod({'method':this.method, 'params':this.params});
- message = new osrfMessage({
- 'threadTrace' : this.reqid,
- 'type' : OSRF_MESSAGE_TYPE_REQUEST,
- 'payload' : method,
- 'locale' : this.session.locale
- });
-
- this.session.send(message, {
- 'timeout' : this.timeout,
- 'onresponse' : this.onresponse,
- 'oncomplete' : this.oncomplete,
- 'onerror' : this.onerror,
- 'onmethoderror' : this.onmethoderror,
- 'ontransporterror' : this.ontransporterror
- });
-}
-
-OpenSRF.NetMessage = function(to, from, thread, body) {
- this.to = to;
- this.from = from;
- this.thread = thread;
- this.body = body;
-}
-
-OpenSRF.Stack = function() {
-}
-
-OpenSRF.Stack.push = function(net_msg, callbacks) {
- var ses = OpenSRF.Session.find_session(net_msg.thread);
- if(!ses) return;
- ses.remote_id = net_msg.sender;
- osrf_msgs = JSON2js(net_msg.body);
- for(var i = 0; i < osrf_msgs.length; i++)
- OpenSRF.Stack.handle_message(ses, osrf_msgs[i], callbacks);
-}
-
-OpenSRF.Stack.handle_message = function(ses, osrf_msg, callbacks) {
-
- var req = null;
-
- if(osrf_msg.type() == OSRF_MESSAGE_TYPE_STATUS) {
-
- var payload = osrf_msg.payload();
- var status = payload.statusCode();
- var status_text = payload.status();
-
- if(status == OSRF_STATUS_COMPLETE) {
- req = ses.find_request(osrf_msg.threadTrace());
- if(req) {
- req.complete = true;
- if(callbacks.oncomplete && !req.oncomplete_called) {
- req.oncomplete_called = true;
- return callbacks.oncomplete(req);
- }
- }
- }
-
- if(status == OSRF_STATUS_OK) {
- ses.state = OSRF_APP_SESSION_CONNECTED;
-
- /* call the connect callback */
- if(ses.onconnect && !ses.onconnect_called) {
- ses.onconnect_called = true;
- return ses.onconnect();
- }
- }
-
- if(status == OSRF_STATUS_NOTFOUND) {
- req = ses.find_request(osrf_msg.threadTrace());
- if(callbacks.onmethoderror)
- return callbacks.onmethoderror(req, status, status_text);
- }
- }
-
- if(osrf_msg.type() == OSRF_MESSAGE_TYPE_RESULT) {
- req = ses.find_request(osrf_msg.threadTrace());
- if(req) {
- req.response_queue.push(osrf_msg.payload());
- if(callbacks.onresponse)
- return callbacks.onresponse(req);
- }
- }
-}
-
-/* The following classes map directly to network-serializable opensrf objects */
-
-function osrfMessage(hash) {
- this.hash = hash;
- this._encodehash = true;
-}
-osrfMessage.prototype.threadTrace = function(d) {
- if(arguments.length == 1)
- this.hash.threadTrace = d;
- return this.hash.threadTrace;
-}
-osrfMessage.prototype.type = function(d) {
- if(arguments.length == 1)
- this.hash.type = d;
- return this.hash.type;
-}
-osrfMessage.prototype.payload = function(d) {
- if(arguments.length == 1)
- this.hash.payload = d;
- return this.hash.payload;
-}
-osrfMessage.prototype.locale = function(d) {
- if(arguments.length == 1)
- this.hash.locale = d;
- return this.hash.locale;
-}
-osrfMessage.prototype.serialize = function() {
- return {
- "__c":"osrfMessage",
- "__p": {
- 'threadTrace' : this.hash.threadTrace,
- 'type' : this.hash.type,
- 'payload' : (this.hash.payload) ? this.hash.payload.serialize() : 'null',
- 'locale' : this.hash.locale
- }
- };
-}
-
-function osrfMethod(hash) {
- this.hash = hash;
- this._encodehash = true;
-}
-osrfMethod.prototype.method = function() {
- if(arguments.length == 1)
- this.hash.method = d;
- return this.hash.method;
-}
-osrfMethod.prototype.params = function() {
- if(arguments.length == 1)
- this.hash.params = d;
- return this.hash.params;
-}
-osrfMethod.prototype.serialize = function() {
- return {
- "__c":"osrfMethod",
- "__p": {
- 'method' : this.hash.method,
- 'params' : this.hash.params
- }
- };
-}
-
-function osrfMethodException(hash) {
- this.hash = hash;
- this._encodehash = true;
-}
-osrfMethodException.prototype.status = function() {
- if(arguments.length == 1)
- this.hash.status = d;
- return this.hash.status;
-}
-osrfMethodException.prototype.statusCode = function() {
- if(arguments.length == 1)
- this.hash.statusCode = d;
- return this.hash.statusCode;
-}
-function osrfConnectStatus(hash) {
- this.hash = hash;
- this._encodehash = true;
-}
-osrfConnectStatus.prototype.status = function() {
- if(arguments.length == 1)
- this.hash.status = d;
- return this.hash.status;
-}
-osrfConnectStatus.prototype.statusCode = function() {
- if(arguments.length == 1)
- this.hash.statusCode = d;
- return this.hash.statusCode;
-}
-function osrfResult(hash) {
- this.hash = hash;
- this._encodehash = true;
-}
-osrfResult.prototype.status = function() {
- if(arguments.length == 1)
- this.hash.status = d;
- return this.hash.status;
-}
-osrfResult.prototype.statusCode = function() {
- if(arguments.length == 1)
- this.hash.statusCode = d;
- return this.hash.statusCode;
-}
-osrfResult.prototype.content = function() {
- if(arguments.length == 1)
- this.hash.content = d;
- return this.hash.content;
-}
-
-
-
+++ /dev/null
-/* -----------------------------------------------------------------------
- * Copyright (C) 2008 Georgia Public Library Service
- * Bill Erickson <erickson@esilibrary.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * ----------------------------------------------------------------------- */
-
-var OSRF_HTTP_HEADER_TO = 'X-OpenSRF-to';
-var OSRF_HTTP_HEADER_XID = 'X-OpenSRF-thread';
-var OSRF_HTTP_HEADER_FROM = 'X-OpenSRF-from';
-var OSRF_HTTP_HEADER_THREAD = 'X-OpenSRF-thread';
-var OSRF_HTTP_HEADER_TIMEOUT = 'X-OpenSRF-timeout';
-var OSRF_HTTP_HEADER_SERVICE = 'X-OpenSRF-service';
-var OSRF_HTTP_HEADER_MULTIPART = 'X-OpenSRF-multipart';
-var OSRF_HTTP_TRANSLATOR = '/osrf-http-translator'; /* XXX config */
-var OSRF_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded';
-
-
-OpenSRF.XHRequest = function(osrf_msg, args) {
- this.message = osrf_msg;
- this.args = args;
- this.xreq = new XMLHttpRequest(); /* XXX browser check */
-}
-
-OpenSRF.XHRequest.prototype.send = function() {
- var xhr_req = this;
- var xreq = this.xreq
-
- if(this.args.timeout) {
- /* this is a standard blocking (non-multipart) call */
- xreq.open('POST', OSRF_HTTP_TRANSLATOR, false);
-
- } else {
-
- if( /* XXX browser != mozilla */ false ) {
-
- /* standard asynchronous call */
- xreq.onreadystatechange = function() {
- if(xreq.readyState == 4)
- xhr_req.core_handler();
- }
- xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
-
- } else {
-
- /* asynchronous multipart call */
- xreq.multipart = true;
- xreq.onload = function(evt) {xhr_req.core_handler();}
- xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
- xreq.setRequestHeader(OSRF_HTTP_HEADER_MULTIPART, 'true');
-
- /* multipart requests do not pass the status info to the onload if there
- is no new data to load. Capture the status on the readystate handler */
- xreq.onreadystatechange = function() {
- if(xreq.readyState == 4 && xreq.status >= 400)
- xhr_req.transport_error_handler();
- }
- }
- }
-
- xreq.setRequestHeader('Content-Type', OSRF_POST_CONTENT_TYPE);
- xreq.setRequestHeader(OSRF_HTTP_HEADER_THREAD, this.args.thread);
- if(this.args.rcpt)
- xreq.setRequestHeader(OSRF_HTTP_HEADER_TO, this.args.rcpt);
- else
- xreq.setRequestHeader(OSRF_HTTP_HEADER_SERVICE, this.args.rcpt_service);
-
- var post = 'osrf-msg=' + encodeURIComponent(js2JSON([this.message.serialize()]));
- xreq.send(post);
-
- if(this.args.timeout) /* this was a blocking call, manually run the handler */
- this.core_handler()
-
- return this;
-}
-
-OpenSRF.XHRequest.prototype.core_handler = function() {
- sender = this.xreq.getResponseHeader(OSRF_HTTP_HEADER_FROM);
- thread = this.xreq.getResponseHeader(OSRF_HTTP_HEADER_THREAD);
- json = this.xreq.responseText;
- stat = this.xreq.status;
-
- if(stat >= 400)
- return this.transport_error_handler();
-
- OpenSRF.Stack.push(
- new OpenSRF.NetMessage(null, sender, thread, json),
- {
- onresponse : this.args.onresponse,
- oncomplete : this.args.oncomplete,
- onerror : this.args.onerror,
- onmethoderror : this.method_error_handler()
- }
- );
-}
-
-
-OpenSRF.XHRequest.prototype.method_error_handler = function() {
- var xhr = this;
- return function(req, status, status_text) {
- if(xhr.args.onmethoderror)
- xhr.args.onmethoderror(req, status, status_text);
- if(xhr.args.onerror)
- xhr.args.onerror(xhr.message, xhr.args.rcpt || xhr.args.rcpt_service, xhr.args.thread);
- }
-}
-
-OpenSRF.XHRequest.prototype.transport_error_handler = function() {
- if(this.args.ontransporterror)
- this.args.ontransporterror(this.xreq);
- if(this.args.onerror)
- this.args.onerror(this.message, this.args.rcpt || this.args.rcpt_service, this.args.thread);
-}
-
-
--- /dev/null
+if(!dojo._hasResource['OpenSRF']){
+
+ dojo._hasResource['OpenSRF'] = true;
+ dojo.provide('OpenSRF');
+ dojo.require('opensrf.opensrf', true);
+ dojo.require('opensrf.opensrf_xhr', true);
+
+ OpenSRF.session_cache = {};
+ OpenSRF.CachedClientSession = function ( app ) {
+ if (this.session_cache[app]) return this.session_cache[app];
+ this.session_cache[app] = new OpenSRF.ClientSession ( app );
+ return this.session_cache[app];
+ }
+}
--- /dev/null
+if(!dojo._hasResource["fieldmapper.Fieldmapper"]){
+
+/* generate fieldmapper javascript classes. This expects a global variable
+ called 'fmclasses' to be fleshed with the classes we need to build */
+
+ function FMEX(message) { this.message = message; }
+ FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
+
+
+ dojo._hasResource["fieldmapper.Fieldmapper"] = true;
+ dojo.provide("fieldmapper.Fieldmapper");
+ dojo.require("OpenSRF");
+
+ dojo.declare( "fieldmapper.Fieldmapper", null, {
+
+ constructor : function (initArray) {
+ if (initArray) {
+ if (dojo.isArray(initArray)) {
+ this.a = initArray;
+ } else {
+ this.a = [];
+ }
+ }
+ },
+
+ _isfieldmapper : true,
+ fm_classes : fmclasses,
+
+ 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;
+ },
+
+ 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._request = function ( meth, staff, params ) {
+ var ses = OpenSRF.CachedClientSession( meth[0] );
+ if (!ses) return null;
+
+ var result = null;
+ var args = {};
+
+ if (dojo.isArray(params)) {
+ args.params = params;
+ } else {
+
+ if (dojo.isObject(params)) {
+ args = params;
+ } else {
+ args.params = arguments.splice(1, arguments.length - 1);
+ }
+
+ }
+
+ if (!args.timeout) args.timeout = 10;
+
+ if (!args.onerror) {
+ args.error = function (r) {
+ throw 'Error encountered! ' + r;
+ }
+ }
+
+ if (!args.oncomplete) {
+ args.oncomplete = function (r) {
+ var x = r.recv();
+ if (x) result = x.content();
+ }
+ }
+
+ args.method = meth[1];
+ if (staff && meth[2]) args.method += '.staff';
+
+ ses.request(args).send();
+
+ return result;
+ };
+
+ fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
+ fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
+
+ fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
+ fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
+
+ 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];
+ for( var pos = 0; pos < this._fields.length; pos++ ) {
+ var p = parseInt(pos) + 3;
+ 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.OpenSRF = {};
+
+ /* Methods are defined as [ service, method, have_staff ]
+ An optional 3rd component is when a method is followed by true, such methods
+ have a staff counterpart and should have ".staff" appended to the method
+ before the method is called when in XUL mode */
+ fieldmapper.OpenSRF.methods = {
+ SEARCH_MRS : ['open-ils.search','open-ils.search.metabib.multiclass',true],
+ SEARCH_RS : ['open-ils.search','open-ils.search.biblio.multiclass',true],
+ SEARCH_MRS_QUERY : ['open-ils.search','open-ils.search.metabib.multiclass.query',true],
+ SEARCH_RS_QUERY : ['open-ils.search','open-ils.search.biblio.multiclass.query',true],
+ FETCH_SEARCH_RIDS : ['open-ils.search','open-ils.search.biblio.record.class.search',true],
+ FETCH_MRMODS : ['open-ils.search','open-ils.search.biblio.metarecord.mods_slim.retrieve'],
+ FETCH_MODS_FROM_COPY : ['open-ils.search','open-ils.search.biblio.mods_from_copy'],
+ FETCH_MR_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.metarecord.copy_count',true],
+ FETCH_RIDS : ['open-ils.search','open-ils.search.biblio.metarecord_to_records',true],
+ FETCH_RMODS : ['open-ils.search','open-ils.search.biblio.record.mods_slim.retrieve'],
+ FETCH_R_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.record.copy_count',true],
+ FETCH_FLESHED_USER : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve'],
+ FETCH_SESSION : ['open-ils.auth','open-ils.auth.session.retrieve'],
+ LOGIN_INIT : ['open-ils.auth','open-ils.auth.authenticate.init'],
+ LOGIN_COMPLETE : ['open-ils.auth','open-ils.auth.authenticate.complete'],
+ LOGIN_DELETE : ['open-ils.auth','open-ils.auth.session.delete'],
+ FETCH_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.retrieve'],
+ UPDATE_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.update'],
+ FETCH_COPY_STATUSES : ['open-ils.search','open-ils.search.config.copy_status.retrieve.all'],
+ FETCH_COPY_COUNTS_SUMMARY : ['open-ils.search','open-ils.search.biblio.copy_counts.summary.retrieve'],
+ FETCH_MARC_HTML : ['open-ils.search','open-ils.search.biblio.record.html'],
+ FETCH_CHECKED_OUT_SUM : ['open-ils.actor','open-ils.actor.user.checked_out'],
+ FETCH_HOLDS : ['open-ils.circ','open-ils.circ.holds.retrieve'],
+ FETCH_FINES_SUMMARY : ['open-ils.actor','open-ils.actor.user.fines.summary'],
+ FETCH_TRANSACTIONS : ['open-ils.actor','open-ils.actor.user.transactions.have_charge.fleshed'],
+ FETCH_MONEY_BILLING : ['open-ils.circ','open-ils.circ.money.billing.retrieve.all'],
+ FETCH_CROSSREF : ['open-ils.search','open-ils.search.authority.crossref'],
+ FETCH_CROSSREF_BATCH : ['open-ils.search','open-ils.search.authority.crossref.batch'],
+ CREATE_HOLD : ['open-ils.circ','open-ils.circ.holds.create'],
+ CREATE_HOLD_OVERRIDE : ['open-ils.circ','open-ils.circ.holds.create.override'],
+ CANCEL_HOLD : ['open-ils.circ','open-ils.circ.hold.cancel'],
+ UPDATE_USERNAME : ['open-ils.actor','open-ils.actor.user.username.update'],
+ UPDATE_PASSWORD : ['open-ils.actor','open-ils.actor.user.password.update'],
+ UPDATE_EMAIL : ['open-ils.actor','open-ils.actor.user.email.update'],
+ RENEW_CIRC : ['open-ils.circ','open-ils.circ.renew'],
+ CHECK_SPELL : ['open-ils.search','open-ils.search.spellcheck'],
+ FETCH_REVIEWS : ['open-ils.search','open-ils.search.added_content.review.retrieve.all'],
+ FETCH_TOC : ['open-ils.search','open-ils.search.added_content.toc.retrieve'],
+ FETCH_ACONT_SUMMARY : ['open-ils.search','open-ils.search.added_content.summary.retrieve'],
+ FETCH_USER_BYBARCODE : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve_by_barcode'],
+ FETCH_ADV_MARC_MRIDS : ['open-ils.search','open-ils.search.biblio.marc',true],
+ FETCH_ADV_ISBN_RIDS : ['open-ils.search','open-ils.search.biblio.isbn'],
+ FETCH_ADV_ISSN_RIDS : ['open-ils.search','open-ils.search.biblio.issn'],
+ FETCH_ADV_TCN_RIDS : ['open-ils.search','open-ils.search.biblio.tcn'],
+ FETCH_CNBROWSE : ['open-ils.search','open-ils.search.callnumber.browse'],
+ FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
+ FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
+ CREATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.create'],
+ DELETE_CONTAINER : ['open-ils.actor','open-ils.actor.container.full_delete'],
+ CREATE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.create'],
+ DELETE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.delete'],
+ FLESH_CONTAINER : ['open-ils.actor','open-ils.actor.container.flesh'],
+ FLESH_PUBLIC_CONTAINER : ['open-ils.actor','open-ils.actor.container.public.flesh'],
+ UPDATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.update'],
+ FETCH_COPY : ['open-ils.search','open-ils.search.asset.copy.retrieve'],
+ FETCH_FLESHED_COPY : ['open-ils.search','open-ils.search.asset.copy.fleshed2.retrieve'],
+ CHECK_HOLD_POSSIBLE : ['open-ils.circ','open-ils.circ.title_hold.is_possible'],
+ UPDATE_HOLD : ['open-ils.circ','open-ils.circ.hold.update'],
+ FETCH_COPIES_FROM_VOLUME : ['open-ils.search','open-ils.search.asset.copy.retrieve_by_cn_label',true],
+ FETCH_VOLUME_BY_INFO : ['open-ils.search','open-ils.search.call_number.retrieve_by_info'], /* XXX staff method? */
+ FETCH_VOLUME : ['open-ils.search','open-ils.search.asset.call_number.retrieve'],
+ FETCH_COPY_LOCATIONS : ['open-ils.circ','open-ils.circ.copy_location.retrieve.all'],
+ FETCH_COPY_NOTES : ['open-ils.circ','open-ils.circ.copy_note.retrieve.all'],
+ FETCH_COPY_STAT_CATS : ['open-ils.circ','open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy'],
+ FETCH_LIT_FORMS : ['open-ils.search','open-ils.search.biblio.lit_form_map.retrieve.all'],
+ FETCH_ITEM_FORMS : ['open-ils.search','open-ils.search.biblio.item_form_map.retrieve.all'],
+ FETCH_ITEM_TYPES : ['open-ils.search','open-ils.search.biblio.item_type_map.retrieve.all'],
+ FETCH_AUDIENCES : ['open-ils.search','open-ils.search.biblio.audience_map.retrieve.all'],
+ FETCH_HOLD_STATUS : ['open-ils.circ','open-ils.circ.hold.status.retrieve'],
+ FETCH_NON_CAT_CIRCS : ['open-ils.circ','open-ils.circ.open_non_cataloged_circulation.user'],
+ FETCH_NON_CAT_CIRC : ['open-ils.circ','open-ils.circ.non_cataloged_circulation.retrieve'],
+ FETCH_NON_CAT_TYPES : ['open-ils.circ','open-ils.circ.non_cat_types.retrieve.all'],
+ FETCH_BRE : ['open-ils.search','open-ils.search.biblio.record_entry.slim.retrieve'],
+ CHECK_USERNAME : ['open-ils.actor','open-ils.actor.username.exists'],
+ FETCH_CIRC_BY_ID : ['open-ils.circ','open-ils.circ.retrieve'],
+ FETCH_MR_DESCRIPTORS : ['open-ils.search','open-ils.search.metabib.record_to_descriptors'],
+ FETCH_HIGHEST_PERM_ORG : ['open-ils.actor','open-ils.actor.user.perm.highest_org.batch'],
+ FETCH_USER_NOTES : ['open-ils.actor','open-ils.actor.note.retrieve.all'],
+ FETCH_ORG_BY_SHORTNAME : ['open-ils.actor','open-ils.actor.org_unit.retrieve_by_shorname'],
+ FETCH_BIB_ID_BY_BARCODE : ['open-ils.search','open-ils.search.bib_id.by_barcode'],
+ FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default']
+ };
+
+}
+
+
+
--- /dev/null
+if(!dojo._hasResource["fieldmapper.OrgUtils"]){
+
+ dojo._hasResource["fieldmapper.OrgUtils"] = true;
+ dojo.provide("fieldmapper.OrgUtils");
+ dojo.require("fieldmapper.Fieldmapper");
+ dojo.require("fieldmapper.OrgTree", true);
+
+ fieldmapper.aou.globalOrgTree = {};
+ fieldmapper.aou.OrgCache = {};
+ fieldmapper.aou.OrgCacheSN = {};
+ fieldmapper.aout.OrgTypeCache = {};
+
+ fieldmapper.aout.LoadOrgTypes = function () {
+ for (var i in fieldmapper.aout.OrgTypeCache) {
+ return;
+ }
+
+ var types = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_types.retrieve']);
+
+ for (var i in types) {
+ fieldmapper.aout.OrgTypeCache[types[i].id()] = {
+ loaded : true,
+ type : types[i]
+ };
+ }
+ }
+
+ fieldmapper.aou.LoadOrg = function (id, slim_ok) {
+ var slim_o = fieldmapper.aou.OrgCache[id];
+
+ if (slim_o && (slim_ok || slim_o.loaded))
+ return fieldmapper.aou.OrgCache[id].org;
+
+ var o = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_unit.retrieve'],[null,id]);
+ fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o };
+ return o;
+ }
+ fieldmapper.aou.findOrgUnit = fieldmapper.aou.LoadOrg;
+
+ if (window._l) {
+ for (var i in _l) {
+ fieldmapper.aou.OrgCache[_l[i][0]] = {
+ loaded: false,
+ org : new fieldmapper.aou().fromHash({
+ id : _l[i][0],
+ ou_type : _l[i][1],
+ parent_ou : _l[i][2],
+ name : _l[i][3],
+ opac_visible : _l[i][4]
+ })
+ };
+
+ }
+
+ for (var i in fieldmapper.aou.OrgCache) {
+ var x = fieldmapper.aou.OrgCache[i].org;
+ if (x.parent_ou() == null || x.parent_ou() == '') {
+ fieldmapper.aou.globalOrgTree = x;
+ continue;
+ }
+
+ var parent = fieldmapper.aou.findOrgUnit(x.parent_ou(),true);
+ if (!parent.children()) parent.children([]);
+ parent.children().push(x);
+ fieldmapper.aou.OrgCache[x.id()].treePtr = x;
+ }
+
+ for (var i in globalOrgTypes) {
+ fieldmapper.aout.OrgTypeCache[globalOrgTypes[i].id()] = {
+ loaded : true,
+ type : globalOrgTypes[i]
+ };
+ }
+ }
+
+
+ /* ---------------------------------------------------------------------- */
+
+ fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
+ return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, name );
+ }
+
+ fieldmapper.aout.findOrgType = function (id) {
+ fieldmapper.aout.LoadOrgTypes();
+ return fieldmapper.aout.OrgTypeCache[id].type;
+ }
+
+ fieldmapper.aou.prototype.findOrgDepth = function (id) {
+ if (!id) id = this.id;
+ if (!id) return null;
+
+ var org = fieldmapper.aou.findOrgUnit(id);
+ return fieldmapper.findOrgType(
+ fieldmapper.aou.findOrgUnit(id).ou_type()
+ ).depth;
+ }
+ fieldmapper.aou.findOrgDepth = fieldmapper.aou.prototype.findOrgDepth;
+
+ fieldmapper.aout.findOrgTypeFromDepth = function (depth) {
+ if( depth == null ) return null;
+ fieldmapper.aout.LoadOrgTypes();
+ for( var i in fieldmapper.aout.OrgTypeCache ) {
+ var t = fieldmapper.aout.OrgTypeCache[i].type;
+ if( t.depth() == depth ) return t;
+ }
+ return null;
+ }
+
+ fieldmapper.aou.findOrgUnitSN = function (sn) {
+ var org = fieldmapper.aou.OrgCacheSN[sn];
+ if (!org) {
+ for (var i in fieldmapper.aou.OrgCache) {
+ var o = fieldmapper.aou.OrgCache[i];
+ if (o.loaded && o.org.shortname() == sn) {
+ fieldmapper.aou.OrgCacheSN[o.org.shortname()] = o;
+ return o.org;
+ }
+ }
+
+ org = fieldmapper.standardRequest(fieldmapper.OpenSRF.methods.FETCH_ORG_BY_SHORTNAME, sn);
+
+ fieldmapper.aou.OrgCache[org.id()] = { loaded : true, org : org };
+ fieldmapper.aou.OrgCacheSN[org.shortname()] = { loaded : true, org : org };
+
+ }
+
+ return org;
+ }
+
+ fieldmapper.aou.prototype.orgNodeTrail = function (node) {
+ if (!node) node = this;
+ if (!node) return [];
+
+ var na = [];
+
+ while( node ) {
+ na.push(node);
+ node = fieldmapper.aou.findOrgUnit(node.parent_ou());
+ }
+
+ return na.reverse();
+ }
+ fieldmapper.aou.orgNodeTrail = fieldmapper.aou.prototype.orgNodeTrail;
+
+ fieldmapper.aou.prototype.orgIsMine = function (me, org) {
+ if (this._isfieldmapper) {
+ org = me;
+ me = this;
+ }
+
+ if(!me || !org) return false;
+
+ if(me.id() == org.id()) return true;
+
+ for( var i in me.children() ) {
+ if(me.children()[i].orgIsMine(org)) return true;
+ }
+ return false;
+ }
+
+ dojo.addOnUnload( function () {
+ for (var i in fieldmapper.aou.OrgCache) {
+ x=fieldmapper.aou.OrgCache[i].treePtr;
+ if (!x) continue;
+
+ x.children(null);
+ x.parent_ou(null);
+ fieldmapper.aou.OrgCache[i]=null;
+ }
+ fieldmapper.aou.globalOrgTree = null;
+ fieldmapper.aou.OrgCache = null;
+ fieldmapper.aou.OrgCacheSN = null;
+ fieldmapper.aout.OrgTypeCache = null;
+ });
+}
+
+
+
--- /dev/null
+if(!dojo._hasResource['fieldmapper.dojoData']){
+
+ dojo._hasResource['fieldmapper.dojoData'] = true;
+ dojo.provide('fieldmapper.dojoData');
+ dojo.require('fieldmapper.Fieldmapper');
+ dojo.require('fieldmapper.hash');
+
+
+ function _fromStoreItem (data) {
+ this.fromHash(data);
+
+ for (var i in this._ignore_fields)
+ this[this._ignore_fields[i]](null);
+
+ for ( var i=0; i < this._fields.length; i++) {
+ if (dojo.isArray( this[this._fields[i]]() ))
+ this[this._fields[i]]( this[this._fields[i]]()[0] );
+ }
+ return this;
+ }
+
+ function _toStoreData (list, label, params) {
+
+ if (!params) params = {};
+ if (!list) list = {};
+
+ // a sane default
+ if (!params.identifier) params.identifier = 'id';
+ if (!label) label = params.label;
+ if (!label) label = params.identifier;
+
+ var data = { label : label, identifier : params.identifier, items : [] };
+
+ for (var i in list) data.items.push( list[i].toHash() );
+
+ if (params.children && params.parent) {
+ var _hash_list = data.items;
+
+ var _find_root = {};
+ for (var i in _hash_list) {
+ _find_root[_hash_list[i][params.identifier]] = _hash_list[i];
+ }
+
+ var item_data = [];
+ for (var i in _hash_list) {
+ var obj = _hash_list[i]
+ obj[params.children] = [];
+
+ for (var j in _hash_list) {
+ var kid = _hash_list[j];
+ if (kid[params.parent] == obj[params.identifier]) {
+ obj[params.children].push( { _reference : kid[params.identifier] } );
+ kid._iskid = true;
+ if (_find_root[kid[params.identifier]]) delete _find_root[kid[params.identifier]];
+ }
+ }
+
+ item_data.push( obj );
+ }
+
+ for (var j in _find_root) {
+ _find_root[j]['_top'] = 'true';
+ if (!_find_root[j][params.parent])
+ _find_root[j]['_trueRoot'] = 'true';
+ }
+
+ data.items = item_data;
+ }
+
+ return data;
+ }
+
+ for (var i in fmclasses) window[i].prototype.fromStoreItem = _fromStoreItem;
+
+ aou.prototype._ignore_fields = ['children'];
+ aout.prototype._ignore_fields = ['children'];
+ pgt.prototype._ignore_fields = ['children'];
+
+ // set up the defaults
+ for (var i in fmclasses) window[i].toStoreData = _toStoreData;
+
+ aou.toStoreData = function (list, label) {
+ if (!label) label = 'shortname';
+ return _toStoreData(list, label, { 'parent' : 'parent_ou', 'children' : 'children' });
+ }
+
+ aout.toStoreData = function (list, label) {
+ if (!label) label = 'name';
+ return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+ }
+
+ pgt.toStoreData = function (list, label) {
+ if (!label) label = 'name';
+ return _toStoreData(list, label, { 'parent' : 'parent', 'children' : 'children' });
+ }
+
+ /*
+ ppl.toStoreData = function (list, label) {
+ if (!label) label = 'code';
+ return _toStoreData(list, label, {});
+ }
+ */
+
+}
--- /dev/null
+if(!dojo._hasResource['fieldmapper.hash']){
+
+ dojo._hasResource['fieldmapper.hash'] = true;
+ dojo.provide('fieldmapper.hash');
+ dojo.require('fieldmapper.Fieldmapper');
+
+ function _fromHash (_hash) {
+ for ( var i=0; i < this._fields.length; i++) {
+ if (_hash[this._fields[i]] != null)
+ this[this._fields[i]]( _hash[this._fields[i]] );
+ }
+ return this;
+ }
+
+ function _toHash () {
+ var _hash = {};
+ for ( var i=0; i < this._fields.length; i++) {
+ if (this[this._fields[i]]() != null)
+ _hash[this._fields[i]] = '' + this[this._fields[i]]();
+ }
+ return _hash;
+ }
+
+ for (var i in fmclasses) {
+ window[i].prototype.fromHash = _fromHash;
+ window[i].prototype.toHash = _toHash;
+ }
+
+}
--- /dev/null
+/* -----------------------------------------------------------------------
+ * Copyright (C) 2008 Georgia Public Library Service
+ * Bill Erickson <erickson@esilibrary.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * ----------------------------------------------------------------------- */
+
+/* session states */
+var OSRF_APP_SESSION_CONNECTED = 0;
+var OSRF_APP_SESSION_CONNECTING = 1;
+var OSRF_APP_SESSION_DISCONNECTED = 2;
+
+/* types of transport layers */
+var OSRF_TRANSPORT_TYPE_XHR = 1;
+var OSRF_TRANSPORT_TYPE_XMPP = 2;
+
+/* message types */
+var OSRF_MESSAGE_TYPE_REQUEST = 'REQUEST';
+var OSRF_MESSAGE_TYPE_STATUS = 'STATUS';
+var OSRF_MESSAGE_TYPE_RESULT = 'RESULT';
+var OSRF_MESSAGE_TYPE_CONNECT = 'CONNECT';
+var OSRF_MESSAGE_TYPE_DISCONNECT = 'DISCONNECT';
+
+/* message statuses */
+var OSRF_STATUS_CONTINUE = 100;
+var OSRF_STATUS_OK = 200;
+var OSRF_STATUS_ACCEPTED = 202;
+var OSRF_STATUS_COMPLETE = 205;
+var OSRF_STATUS_REDIRECTED = 307;
+var OSRF_STATUS_BADREQUEST = 400;
+var OSRF_STATUS_UNAUTHORIZED = 401;
+var OSRF_STATUS_FORBIDDEN = 403;
+var OSRF_STATUS_NOTFOUND = 404;
+var OSRF_STATUS_NOTALLOWED = 405;
+var OSRF_STATUS_TIMEOUT = 408;
+var OSRF_STATUS_EXPFAILED = 417;
+var OSRF_STATUS_INTERNALSERVERERROR = 500;
+var OSRF_STATUS_NOTIMPLEMENTED = 501;
+var OSRF_STATUS_VERSIONNOTSUPPORTED = 505;
+
+var OpenSRF = {};
+
+/* makes cls a subclass of pcls */
+OpenSRF.set_subclass = function(cls, pcls) {
+ var str = cls+'.prototype = new '+pcls+'();';
+ str += cls+'.prototype.constructor = '+cls+';';
+ str += cls+'.baseClass = '+pcls+'.prototype.constructor;';
+ str += cls+'.prototype.super = '+pcls+'.prototype;';
+ eval(str);
+}
+
+
+/* general session superclass */
+OpenSRF.Session = function() {
+ this.remote_id = null;
+ this.state = OSRF_APP_SESSION_DISCONNECTED;
+}
+
+OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_XHR; /* default to XHR */
+OpenSRF.Session.cache = {};
+OpenSRF.Session.find_session = function(thread_trace) {
+ return OpenSRF.Session.cache[thread_trace];
+}
+OpenSRF.Session.prototype.cleanup = function() {
+ delete OpenSRF.Session.cache[this.thread];
+}
+
+OpenSRF.Session.prototype.send = function(osrf_msg, args) {
+ args = (args) ? args : {};
+ switch(OpenSRF.Session.transport) {
+ case OSRF_TRANSPORT_TYPE_XHR:
+ return this.send_xhr(osrf_msg, args);
+ case OSRF_TRANSPORT_TYPE_XMPP:
+ return this.send_xmpp(osrf_msg, args);
+ }
+}
+
+OpenSRF.Session.prototype.send_xhr = function(osrf_msg, args) {
+ args.thread = this.thread;
+ args.rcpt = this.remote_id;
+ args.rcpt_service = this.service;
+ new OpenSRF.XHRequest(osrf_msg, args).send();
+}
+
+OpenSRF.Session.prototype.send_xmpp = function(osrf_msg, args) {
+ alert('xmpp transport not yet implemented');
+}
+
+
+/* client sessions make requests */
+OpenSRF.ClientSession = function(service) {
+ this.service = service
+ this.remote_id = null;
+ this.locale = 'en-US';
+ this.last_id = 0;
+ this.thread = Math.random() + '' + new Date().getTime();
+ this.requests = [];
+ this.onconnect = null;
+ OpenSRF.Session.cache[this.thread] = this;
+}
+OpenSRF.set_subclass('OpenSRF.ClientSession', 'OpenSRF.Session');
+
+
+OpenSRF.ClientSession.prototype.connect = function(args) {
+ args = (args) ? args : {};
+
+ if(args.onconnect)
+ this.onconnect = args.onconnect;
+
+ /* if no handler is provided, make this a synchronous call */
+ if(!this.onconnect)
+ this.timeout = (args.timeout) ? args.timeout : 5;
+
+ message = new osrfMessage({
+ 'threadTrace' : this.reqid,
+ 'type' : OSRF_MESSAGE_TYPE_CONNECT,
+ });
+
+ this.send(message, {'timeout' : this.timeout});
+
+ if(this.onconnect || this.state == OSRF_APP_SESSION_CONNECTED)
+ return true;
+ return false;
+}
+
+OpenSRF.ClientSession.prototype.disconnect = function(args) {
+ this.send(
+ new osrfMessage({
+ 'threadTrace' : this.reqid,
+ 'type' : OSRF_MESSAGE_TYPE_DISCONNECT,
+ })
+ );
+}
+
+
+OpenSRF.ClientSession.prototype.request = function(args) {
+
+ if(typeof args == 'string') {
+ params = [];
+ for(var i = 1; i < arguments.length; i++)
+ params.push(arguments[i]);
+
+ args = {
+ method : args,
+ params : params
+ };
+ } else {
+ if(typeof args == 'undefined')
+ args = {};
+ }
+
+ var req = new OpenSRF.Request(this, this.last_id++, args);
+ this.requests.push(req);
+ return req;
+}
+
+OpenSRF.ClientSession.prototype.find_request = function(reqid) {
+ for(var i = 0; i < this.requests.length; i++) {
+ var req = this.requests[i];
+ if(req.reqid == reqid)
+ return req;
+ }
+ return null;
+}
+
+OpenSRF.Request = function(session, reqid, args) {
+ this.session = session;
+ this.reqid = reqid;
+
+ /* callbacks */
+ this.onresponse = args.onresponse;
+ this.oncomplete = args.oncomplete;
+ this.onerror = args.onerror;
+ this.onmethoderror = args.onmethoderror;
+ this.ontransporterror = args.ontransporterror;
+
+ this.method = args.method;
+ this.params = args.params;
+ this.timeout = args.timeout;
+ this.response_queue = [];
+ this.complete = false;
+}
+
+OpenSRF.Request.prototype.recv = function(timeout) {
+ if(this.response_queue.length > 0)
+ return this.response_queue.shift();
+ return null;
+}
+
+OpenSRF.Request.prototype.send = function() {
+ method = new osrfMethod({'method':this.method, 'params':this.params});
+ message = new osrfMessage({
+ 'threadTrace' : this.reqid,
+ 'type' : OSRF_MESSAGE_TYPE_REQUEST,
+ 'payload' : method,
+ 'locale' : this.session.locale
+ });
+
+ this.session.send(message, {
+ 'timeout' : this.timeout,
+ 'onresponse' : this.onresponse,
+ 'oncomplete' : this.oncomplete,
+ 'onerror' : this.onerror,
+ 'onmethoderror' : this.onmethoderror,
+ 'ontransporterror' : this.ontransporterror
+ });
+}
+
+OpenSRF.NetMessage = function(to, from, thread, body) {
+ this.to = to;
+ this.from = from;
+ this.thread = thread;
+ this.body = body;
+}
+
+OpenSRF.Stack = function() {
+}
+
+OpenSRF.Stack.push = function(net_msg, callbacks) {
+ var ses = OpenSRF.Session.find_session(net_msg.thread);
+ if(!ses) return;
+ ses.remote_id = net_msg.sender;
+ osrf_msgs = JSON2js(net_msg.body);
+ for(var i = 0; i < osrf_msgs.length; i++)
+ OpenSRF.Stack.handle_message(ses, osrf_msgs[i], callbacks);
+}
+
+OpenSRF.Stack.handle_message = function(ses, osrf_msg, callbacks) {
+
+ var req = null;
+
+ if(osrf_msg.type() == OSRF_MESSAGE_TYPE_STATUS) {
+
+ var payload = osrf_msg.payload();
+ var status = payload.statusCode();
+ var status_text = payload.status();
+
+ if(status == OSRF_STATUS_COMPLETE) {
+ req = ses.find_request(osrf_msg.threadTrace());
+ if(req) {
+ req.complete = true;
+ if(callbacks.oncomplete && !req.oncomplete_called) {
+ req.oncomplete_called = true;
+ return callbacks.oncomplete(req);
+ }
+ }
+ }
+
+ if(status == OSRF_STATUS_OK) {
+ ses.state = OSRF_APP_SESSION_CONNECTED;
+
+ /* call the connect callback */
+ if(ses.onconnect && !ses.onconnect_called) {
+ ses.onconnect_called = true;
+ return ses.onconnect();
+ }
+ }
+
+ if(status == OSRF_STATUS_NOTFOUND) {
+ req = ses.find_request(osrf_msg.threadTrace());
+ if(callbacks.onmethoderror)
+ return callbacks.onmethoderror(req, status, status_text);
+ }
+ }
+
+ if(osrf_msg.type() == OSRF_MESSAGE_TYPE_RESULT) {
+ req = ses.find_request(osrf_msg.threadTrace());
+ if(req) {
+ req.response_queue.push(osrf_msg.payload());
+ if(callbacks.onresponse)
+ return callbacks.onresponse(req);
+ }
+ }
+}
+
+/* The following classes map directly to network-serializable opensrf objects */
+
+function osrfMessage(hash) {
+ this.hash = hash;
+ this._encodehash = true;
+}
+osrfMessage.prototype.threadTrace = function(d) {
+ if(arguments.length == 1)
+ this.hash.threadTrace = d;
+ return this.hash.threadTrace;
+}
+osrfMessage.prototype.type = function(d) {
+ if(arguments.length == 1)
+ this.hash.type = d;
+ return this.hash.type;
+}
+osrfMessage.prototype.payload = function(d) {
+ if(arguments.length == 1)
+ this.hash.payload = d;
+ return this.hash.payload;
+}
+osrfMessage.prototype.locale = function(d) {
+ if(arguments.length == 1)
+ this.hash.locale = d;
+ return this.hash.locale;
+}
+osrfMessage.prototype.serialize = function() {
+ return {
+ "__c":"osrfMessage",
+ "__p": {
+ 'threadTrace' : this.hash.threadTrace,
+ 'type' : this.hash.type,
+ 'payload' : (this.hash.payload) ? this.hash.payload.serialize() : 'null',
+ 'locale' : this.hash.locale
+ }
+ };
+}
+
+function osrfMethod(hash) {
+ this.hash = hash;
+ this._encodehash = true;
+}
+osrfMethod.prototype.method = function() {
+ if(arguments.length == 1)
+ this.hash.method = d;
+ return this.hash.method;
+}
+osrfMethod.prototype.params = function() {
+ if(arguments.length == 1)
+ this.hash.params = d;
+ return this.hash.params;
+}
+osrfMethod.prototype.serialize = function() {
+ return {
+ "__c":"osrfMethod",
+ "__p": {
+ 'method' : this.hash.method,
+ 'params' : this.hash.params
+ }
+ };
+}
+
+function osrfMethodException(hash) {
+ this.hash = hash;
+ this._encodehash = true;
+}
+osrfMethodException.prototype.status = function() {
+ if(arguments.length == 1)
+ this.hash.status = d;
+ return this.hash.status;
+}
+osrfMethodException.prototype.statusCode = function() {
+ if(arguments.length == 1)
+ this.hash.statusCode = d;
+ return this.hash.statusCode;
+}
+function osrfConnectStatus(hash) {
+ this.hash = hash;
+ this._encodehash = true;
+}
+osrfConnectStatus.prototype.status = function() {
+ if(arguments.length == 1)
+ this.hash.status = d;
+ return this.hash.status;
+}
+osrfConnectStatus.prototype.statusCode = function() {
+ if(arguments.length == 1)
+ this.hash.statusCode = d;
+ return this.hash.statusCode;
+}
+function osrfResult(hash) {
+ this.hash = hash;
+ this._encodehash = true;
+}
+osrfResult.prototype.status = function() {
+ if(arguments.length == 1)
+ this.hash.status = d;
+ return this.hash.status;
+}
+osrfResult.prototype.statusCode = function() {
+ if(arguments.length == 1)
+ this.hash.statusCode = d;
+ return this.hash.statusCode;
+}
+osrfResult.prototype.content = function() {
+ if(arguments.length == 1)
+ this.hash.content = d;
+ return this.hash.content;
+}
+
+
+
--- /dev/null
+/* -----------------------------------------------------------------------
+ * Copyright (C) 2008 Georgia Public Library Service
+ * Bill Erickson <erickson@esilibrary.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * ----------------------------------------------------------------------- */
+
+var OSRF_HTTP_HEADER_TO = 'X-OpenSRF-to';
+var OSRF_HTTP_HEADER_XID = 'X-OpenSRF-thread';
+var OSRF_HTTP_HEADER_FROM = 'X-OpenSRF-from';
+var OSRF_HTTP_HEADER_THREAD = 'X-OpenSRF-thread';
+var OSRF_HTTP_HEADER_TIMEOUT = 'X-OpenSRF-timeout';
+var OSRF_HTTP_HEADER_SERVICE = 'X-OpenSRF-service';
+var OSRF_HTTP_HEADER_MULTIPART = 'X-OpenSRF-multipart';
+var OSRF_HTTP_TRANSLATOR = '/osrf-http-translator'; /* XXX config */
+var OSRF_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded';
+
+
+OpenSRF.XHRequest = function(osrf_msg, args) {
+ this.message = osrf_msg;
+ this.args = args;
+ this.xreq = new XMLHttpRequest(); /* XXX browser check */
+}
+
+OpenSRF.XHRequest.prototype.send = function() {
+ var xhr_req = this;
+ var xreq = this.xreq
+
+ if(this.args.timeout) {
+ /* this is a standard blocking (non-multipart) call */
+ xreq.open('POST', OSRF_HTTP_TRANSLATOR, false);
+
+ } else {
+
+ if( /* XXX browser != mozilla */ false ) {
+
+ /* standard asynchronous call */
+ xreq.onreadystatechange = function() {
+ if(xreq.readyState == 4)
+ xhr_req.core_handler();
+ }
+ xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
+
+ } else {
+
+ /* asynchronous multipart call */
+ xreq.multipart = true;
+ xreq.onload = function(evt) {xhr_req.core_handler();}
+ xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
+ xreq.setRequestHeader(OSRF_HTTP_HEADER_MULTIPART, 'true');
+
+ /* multipart requests do not pass the status info to the onload if there
+ is no new data to load. Capture the status on the readystate handler */
+ xreq.onreadystatechange = function() {
+ if(xreq.readyState == 4 && xreq.status >= 400)
+ xhr_req.transport_error_handler();
+ }
+ }
+ }
+
+ xreq.setRequestHeader('Content-Type', OSRF_POST_CONTENT_TYPE);
+ xreq.setRequestHeader(OSRF_HTTP_HEADER_THREAD, this.args.thread);
+ if(this.args.rcpt)
+ xreq.setRequestHeader(OSRF_HTTP_HEADER_TO, this.args.rcpt);
+ else
+ xreq.setRequestHeader(OSRF_HTTP_HEADER_SERVICE, this.args.rcpt_service);
+
+ var post = 'osrf-msg=' + encodeURIComponent(js2JSON([this.message.serialize()]));
+ xreq.send(post);
+
+ if(this.args.timeout) /* this was a blocking call, manually run the handler */
+ this.core_handler()
+
+ return this;
+}
+
+OpenSRF.XHRequest.prototype.core_handler = function() {
+ sender = this.xreq.getResponseHeader(OSRF_HTTP_HEADER_FROM);
+ thread = this.xreq.getResponseHeader(OSRF_HTTP_HEADER_THREAD);
+ json = this.xreq.responseText;
+ stat = this.xreq.status;
+
+ if(stat >= 400)
+ return this.transport_error_handler();
+
+ OpenSRF.Stack.push(
+ new OpenSRF.NetMessage(null, sender, thread, json),
+ {
+ onresponse : this.args.onresponse,
+ oncomplete : this.args.oncomplete,
+ onerror : this.args.onerror,
+ onmethoderror : this.method_error_handler()
+ }
+ );
+}
+
+
+OpenSRF.XHRequest.prototype.method_error_handler = function() {
+ var xhr = this;
+ return function(req, status, status_text) {
+ if(xhr.args.onmethoderror)
+ xhr.args.onmethoderror(req, status, status_text);
+ if(xhr.args.onerror)
+ xhr.args.onerror(xhr.message, xhr.args.rcpt || xhr.args.rcpt_service, xhr.args.thread);
+ }
+}
+
+OpenSRF.XHRequest.prototype.transport_error_handler = function() {
+ if(this.args.ontransporterror)
+ this.args.ontransporterror(this.xreq);
+ if(this.args.onerror)
+ this.args.onerror(this.message, this.args.rcpt || this.args.rcpt_service, this.args.thread);
+}
+
+