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