]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/fieldmapper/Fieldmapper.js
the change from 'for (var foo in bar)' to 'for (var foo = 0; foo < bar.length; foo...
[working/Evergreen.git] / Open-ILS / web / js / dojo / fieldmapper / Fieldmapper.js
1 /*
2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008  Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
5
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.
10
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 # ---------------------------------------------------------------------------
16 */
17
18 if(!dojo._hasResource["fieldmapper.Fieldmapper"]){
19
20 /* generate fieldmapper javascript classes.  This expects a global variable
21         called 'fmclasses' to be fleshed with the classes we need to build */
22
23         function FMEX(message) { this.message = message; }
24         FMEX.toString = function() { return "FieldmapperException: " + this.message + "\n"; }
25
26
27         dojo._hasResource["fieldmapper.Fieldmapper"] = true;
28         dojo.provide("fieldmapper.Fieldmapper");
29         dojo.require("DojoSRF");
30
31         dojo.declare( "fieldmapper.Fieldmapper", null, {
32
33                 constructor : function (initArray) {
34                         if (initArray) {
35                                 if (dojo.isArray(initArray)) {
36                                         this.a = initArray;
37                                 } else {
38                                         this.a = [];
39                                 }
40                         }
41                 },
42
43                 _isfieldmapper : true,
44
45                 clone : function() {
46                         var obj = new this.constructor();
47
48                         for( var i in this.a ) {
49                                 var thing = this.a[i];
50                                 if(thing == null) continue;
51
52                                 if( thing._isfieldmapper ) {
53                                         obj.a[i] = thing.clone();
54                                 } else {
55
56                                         if(instanceOf(thing, Array)) {
57                                                 obj.a[i] = new Array();
58
59                                                 for( var j in thing ) {
60
61                                                         if( thing[j]._isfieldmapper )
62                                                                 obj.a[i][j] = thing[j].clone();
63                                                         else
64                                                                 obj.a[i][j] = thing[j];
65                                                 }
66                                         } else {
67                                                 obj.a[i] = thing;
68                                         }
69                                 }
70                         }
71                         return obj;
72                 }
73
74  
75 /*
76                 isnew : function(n) { if(arguments.length == 1) this.a[0] =n; return this.a[0]; },
77                 ischanged : function(n) { if(arguments.length == 1) this.a[1] =n; return this.a[1]; },
78                 isdeleted : function(n) { if(arguments.length == 1) this.a[2] =n; return this.a[2]; }
79 */
80
81         });
82
83     fieldmapper.vivicateClass = function (cl) {
84                 dojo.provide( cl );
85                 dojo.declare( cl , fieldmapper.Fieldmapper, {
86                         constructor : function () {
87                                 if (!this.a) this.a = [];
88                                 this.classname = this.declaredClass;
89                 this._fields = [];
90
91                 if (fieldmapper.IDL && fieldmapper.IDL.loaded) {
92                     this.Structure = fieldmapper.IDL.fmclasses[this.classname]
93
94                     for (var f in fieldmapper.IDL.fmclasses[this.classname].fields) {
95                         var field = fieldmapper.IDL.fmclasses[this.classname].fields[f];
96                         var p = field.array_position;
97                                 this._fields.push( field.name );
98                                         this[field.name]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
99                     }
100                 } else {
101                                     this._fields = fmclasses[this.classname];
102
103                                 for( var pos = 0; pos <  this._fields.length; pos++ ) {
104                                         var p = parseInt(pos);
105                                         var f = this._fields[pos];
106                                         this[f]=new Function('n', 'if(arguments.length==1)this.a['+p+']=n;return this.a['+p+'];');
107                                 }
108                 }
109
110                         }
111                 });
112                 fieldmapper[cl] = window[cl]; // alias into place
113         if (fieldmapper.IDL && fieldmapper.IDL.loaded) fieldmapper[cl].Identifier = fieldmapper.IDL.fmclasses[cl].pkey;
114     };
115
116     if (!window.fmclasses) dojo.require("fieldmapper.fmall", true);
117     for( var cl in fmclasses ) {
118         fieldmapper.vivicateClass(cl);
119     }
120
121     // if we were NOT called by the IDL loader ...
122     // XXX This is now deprecated in preference to fieldmapper.AutoIDL
123     if ( !(fieldmapper.IDL && fieldmapper.IDL.loaded) ) {
124
125         fieldmapper.i18n_l.Identifier = 'code';
126         fieldmapper.ccpbt.Identifier = 'code';
127         fieldmapper.ccnbt.Identifier = 'code';
128         fieldmapper.cbrebt.Identifier = 'code';
129         fieldmapper.cubt.Identifier = 'code';
130         fieldmapper.ccm.Identifier = 'code';
131         fieldmapper.cvrfm.Identifier = 'code';
132         fieldmapper.clm.Identifier = 'code';
133         fieldmapper.cam.Identifier = 'code';
134         fieldmapper.cifm.Identifier = 'code';
135         fieldmapper.citm.Identifier = 'code';
136         fieldmapper.cblvl.Identifier = 'code';
137         fieldmapper.clfm.Identifier = 'code';
138         fieldmapper.mous.Identifier = 'usr';
139         fieldmapper.moucs.Identifier = 'usr';
140         fieldmapper.mucs.Identifier = 'usr';
141         fieldmapper.mus.Identifier = 'usr';
142         fieldmapper.rxbt.Identifier = 'xact';
143         fieldmapper.rxpt.Identifier = 'xact';
144         fieldmapper.cxt.Identifier = 'name';
145         fieldmapper.amtr.Identifier = 'matchpoint';
146         fieldmapper.coust.Identifier = 'name';
147
148     }
149
150         fieldmapper._request = function ( meth, staff, params ) {
151                 var ses = OpenSRF.CachedClientSession( meth[0] );
152                 if (!ses) return null;
153
154                 var result = null;
155                 var args = {};
156
157                 if (dojo.isArray(params)) {
158                         args.params = params;
159                 } else {
160
161                         if (dojo.isObject(params)) {
162                                 args = params;
163                         } else {
164                 args.params = [].splice.call(arguments, 1, arguments.length - 1);
165                         }
166
167                 }
168
169         if (!args.async && !args.timeout) args.timeout = 10;
170
171         if(!args.onmethoderror) {
172             args.onmethoderror = function(r, stat, stat_text) {
173                 throw new Error('Method error: ' + r.stat + ' : ' + stat_text);
174             }
175         }
176
177         if(!args.ontransporterror) {
178             args.ontransporterror = function(xreq) {
179                 throw new Error('Transport error method='+args.method+', status=' + xreq.status);
180             }
181         }
182
183                 if (!args.onerror) {
184                         args.onerror = function (r) {
185                                 throw new Error('Request error encountered! ' + r);
186                         }
187                 }
188
189                 if (!args.oncomplete) {
190                         args.oncomplete = function (r) {
191                                 var x = r.recv();
192                                 if (x) result = x.content();
193                         }
194                 }
195
196                 args.method = meth[1];
197                 if (staff && meth[2]) args.method += '.staff';
198
199                 ses.request(args).send();
200
201                 return result;
202         };
203
204         fieldmapper.standardRequest = function (meth, params) { return fieldmapper._request(meth, false, params) };
205         fieldmapper.Fieldmapper.prototype.standardRequest = fieldmapper.standardRequest;
206
207         fieldmapper.staffRequest = function (meth, params) { return fieldmapper._request(meth, true, params) };
208         fieldmapper.Fieldmapper.prototype.staffRequest = fieldmapper.staffRequest;
209
210         fieldmapper.OpenSRF = {};
211
212         /*      Methods are defined as [ service, method, have_staff ]
213                 An optional 3rd component is when a method is followed by true, such methods
214                 have a staff counterpart and should have ".staff" appended to the method 
215                 before the method is called when in XUL mode */
216         fieldmapper.OpenSRF.methods = {
217                 SEARCH_MRS : ['open-ils.search','open-ils.search.metabib.multiclass',true],
218                 SEARCH_RS : ['open-ils.search','open-ils.search.biblio.multiclass',true],
219                 SEARCH_MRS_QUERY : ['open-ils.search','open-ils.search.metabib.multiclass.query',true],
220                 SEARCH_RS_QUERY : ['open-ils.search','open-ils.search.biblio.multiclass.query',true],
221                 FETCH_SEARCH_RIDS : ['open-ils.search','open-ils.search.biblio.record.class.search',true],
222                 FETCH_MRMODS : ['open-ils.search','open-ils.search.biblio.metarecord.mods_slim.retrieve'],
223                 FETCH_MODS_FROM_COPY : ['open-ils.search','open-ils.search.biblio.mods_from_copy'],
224                 FETCH_MR_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.metarecord.copy_count',true],
225                 FETCH_RIDS : ['open-ils.search','open-ils.search.biblio.metarecord_to_records',true],
226                 FETCH_RMODS : ['open-ils.search','open-ils.search.biblio.record.mods_slim.retrieve'],
227                 FETCH_R_COPY_COUNTS : ['open-ils.search','open-ils.search.biblio.record.copy_count',true],
228                 FETCH_FLESHED_USER : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve'],
229                 FETCH_SESSION : ['open-ils.auth','open-ils.auth.session.retrieve'],
230                 LOGIN_INIT : ['open-ils.auth','open-ils.auth.authenticate.init'],
231                 LOGIN_COMPLETE : ['open-ils.auth','open-ils.auth.authenticate.complete'],
232                 LOGIN_DELETE : ['open-ils.auth','open-ils.auth.session.delete'],
233                 FETCH_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.retrieve'], 
234                 UPDATE_USER_PREFS : ['open-ils.actor','open-ils.actor.patron.settings.update'], 
235                 FETCH_COPY_STATUSES : ['open-ils.search','open-ils.search.config.copy_status.retrieve.all'],
236                 FETCH_COPY_COUNTS_SUMMARY : ['open-ils.search','open-ils.search.biblio.copy_counts.summary.retrieve'],
237                 FETCH_MARC_HTML : ['open-ils.search','open-ils.search.biblio.record.html'],
238                 FETCH_CHECKED_OUT_SUM : ['open-ils.actor','open-ils.actor.user.checked_out'],
239                 FETCH_HOLDS : ['open-ils.circ','open-ils.circ.holds.retrieve'],
240                 FETCH_FINES_SUMMARY : ['open-ils.actor','open-ils.actor.user.fines.summary'],
241                 FETCH_TRANSACTIONS : ['open-ils.actor','open-ils.actor.user.transactions.have_charge.fleshed'],
242                 FETCH_MONEY_BILLING : ['open-ils.circ','open-ils.circ.money.billing.retrieve.all'],
243                 FETCH_CROSSREF : ['open-ils.search','open-ils.search.authority.crossref'],
244                 FETCH_CROSSREF_BATCH : ['open-ils.search','open-ils.search.authority.crossref.batch'],
245                 CREATE_HOLD : ['open-ils.circ','open-ils.circ.holds.create'],
246                 CREATE_HOLD_OVERRIDE : ['open-ils.circ','open-ils.circ.holds.create.override'],
247                 CANCEL_HOLD : ['open-ils.circ','open-ils.circ.hold.cancel'],
248                 UPDATE_USERNAME : ['open-ils.actor','open-ils.actor.user.username.update'],
249                 UPDATE_PASSWORD : ['open-ils.actor','open-ils.actor.user.password.update'],
250                 UPDATE_EMAIL : ['open-ils.actor','open-ils.actor.user.email.update'],
251                 RENEW_CIRC : ['open-ils.circ','open-ils.circ.renew'],
252                 CHECK_SPELL : ['open-ils.search','open-ils.search.spellcheck'],
253                 FETCH_REVIEWS : ['open-ils.search','open-ils.search.added_content.review.retrieve.all'],
254                 FETCH_TOC : ['open-ils.search','open-ils.search.added_content.toc.retrieve'],
255                 FETCH_ACONT_SUMMARY : ['open-ils.search','open-ils.search.added_content.summary.retrieve'],
256                 FETCH_USER_BYBARCODE : ['open-ils.actor','open-ils.actor.user.fleshed.retrieve_by_barcode'],
257                 FETCH_ADV_MARC_MRIDS : ['open-ils.search','open-ils.search.biblio.marc',true],
258                 FETCH_ADV_ISBN_RIDS : ['open-ils.search','open-ils.search.biblio.isbn'],
259                 FETCH_ADV_ISSN_RIDS : ['open-ils.search','open-ils.search.biblio.issn'],
260                 FETCH_ADV_TCN_RIDS : ['open-ils.search','open-ils.search.biblio.tcn'],
261                 FETCH_CNBROWSE : ['open-ils.search','open-ils.search.callnumber.browse'],
262                 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
263                 FETCH_CONTAINERS : ['open-ils.actor','open-ils.actor.container.retrieve_by_class'],
264                 CREATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.create'],
265                 DELETE_CONTAINER : ['open-ils.actor','open-ils.actor.container.full_delete'],
266                 CREATE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.create'],
267                 DELETE_CONTAINER_ITEM : ['open-ils.actor','open-ils.actor.container.item.delete'],
268                 FLESH_CONTAINER : ['open-ils.actor','open-ils.actor.container.flesh'],
269                 FLESH_PUBLIC_CONTAINER : ['open-ils.actor','open-ils.actor.container.public.flesh'],
270                 UPDATE_CONTAINER : ['open-ils.actor','open-ils.actor.container.update'],
271                 FETCH_COPY : ['open-ils.search','open-ils.search.asset.copy.retrieve'],
272                 FETCH_FLESHED_COPY : ['open-ils.search','open-ils.search.asset.copy.fleshed2.retrieve'],
273                 CHECK_HOLD_POSSIBLE : ['open-ils.circ','open-ils.circ.title_hold.is_possible'],
274                 UPDATE_HOLD : ['open-ils.circ','open-ils.circ.hold.update'],
275                 FETCH_COPIES_FROM_VOLUME : ['open-ils.search','open-ils.search.asset.copy.retrieve_by_cn_label',true],
276                 FETCH_VOLUME_BY_INFO : ['open-ils.search','open-ils.search.call_number.retrieve_by_info'], /* XXX staff method? */
277                 FETCH_VOLUME : ['open-ils.search','open-ils.search.asset.call_number.retrieve'],
278                 FETCH_COPY_LOCATIONS : ['open-ils.circ','open-ils.circ.copy_location.retrieve.all'],
279                 FETCH_COPY_NOTES : ['open-ils.circ','open-ils.circ.copy_note.retrieve.all'],
280                 FETCH_COPY_STAT_CATS : ['open-ils.circ','open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy'],
281                 FETCH_LIT_FORMS : ['open-ils.search','open-ils.search.biblio.lit_form_map.retrieve.all'],
282                 FETCH_ITEM_FORMS : ['open-ils.search','open-ils.search.biblio.item_form_map.retrieve.all'],
283                 FETCH_ITEM_TYPES : ['open-ils.search','open-ils.search.biblio.item_type_map.retrieve.all'],
284                 FETCH_AUDIENCES : ['open-ils.search','open-ils.search.biblio.audience_map.retrieve.all'],
285                 FETCH_HOLD_STATUS : ['open-ils.circ','open-ils.circ.hold.status.retrieve'],
286                 FETCH_NON_CAT_CIRCS : ['open-ils.circ','open-ils.circ.open_non_cataloged_circulation.user'],
287                 FETCH_NON_CAT_CIRC : ['open-ils.circ','open-ils.circ.non_cataloged_circulation.retrieve'],
288                 FETCH_NON_CAT_TYPES : ['open-ils.circ','open-ils.circ.non_cat_types.retrieve.all'],
289                 FETCH_BRE : ['open-ils.search','open-ils.search.biblio.record_entry.slim.retrieve'],
290                 CHECK_USERNAME : ['open-ils.actor','open-ils.actor.username.exists'],
291                 FETCH_CIRC_BY_ID : ['open-ils.circ','open-ils.circ.retrieve'],
292                 FETCH_MR_DESCRIPTORS : ['open-ils.search','open-ils.search.metabib.record_to_descriptors'],
293                 FETCH_HIGHEST_PERM_ORG : ['open-ils.actor','open-ils.actor.user.perm.highest_org.batch'],
294                 FETCH_USER_NOTES : ['open-ils.actor','open-ils.actor.note.retrieve.all'],
295                 FETCH_ORG_BY_SHORTNAME : ['open-ils.actor','open-ils.actor.org_unit.retrieve_by_shorname'],
296                 FETCH_BIB_ID_BY_BARCODE : ['open-ils.search','open-ils.search.bib_id.by_barcode'],
297                 FETCH_ORG_SETTING : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default'],
298                 FETCH_ORG_SETTING_BATCH : ['open-ils.actor','open-ils.actor.ou_setting.ancestor_default.batch']
299         };
300
301 }
302
303
304