2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008 Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
18 if(!dojo._hasResource["fieldmapper.Fieldmapper"]){
20 /* generate fieldmapper javascript classes. This expects a global variable
21 called 'fmclasses' to be fleshed with the classes we need to build */
23 function FMEX(message) { this.message = message; }
24 FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
27 dojo._hasResource["fieldmapper.Fieldmapper"] = true;
28 dojo.provide("fieldmapper.Fieldmapper");
29 dojo.require("DojoSRF");
31 dojo.declare( "fieldmapper.Fieldmapper", null, {
33 constructor : function (initArray) {
35 if (dojo.isArray(initArray)) {
43 _isfieldmapper : true,
46 var obj = new this.constructor();
48 for( var i in this.a ) {
49 var thing = this.a[i];
50 if(thing == null) continue;
52 if( thing._isfieldmapper ) {
53 obj.a[i] = thing.clone();
56 if(instanceOf(thing, Array)) {
57 obj.a[i] = new Array();
59 for( var j in thing ) {
61 if( thing[j]._isfieldmapper )
62 obj.a[i][j] = thing[j].clone();
64 obj.a[i][j] = thing[j];
74 isnew : function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; },
75 ischanged : function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; },
76 isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
79 fieldmapper._request = function ( meth, staff, params ) {
80 var ses = OpenSRF.CachedClientSession( meth[0] );
81 if (!ses) return null;
86 if (dojo.isArray(params)) {
90 if (dojo.isObject(params)) {
93 args.params = [].splice.call(arguments, 1, arguments.length - 1);
98 if (!args.async && !args.timeout) args.timeout = 10;
100 if(!args.onmethoderror) {
101 args.onmethoderror = function(r, stat, stat_text) {
102 throw new Error('Method error: ' + r.stat + ' : ' + stat_text);
106 if(!args.ontransporterror) {
107 args.ontransporterror = function(xreq) {
108 throw new Error('Transport error method='+args.method+', status=' + xreq.status);
113 args.onerror = function (r) {
114 throw new Error('Request error encountered! ' + r);
118 if (!args.oncomplete) {
119 args.oncomplete = function (r) {
121 if (x) result = x.content();
125 args.method = meth[1];
126 if (staff && meth[2]) args.method += '.staff';
128 ses.request(args).send();
133 fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
134 fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
136 fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
137 fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
139 // if we were called by the IDL loader ...
140 if ( fieldmapper.IDL && fieldmapper.IDL.loaded ) {
141 for( var cl in fieldmapper.IDL.fmclasses ) {
143 dojo.declare( cl , fieldmapper.Fieldmapper, {
144 constructor : function () {
145 if (!this.a) this.a = [];
146 this.classname = this.declaredClass;
148 this.Structure = fieldmapper.IDL.fmclasses[this.classname]
150 for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
151 var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
152 var p = field.array_position;
153 if (p <= 2) continue;
155 this._fields.push( field.name );
156 this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
160 fieldmapper[cl] = window[cl]; // alias into place
161 fieldmapper[cl].Identifier = fieldmapper.IDL.fmclasses[cl].pkey;
164 // ... otherwise we need to get the oldschool fmall.js stuff, which will lack .structure
166 if (!window.fmclasses)
167 dojo.require("fieldmapper.fmall", true);
169 for( var cl in fmclasses ) {
171 dojo.declare( cl , fieldmapper.Fieldmapper, {
172 constructor : function () {
173 if (!this.a) this.a = [];
174 this.classname = this.declaredClass;
175 this._fields = fmclasses[this.classname];
176 for( var pos = 0; pos < this._fields.length; pos++ ) {
177 var p = parseInt(pos) + 3;
178 var f = this._fields[pos];
179 this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
183 fieldmapper[cl] = window[cl]; // alias into place
184 fieldmapper[cl].Identifier = 'id'; // alias into place
187 fieldmapper.i18n_l.Identifier = 'code';
188 fieldmapper.ccpbt.Identifier = 'code';
189 fieldmapper.ccnbt.Identifier = 'code';
190 fieldmapper.cbrebt.Identifier = 'code';
191 fieldmapper.cubt.Identifier = 'code';
192 fieldmapper.ccm.Identifier = 'code';
193 fieldmapper.cvrfm.Identifier = 'code';
194 fieldmapper.clm.Identifier = 'code';
195 fieldmapper.cam.Identifier = 'code';
196 fieldmapper.cifm.Identifier = 'code';
197 fieldmapper.citm.Identifier = 'code';
198 fieldmapper.cblvl.Identifier = 'code';
199 fieldmapper.clfm.Identifier = 'code';
200 fieldmapper.mous.Identifier = 'usr';
201 fieldmapper.moucs.Identifier = 'usr';
202 fieldmapper.mucs.Identifier = 'usr';
203 fieldmapper.mus.Identifier = 'usr';
204 fieldmapper.rxbt.Identifier = 'xact';
205 fieldmapper.rxpt.Identifier = 'xact';
206 fieldmapper.cxt.Identifier = 'name';
207 fieldmapper.amtr.Identifier = 'matchpoint';
211 fieldmapper.OpenSRF = {};
213 /* Methods are defined as [ service, method, have_staff ]
214 An optional 3rd component is when a method is followed by true, such methods
215 have a staff counterpart and should have ".staff" appended to the method
216 before the method is called when in XUL mode */
217 fieldmapper.OpenSRF.methods = {
218 SEARCH_MRS : ['open-ils.search','open-ils.search.metabib.multiclass',true],
219 SEARCH_RS : ['open-ils.search','open-ils.search.biblio.multiclass',true],
220 SEARCH_MRS_QUERY : ['open-ils.search','open-ils.search.metabib.multiclass.query',true],
221 SEARCH_RS_QUERY : ['open-ils.search','open-ils.search.biblio.multiclass.query',true],
222 FETCH_SEARCH_RIDS : ['open-ils.search','open-ils.search.biblio.record.class.search',true],
223 FETCH_MRMODS : ['open-ils.search','open-ils.search.biblio.metarecord.mods_slim.retrieve'],
224 FETCH_MODS_FROM_COPY : ['open-ils.search','open-ils.search.biblio.mods_from_copy'],
225 FETCH_MR_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.metarecord.copy_count',true],
226 FETCH_RIDS : ['open-ils.search','open-ils.search.biblio.metarecord_to_records',true],
227 FETCH_RMODS : ['open-ils.search','open-ils.search.biblio.record.mods_slim.retrieve'],
228 FETCH_R_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.record.copy_count',true],
229 FETCH_FLESHED_USER : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve'],
230 FETCH_SESSION : ['open-ils.auth','open-ils.auth.session.retrieve'],
231 LOGIN_INIT : ['open-ils.auth','open-ils.auth.authenticate.init'],
232 LOGIN_COMPLETE : ['open-ils.auth','open-ils.auth.authenticate.complete'],
233 LOGIN_DELETE : ['open-ils.auth','open-ils.auth.session.delete'],
234 FETCH_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.retrieve'],
235 UPDATE_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.update'],
236 FETCH_COPY_STATUSES : ['open-ils.search','open-ils.search.config.copy_status.retrieve.all'],
237 FETCH_COPY_COUNTS_SUMMARY : ['open-ils.search','open-ils.search.biblio.copy_counts.summary.retrieve'],
238 FETCH_MARC_HTML : ['open-ils.search','open-ils.search.biblio.record.html'],
239 FETCH_CHECKED_OUT_SUM : ['open-ils.actor','open-ils.actor.user.checked_out'],
240 FETCH_HOLDS : ['open-ils.circ','open-ils.circ.holds.retrieve'],
241 FETCH_FINES_SUMMARY : ['open-ils.actor','open-ils.actor.user.fines.summary'],
242 FETCH_TRANSACTIONS : ['open-ils.actor','open-ils.actor.user.transactions.have_charge.fleshed'],
243 FETCH_MONEY_BILLING : ['open-ils.circ','open-ils.circ.money.billing.retrieve.all'],
244 FETCH_CROSSREF : ['open-ils.search','open-ils.search.authority.crossref'],
245 FETCH_CROSSREF_BATCH : ['open-ils.search','open-ils.search.authority.crossref.batch'],
246 CREATE_HOLD : ['open-ils.circ','open-ils.circ.holds.create'],
247 CREATE_HOLD_OVERRIDE : ['open-ils.circ','open-ils.circ.holds.create.override'],
248 CANCEL_HOLD : ['open-ils.circ','open-ils.circ.hold.cancel'],
249 UPDATE_USERNAME : ['open-ils.actor','open-ils.actor.user.username.update'],
250 UPDATE_PASSWORD : ['open-ils.actor','open-ils.actor.user.password.update'],
251 UPDATE_EMAIL : ['open-ils.actor','open-ils.actor.user.email.update'],
252 RENEW_CIRC : ['open-ils.circ','open-ils.circ.renew'],
253 CHECK_SPELL : ['open-ils.search','open-ils.search.spellcheck'],
254 FETCH_REVIEWS : ['open-ils.search','open-ils.search.added_content.review.retrieve.all'],
255 FETCH_TOC : ['open-ils.search','open-ils.search.added_content.toc.retrieve'],
256 FETCH_ACONT_SUMMARY : ['open-ils.search','open-ils.search.added_content.summary.retrieve'],
257 FETCH_USER_BYBARCODE : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve_by_barcode'],
258 FETCH_ADV_MARC_MRIDS : ['open-ils.search','open-ils.search.biblio.marc',true],
259 FETCH_ADV_ISBN_RIDS : ['open-ils.search','open-ils.search.biblio.isbn'],
260 FETCH_ADV_ISSN_RIDS : ['open-ils.search','open-ils.search.biblio.issn'],
261 FETCH_ADV_TCN_RIDS : ['open-ils.search','open-ils.search.biblio.tcn'],
262 FETCH_CNBROWSE : ['open-ils.search','open-ils.search.callnumber.browse'],
263 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
264 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
265 CREATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.create'],
266 DELETE_CONTAINER : ['open-ils.actor','open-ils.actor.container.full_delete'],
267 CREATE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.create'],
268 DELETE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.delete'],
269 FLESH_CONTAINER : ['open-ils.actor','open-ils.actor.container.flesh'],
270 FLESH_PUBLIC_CONTAINER : ['open-ils.actor','open-ils.actor.container.public.flesh'],
271 UPDATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.update'],
272 FETCH_COPY : ['open-ils.search','open-ils.search.asset.copy.retrieve'],
273 FETCH_FLESHED_COPY : ['open-ils.search','open-ils.search.asset.copy.fleshed2.retrieve'],
274 CHECK_HOLD_POSSIBLE : ['open-ils.circ','open-ils.circ.title_hold.is_possible'],
275 UPDATE_HOLD : ['open-ils.circ','open-ils.circ.hold.update'],
276 FETCH_COPIES_FROM_VOLUME : ['open-ils.search','open-ils.search.asset.copy.retrieve_by_cn_label',true],
277 FETCH_VOLUME_BY_INFO : ['open-ils.search','open-ils.search.call_number.retrieve_by_info'], /* XXX staff method? */
278 FETCH_VOLUME : ['open-ils.search','open-ils.search.asset.call_number.retrieve'],
279 FETCH_COPY_LOCATIONS : ['open-ils.circ','open-ils.circ.copy_location.retrieve.all'],
280 FETCH_COPY_NOTES : ['open-ils.circ','open-ils.circ.copy_note.retrieve.all'],
281 FETCH_COPY_STAT_CATS : ['open-ils.circ','open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy'],
282 FETCH_LIT_FORMS : ['open-ils.search','open-ils.search.biblio.lit_form_map.retrieve.all'],
283 FETCH_ITEM_FORMS : ['open-ils.search','open-ils.search.biblio.item_form_map.retrieve.all'],
284 FETCH_ITEM_TYPES : ['open-ils.search','open-ils.search.biblio.item_type_map.retrieve.all'],
285 FETCH_AUDIENCES : ['open-ils.search','open-ils.search.biblio.audience_map.retrieve.all'],
286 FETCH_HOLD_STATUS : ['open-ils.circ','open-ils.circ.hold.status.retrieve'],
287 FETCH_NON_CAT_CIRCS : ['open-ils.circ','open-ils.circ.open_non_cataloged_circulation.user'],
288 FETCH_NON_CAT_CIRC : ['open-ils.circ','open-ils.circ.non_cataloged_circulation.retrieve'],
289 FETCH_NON_CAT_TYPES : ['open-ils.circ','open-ils.circ.non_cat_types.retrieve.all'],
290 FETCH_BRE : ['open-ils.search','open-ils.search.biblio.record_entry.slim.retrieve'],
291 CHECK_USERNAME : ['open-ils.actor','open-ils.actor.username.exists'],
292 FETCH_CIRC_BY_ID : ['open-ils.circ','open-ils.circ.retrieve'],
293 FETCH_MR_DESCRIPTORS : ['open-ils.search','open-ils.search.metabib.record_to_descriptors'],
294 FETCH_HIGHEST_PERM_ORG : ['open-ils.actor','open-ils.actor.user.perm.highest_org.batch'],
295 FETCH_USER_NOTES : ['open-ils.actor','open-ils.actor.note.retrieve.all'],
296 FETCH_ORG_BY_SHORTNAME : ['open-ils.actor','open-ils.actor.org_unit.retrieve_by_shorname'],
297 FETCH_BIB_ID_BY_BARCODE : ['open-ils.search','open-ils.search.bib_id.by_barcode'],
298 FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default']