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(dojo.isArray(thing)) {
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 RequiredField : function (f) {
76 if (fieldmapper.IDL && fieldmapper.IDL.loaded)
77 return this.Structure.fields[f].required;
81 ValidateField : function (f) {
83 if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
84 if (this.Structure.fields[f] && this.Structure.fields[f].validate) {
85 return this.Structure.fields[f].validate.test(this[f]());
95 isnew : function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; },
96 ischanged : function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; },
97 isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
102 fieldmapper.vivicateClass = function (cl) {
104 dojo.declare( cl , fieldmapper.Fieldmapper, {
105 constructor : function () {
106 if (!this.a) this.a = [];
107 this.classname = this.declaredClass;
110 if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
111 this.Structure = fieldmapper.IDL.fmclasses[this.classname]
113 for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
114 var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
115 var p = field.array_position;
116 this._fields.push( field.name );
117 this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
120 this._fields = fmclasses[this.classname];
122 for( var pos = 0; pos < this._fields.length; pos++ ) {
123 var p = parseInt(pos);
124 var f = this._fields[pos];
125 this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
131 fieldmapper[cl] = window[cl]; // alias into place
132 if (fieldmapper.IDL && fieldmapper.IDL.loaded) fieldmapper[cl].Identifier = fieldmapper.IDL.fmclasses[cl].pkey;
134 if (dojo._hasResource['fieldmapper.dojoData'] && dojo.filter(['aou','aout','pgt'], function(x){return x == cl}).length == 0) {
135 fieldmapper[cl].prototype.fromStoreItem = _fromStoreItem;
136 fieldmapper[cl].toStoreData = _toStoreData;
137 fieldmapper[cl].toStoreItem = _toStoreItem;
138 fieldmapper[cl].prototype.toStoreItem = function ( args ) { return _toStoreItem(this, args) };
139 fieldmapper[cl].initStoreData = _initStoreData;
140 fieldmapper[cl].prototype.toHash = _toHash;
141 fieldmapper[cl].toHash = _toHash;
146 if (!window.fmclasses) dojo.require("fieldmapper.fmall", true);
147 for( var cl in fmclasses ) {
148 fieldmapper.vivicateClass(cl);
151 // if we were NOT called by the IDL loader ...
152 // XXX This is now deprecated in preference to fieldmapper.AutoIDL
153 if ( !(fieldmapper.IDL && fieldmapper.IDL.loaded) ) {
155 fieldmapper.cmsa.Identifier = 'alias';
156 fieldmapper.cmc.Identifier = 'name';
157 fieldmapper.i18n_l.Identifier = 'code';
158 fieldmapper.ccpbt.Identifier = 'code';
159 fieldmapper.ccnbt.Identifier = 'code';
160 fieldmapper.cbrebt.Identifier = 'code';
161 fieldmapper.cubt.Identifier = 'code';
162 fieldmapper.ccm.Identifier = 'code';
163 fieldmapper.cvrfm.Identifier = 'code';
164 fieldmapper.clm.Identifier = 'code';
165 fieldmapper.cam.Identifier = 'code';
166 fieldmapper.cifm.Identifier = 'code';
167 fieldmapper.citm.Identifier = 'code';
168 fieldmapper.cblvl.Identifier = 'code';
169 fieldmapper.clfm.Identifier = 'code';
170 fieldmapper.mous.Identifier = 'usr';
171 fieldmapper.moucs.Identifier = 'usr';
172 fieldmapper.mucs.Identifier = 'usr';
173 fieldmapper.mus.Identifier = 'usr';
174 fieldmapper.rxbt.Identifier = 'xact';
175 fieldmapper.rxpt.Identifier = 'xact';
176 fieldmapper.cxt.Identifier = 'name';
177 fieldmapper.amtr.Identifier = 'matchpoint';
178 fieldmapper.coust.Identifier = 'name';
182 fieldmapper._request = function ( meth, staff, params ) {
183 var ses = OpenSRF.CachedClientSession( meth[0] );
184 if (!ses) return null;
189 if (dojo.isArray(params)) {
190 args.params = params;
193 if (dojo.isObject(params)) {
196 args.params = [].splice.call(arguments, 2, arguments.length - 2);
201 if (!args.async && !args.timeout) args.timeout = 10;
203 if(!args.onmethoderror) {
204 args.onmethoderror = function(r, stat, stat_text) {
205 throw new Error('Method error: ' + r.stat + ' : ' + stat_text);
209 if(!args.ontransporterror) {
210 args.ontransporterror = function(xreq) {
211 throw new Error('Transport error method='+args.method+', status=' + xreq.status);
216 args.onerror = function (r) {
217 throw new Error('Request error encountered! ' + r);
221 if (!args.oncomplete) {
222 args.oncomplete = function (r) {
224 if (x) result = x.content();
228 args.method = meth[1];
229 if (staff && meth[2]) args.method += '.staff';
231 ses.request(args).send();
236 fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
237 fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
239 fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
240 fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
242 fieldmapper.OpenSRF = {};
244 /* Methods are defined as [ service, method, have_staff ]
245 An optional 3rd component is when a method is followed by true, such methods
246 have a staff counterpart and should have ".staff" appended to the method
247 before the method is called when in XUL mode */
248 fieldmapper.OpenSRF.methods = {
249 SEARCH_MRS : ['open-ils.search','open-ils.search.metabib.multiclass',true],
250 SEARCH_RS : ['open-ils.search','open-ils.search.biblio.multiclass',true],
251 SEARCH_MRS_QUERY : ['open-ils.search','open-ils.search.metabib.multiclass.query',true],
252 SEARCH_RS_QUERY : ['open-ils.search','open-ils.search.biblio.multiclass.query',true],
253 FETCH_SEARCH_RIDS : ['open-ils.search','open-ils.search.biblio.record.class.search',true],
254 FETCH_MRMODS : ['open-ils.search','open-ils.search.biblio.metarecord.mods_slim.retrieve'],
255 FETCH_MODS_FROM_COPY : ['open-ils.search','open-ils.search.biblio.mods_from_copy'],
256 FETCH_MR_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.metarecord.copy_count',true],
257 FETCH_RIDS : ['open-ils.search','open-ils.search.biblio.metarecord_to_records',true],
258 FETCH_RMODS : ['open-ils.search','open-ils.search.biblio.record.mods_slim.retrieve'],
259 FETCH_R_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.record.copy_count',true],
260 FETCH_FLESHED_USER : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve'],
261 FETCH_SESSION : ['open-ils.auth','open-ils.auth.session.retrieve'],
262 LOGIN_INIT : ['open-ils.auth','open-ils.auth.authenticate.init'],
263 LOGIN_COMPLETE : ['open-ils.auth','open-ils.auth.authenticate.complete'],
264 LOGIN_DELETE : ['open-ils.auth','open-ils.auth.session.delete'],
265 FETCH_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.retrieve'],
266 UPDATE_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.update'],
267 FETCH_COPY_STATUSES : ['open-ils.search','open-ils.search.config.copy_status.retrieve.all'],
268 FETCH_COPY_COUNTS_SUMMARY : ['open-ils.search','open-ils.search.biblio.copy_counts.summary.retrieve'],
269 FETCH_MARC_HTML : ['open-ils.search','open-ils.search.biblio.record.html'],
270 FETCH_CHECKED_OUT_SUM : ['open-ils.actor','open-ils.actor.user.checked_out'],
271 FETCH_HOLDS : ['open-ils.circ','open-ils.circ.holds.retrieve'],
272 FETCH_FINES_SUMMARY : ['open-ils.actor','open-ils.actor.user.fines.summary'],
273 FETCH_TRANSACTIONS : ['open-ils.actor','open-ils.actor.user.transactions.have_charge.fleshed'],
274 FETCH_MONEY_BILLING : ['open-ils.circ','open-ils.circ.money.billing.retrieve.all'],
275 FETCH_CROSSREF : ['open-ils.search','open-ils.search.authority.crossref'],
276 FETCH_CROSSREF_BATCH : ['open-ils.search','open-ils.search.authority.crossref.batch'],
277 CREATE_HOLD : ['open-ils.circ','open-ils.circ.holds.create'],
278 CREATE_HOLD_OVERRIDE : ['open-ils.circ','open-ils.circ.holds.create.override'],
279 CANCEL_HOLD : ['open-ils.circ','open-ils.circ.hold.cancel'],
280 UPDATE_USERNAME : ['open-ils.actor','open-ils.actor.user.username.update'],
281 UPDATE_PASSWORD : ['open-ils.actor','open-ils.actor.user.password.update'],
282 UPDATE_EMAIL : ['open-ils.actor','open-ils.actor.user.email.update'],
283 RENEW_CIRC : ['open-ils.circ','open-ils.circ.renew'],
284 CHECK_SPELL : ['open-ils.search','open-ils.search.spellcheck'],
285 FETCH_REVIEWS : ['open-ils.search','open-ils.search.added_content.review.retrieve.all'],
286 FETCH_TOC : ['open-ils.search','open-ils.search.added_content.toc.retrieve'],
287 FETCH_ACONT_SUMMARY : ['open-ils.search','open-ils.search.added_content.summary.retrieve'],
288 FETCH_USER_BYBARCODE : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve_by_barcode'],
289 FETCH_ADV_MARC_MRIDS : ['open-ils.search','open-ils.search.biblio.marc',true],
290 FETCH_ADV_ISBN_RIDS : ['open-ils.search','open-ils.search.biblio.isbn'],
291 FETCH_ADV_ISSN_RIDS : ['open-ils.search','open-ils.search.biblio.issn'],
292 FETCH_ADV_TCN_RIDS : ['open-ils.search','open-ils.search.biblio.tcn'],
293 FETCH_CNBROWSE : ['open-ils.search','open-ils.search.callnumber.browse'],
294 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
295 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
296 CREATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.create'],
297 DELETE_CONTAINER : ['open-ils.actor','open-ils.actor.container.full_delete'],
298 CREATE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.create'],
299 DELETE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.delete'],
300 FLESH_CONTAINER : ['open-ils.actor','open-ils.actor.container.flesh'],
301 FLESH_PUBLIC_CONTAINER : ['open-ils.actor','open-ils.actor.container.public.flesh'],
302 UPDATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.update'],
303 FETCH_COPY : ['open-ils.search','open-ils.search.asset.copy.retrieve'],
304 FETCH_FLESHED_COPY : ['open-ils.search','open-ils.search.asset.copy.fleshed2.retrieve'],
305 CHECK_HOLD_POSSIBLE : ['open-ils.circ','open-ils.circ.title_hold.is_possible'],
306 UPDATE_HOLD : ['open-ils.circ','open-ils.circ.hold.update'],
307 FETCH_COPIES_FROM_VOLUME : ['open-ils.search','open-ils.search.asset.copy.retrieve_by_cn_label',true],
308 FETCH_VOLUME_BY_INFO : ['open-ils.search','open-ils.search.call_number.retrieve_by_info'], /* XXX staff method? */
309 FETCH_VOLUME : ['open-ils.search','open-ils.search.asset.call_number.retrieve'],
310 FETCH_COPY_LOCATIONS : ['open-ils.circ','open-ils.circ.copy_location.retrieve.all'],
311 FETCH_COPY_NOTES : ['open-ils.circ','open-ils.circ.copy_note.retrieve.all'],
312 FETCH_COPY_STAT_CATS : ['open-ils.circ','open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy'],
313 FETCH_LIT_FORMS : ['open-ils.search','open-ils.search.biblio.lit_form_map.retrieve.all'],
314 FETCH_ITEM_FORMS : ['open-ils.search','open-ils.search.biblio.item_form_map.retrieve.all'],
315 FETCH_ITEM_TYPES : ['open-ils.search','open-ils.search.biblio.item_type_map.retrieve.all'],
316 FETCH_AUDIENCES : ['open-ils.search','open-ils.search.biblio.audience_map.retrieve.all'],
317 FETCH_HOLD_STATUS : ['open-ils.circ','open-ils.circ.hold.status.retrieve'],
318 FETCH_NON_CAT_CIRCS : ['open-ils.circ','open-ils.circ.open_non_cataloged_circulation.user'],
319 FETCH_NON_CAT_CIRC : ['open-ils.circ','open-ils.circ.non_cataloged_circulation.retrieve'],
320 FETCH_NON_CAT_TYPES : ['open-ils.circ','open-ils.circ.non_cat_types.retrieve.all'],
321 FETCH_BRE : ['open-ils.search','open-ils.search.biblio.record_entry.slim.retrieve'],
322 CHECK_USERNAME : ['open-ils.actor','open-ils.actor.username.exists'],
323 FETCH_CIRC_BY_ID : ['open-ils.circ','open-ils.circ.retrieve'],
324 FETCH_MR_DESCRIPTORS : ['open-ils.search','open-ils.search.metabib.record_to_descriptors'],
325 FETCH_HIGHEST_PERM_ORG : ['open-ils.actor','open-ils.actor.user.perm.highest_org.batch'],
326 FETCH_USER_NOTES : ['open-ils.actor','open-ils.actor.note.retrieve.all'],
327 FETCH_ORG_BY_SHORTNAME : ['open-ils.actor','open-ils.actor.org_unit.retrieve_by_shortname'],
328 FETCH_BIB_ID_BY_BARCODE : ['open-ils.search','open-ils.search.bib_id.by_barcode'],
329 FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default'],
330 FETCH_ORG_SETTING_BATCH : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default.batch']