]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/ue.js
793f5be0b6954040c14c734dcf39ad7100429c14
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / ue.js
1 var cgi                            = null;
2 var clone                        = false;
3 var patron                        = null;
4 var counter                        = 0;
5 var identTypesCache            = {};
6 var statCatsCache                = {};
7 var surveysCache                = {};
8 var surveyQuestionsCache    = {};
9 var surveyAnswersCache        = {};
10 var userCache                    = {};
11 var groupsCache                = {};
12 var netLevelsCache            = {};
13 var orgSettings             = [];
14 //var guardianNote                = null;
15 var uEditUsePhonePw = false;
16
17 if(!window.xulG) var xulG = null;
18
19 function $(id) { return document.getElementById(id); }
20
21 /* fetch the necessary data to start off */
22 function uEditInit() {
23
24     _debug('uEditInit(): ' + location.search);
25
26     cgi        = new CGI();
27     session    = cgi.param('ses'); 
28     if (xulG) if (xulG.ses) session = xulG.ses;
29     if (xulG) if (xulG.params) if (xulG.params.ses) session = xulG.params.ses;
30     clone        = cgi.param('clone'); 
31     if (xulG) if (xulG.clone) clone = xulG.clone;
32     if (xulG) if (xulG.params) if (xulG.params.clone) clone = xulG.params.clone;
33     if(!session) throw $("patronStrings").getString('web.staff.patron.ue.session_no_defined');
34
35     fetchUser(session);
36     $('uedit_user').appendChild(text(USER.usrname()));
37
38     setTimeout( function() { 
39         uEditBuild(); uEditShowPage('uedit_userid'); }, 20 );
40 }
41
42 function uEditSetUnload() {
43    _debug('setting window unload event');
44    /*
45    window.onbeforeunload = function(evt) { 
46       return $('ue_unsaved_changes').innerHTML; 
47    };
48    */
49 }
50
51 function uEditClearUnload() {
52    _debug('clearing window unload event');
53    /*
54    window.onbeforeunload = null;
55    */
56 }
57
58 /* ------------------------------------------------------------------------------ */
59 /* Fetch code
60 /* ------------------------------------------------------------------------------ */
61 function uEditFetchIdentTypes() {
62     _debug("uEditFetchIdentTypes()");
63     var s = fetchXULStash(); 
64     if (typeof s.list != 'undefined') 
65         if (typeof s.list.cit != 'undefined') return s.list.cit;
66     var req = new Request(FETCH_ID_TYPES);
67     req.send(true);
68     return req.result();
69 }
70
71 function uEditFetchStatCats() {
72     _debug("uEditFetchStatCats()");
73     var s = fetchXULStash(); 
74     if (typeof s.list != 'undefined') 
75         if (typeof s.list.my_actsc != 'undefined') return s.list.my_actsc;
76     var req = new Request(SC_FETCH_ALL, SESSION);
77     req.send(true);
78     return req.result();
79 }
80
81 function uEditFetchSurveys() {
82     _debug("uEditFetchSurveys()");
83     var s = fetchXULStash(); 
84     if (typeof s.list != 'undefined') 
85         if (typeof s.list.asv != 'undefined') return s.list.asv;
86     var req = new Request(SV_FETCH_ALL, SESSION);
87     req.send(true);
88     return req.result();
89 }
90
91 function uEditFetchGroups() {
92     _debug("uEditFetchGroups()");
93     var s = fetchXULStash(); 
94     if (typeof s.tree != 'undefined') 
95         if (typeof s.tree.pgt != 'undefined') return s.tree.pgt;
96     var req = new Request(FETCH_GROUPS);
97     req.send(true);
98     return req.result();
99 }
100
101 function uEditFetchNetLevels() {
102     _debug("uEditFetchNetLevels()");
103     var s = fetchXULStash(); 
104     if (typeof s.list != 'undefined') 
105         if (typeof s.list.cnal != 'undefined') return s.list.cnal;
106     var req = new Request(FETCH_NET_LEVELS, SESSION);
107     req.send(true);
108     return req.result();
109 }
110
111 /* ------------------------------------------------------------------------------ */
112
113
114 /*  
115  * adds all of the group.application_perm's to the list 
116  * provided by descending through the group tree 
117  */
118 function buildAppPermList(list, group) {
119     if(!group) return;
120     if(group.application_perm() ) 
121         list.push(group.application_perm());
122     for(i in group.children()) {
123         buildAppPermList(list, group.children()[i]);
124     }
125 }
126
127 /* fetches necessary objects and builds the UI */
128 function uEditBuild() {
129
130     myPerms = ['BAR_PATRON', 'UNBAR_PATRON'];
131
132     /*  grab the groups before we check perms so we know what
133         application_perms to check */
134     var groups = uEditFetchGroups();
135     buildAppPermList(myPerms, groups);
136
137     // de-dupe the permission list
138     var perms = [];
139     for(var p in myPerms) 
140         if(perms.indexOf(myPerms[p]) == -1)
141            perms.push(myPerms[p]);
142     myPerms = perms;
143         
144     fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
145
146     uEditBuildLibSelector();
147     var usr = cgi.param('usr'); 
148     if (xulG) if (xulG.usr) usr = xulG.usr;
149     if (xulG) if (xulG.params) if (xulG.params.usr) usr = xulG.params.usr;
150
151     orgSettings = fetchBatchOrgSetting(USER.ws_ou(), [
152         'global.juvenile_age_threshold',
153         'patron.password.use_phone'
154     ]);
155
156     uEditUsePhonePw = (orgSettings['patron.password.use_phone'] && 
157         orgSettings['patron.password.use_phone'].value);
158
159     patron = fetchFleshedUser(usr);
160     if(!patron) patron = uEditNewPatron(); 
161     
162     uEditDraw( 
163         uEditFetchIdentTypes(),
164         groups,
165         uEditFetchStatCats(),
166         uEditFetchSurveys(),
167         uEditFetchNetLevels()
168         );
169
170     if(patron.isnew()) {
171         if(clone) uEditClone(clone);
172         else uEditCreateNewAddr();
173
174     } else {
175
176         /* do we need to display the parent / gurdian field? */
177         uEditCheckDOB(uEditFindFieldByKey('dob'));
178
179         $('ue_barcode').disabled = true;
180         unHideMe($('ue_mark_card_lost'));
181         unHideMe($('ue_reset_pw'));
182         uEditCheckEditPerm();
183     }
184
185     uEditCheckBarredPerm();
186 }
187
188 function uEditCheckBarredPerm() {
189     if(PERMS['BAR_PATRON'] != -1) 
190         return;
191
192     if(isTrue(patron.barred()) && PERMS['UNBAR_PATRON'] != -1) 
193         return;
194
195     $('ue_barred').disabled = true;
196 }
197
198
199 /* if this user does not have permission to put users into
200     the edited users group, they do not have permission to 
201     edit this user */
202 function uEditCheckEditPerm() {
203
204     var perm = uEditFindGroupPerm(groupsCache[patron.profile()]);    
205     /*
206     _debug("editing user with group app perm "+patron.profile()+' : '+
207         groupsCache[patron.profile()].name() +', and perm = ' + perm);
208         */
209
210     if(PERMS[perm] != -1) return;
211
212     /* we can edit our own account, but not others in our group */
213     if( patron.id() != USER.id() ){
214         _debug("we are not allowed to edit this user");
215     
216         $('ue_save').disabled = true;
217         $('ue_save_clone').disabled = true;
218         $('ue_mark_card_lost').disabled = true;
219         $('ue_reset_pw').disabled = true;
220     
221         uEditIterateFields(
222             function(f) {
223                 if( f && f.widget && f.widget.node )
224                     f.widget.node.disabled = true;
225             }    
226         );    
227
228     }
229
230     var node = $('ue_profile').parentNode;
231     node.removeChild($('ue_profile'));
232     node.appendChild(elem('span',null,groupsCache[patron.profile()].name()));
233
234     var field = uEditFindFieldByKey('profile');
235     field.required = false;
236     removeCSSClass(field.widget.node, CSS_INVALID_DATA);
237     uEditCheckErrors();
238 }
239
240
241 /* creates a new patron object with card attached */
242 var uEditCardVirtId = -1;
243 function uEditNewPatron() {
244     var patron = new au(); 
245     patron.isnew(1);
246     patron.id(-1);
247     card = new ac();
248     card.id(uEditCardVirtId--);
249     card.isnew(1);
250     patron.card(card);
251     patron.cards([card]);
252     patron.net_access_level(defaultNetLevel);
253     patron.stat_cat_entries([]);
254     patron.survey_responses([]);
255     patron.addresses([]);
256     patron.home_ou(USER.ws_ou());
257     uEditMakeRandomPw(patron);
258     return patron;
259 }
260
261 function uEditMakeRandomPw(patron) {
262     if(uEditUsePhonePw) return;
263     var rand  = Math.random();
264     rand = parseInt(rand * 10000) + '';
265     while(rand.length < 4) rand += '0';
266     appendClear($('ue_password_plain'),text(rand));
267     unHideMe($('ue_password_gen'));
268     patron.passwd(rand);
269     return rand;
270 }
271
272 function uEditMakePhonePw() {
273     if(patron.passwd()) return;
274     if( (pw = patron.day_phone()) || 
275         (pw = patron.evening_phone()) || (pw = patron.other_phone()) ) {
276             pw = pw.substring(pw.length - 4); // this is iffy
277             uEditResetPw(pw);
278             appendClear($('ue_password_plain'), text(pw));
279             unHideMe($('ue_password_gen'));
280             patron.passwd(pw);
281     }
282 }
283
284 function uEditResetPw(pw) { 
285     if(!pw) pw = uEditMakeRandomPw(patron);    
286     $('ue_password1').value = pw;
287     $('ue_password2').value = pw;
288     $('ue_password1').onchange();
289 }
290
291 function uEditClone(clone) {
292
293     var cloneUser = fetchFleshedUser(clone);
294     patron.usrgroup(cloneUser.usrgroup());
295
296     if( cloneUser.day_phone() ) {
297         $('ue_day_phone').value = cloneUser.day_phone();
298         $('ue_day_phone').onchange();
299     }
300
301     if( cloneUser.evening_phone() ) {
302         $('ue_night_phone').value = cloneUser.evening_phone();
303         $('ue_night_phone').onchange();
304     }
305
306     if( cloneUser.other_phone() ) {
307         $('ue_other_phone').value = cloneUser.other_phone();
308         $('ue_other_phone').onchange();
309     }
310
311     setSelector($('ue_org_selector'), cloneUser.home_ou());
312     setSelector($('ue_profile'), cloneUser.profile());
313
314     /* force the expire date to be set */
315     $('ue_profile').onchange();
316     $('ue_org_selector').onchange();
317
318     for( var a in cloneUser.addresses() ) {
319         var addr = cloneUser.addresses()[a];
320         if( cloneUser.mailing_address && 
321                 addr.id() == cloneUser.mailing_address().id() )
322             patron.mailing_address(addr);
323         if( cloneUser.billing_address() &&
324                 addr.id() == cloneUser.billing_address().id() )
325             patron.billing_address(addr);
326         patron.addresses().push(addr);
327     }
328
329     uEditBuildAddrs(patron);
330 }
331
332
333 /* Creates a new blank address, 
334     adds it to the user and the fields array */
335 var uEditVirtualAddrId = -1;
336 function uEditCreateNewAddr() {
337     var addr = new aua();
338
339     addr.id(uEditVirtualAddrId--);
340     addr.isnew(1);
341     addr.usr(patron.id());
342     addr.country(defaultCountry);
343
344     if(!patron.addresses()) 
345         patron.addresses([]);
346
347     if(patron.addresses().length == 0) {
348         patron.mailing_address(addr);
349         patron.billing_address(addr);
350     }
351
352     addr.valid(1);
353     addr.within_city_limits(1);
354
355     uEditBuildAddrFields(patron, addr);
356     patron.addresses().push(addr);
357     uEditIterateFields(function(f) { uEditCheckValid(f); });
358     uEditCheckErrors();
359 }
360
361
362 /* kicks off the UI drawing */
363 function uEditDraw(identTypes, groups, statCats, surveys, netLevels ) {
364     hideMe($('uedit_loading'));
365     unHideMe($('ue_maintd'));
366
367     dataFields = [];
368     uEditDrawIDTypes(identTypes);
369     uEditDrawGroups(groups, null, null, true);
370     uEditDrawStatCats(statCats);
371     uEditDrawSurveys(surveys);
372     uEditDrawNetLevels(netLevels);
373     uEditDefineData(patron);
374
375     uEditIterateFields(function(f) { uEditActivateField(f) });
376     uEditIterateFields(function(f) { uEditCheckValid(f); });
377     uEditCheckErrors();
378 }
379
380
381 /** Applies the event handlers and sets the data for the field */
382 function uEditActivateField(field) {
383
384     if( field.widget.id ) {
385         field.widget.node = $(field.widget.id);
386
387     } else {
388         field.widget.node = 
389             $n(field.widget.base, field.widget.name);
390     }
391
392     uEditSetOnchange(field);
393
394     if(field.widget.onblur) {
395         field.widget.node.onblur = 
396             function() { field.widget.onblur(field); };
397     }
398
399     field.widget.node.disabled = field.widget.disabled;
400     if(field.object == null) return;
401     var val = field.object[field.key]();
402     if(val == null) return;
403
404     if( field.widget.type == 'input' )
405         field.widget.node.value = val;
406
407     if( field.widget.type == 'select' )
408         setSelector(field.widget.node, val);
409
410     if( field.widget.type == 'checkbox' )
411         field.widget.node.checked = 
412             (val && val != 'f') ? true : false;
413
414     if( field.widget.onload ) 
415         field.widget.onload(val);
416 }
417
418
419 /* set up the onchange event for the field */
420 function uEditSetOnchange(field) {
421     var func = function() {uEditOnChange( field );}
422     field.widget.node.onchange = func;
423
424     if(field.widget.type != 'select')
425         field.widget.node.onkeyup = func;
426 }
427
428 /* find the current value of the field object's widget */
429 function uEditNodeVal(field) {
430     if(field.widget.type == 'input')
431         return field.widget.node.value;
432
433     if(field.widget.type == 'checkbox')
434         return field.widget.node.checked;
435
436     if(field.widget.type == 'select')
437         return getSelectorVal(field.widget.node);
438 }
439
440
441 /* update a field value */
442 function uEditOnChange(field) {
443
444     var newval = uEditNodeVal(field);
445     field.object[field.key](newval);
446     field.object.ischanged(1);
447
448     if(field.widget.onpostchange)
449         field.widget.onpostchange(field, newval);
450
451     //_debug(field.key+' = '+newval);
452
453     uEditIterateFields(function(f) { uEditCheckValid(f); });
454     uEditCheckErrors();
455
456    uEditSetUnload();
457 }
458
459
460 function uEditCheckValid(field) {
461     var newval = uEditNodeVal(field);
462
463     if(newval) {
464
465         if(field.widget.regex) { 
466             if(newval.match(field.widget.regex)) 
467                 removeCSSClass(field.widget.node, CSS_INVALID_DATA);
468             else
469                 addCSSClass(field.widget.node, CSS_INVALID_DATA);
470
471         } else {
472             removeCSSClass(field.widget.node, CSS_INVALID_DATA);
473         }
474
475     } else {
476
477         if(field.required) {
478             addCSSClass(field.widget.node, CSS_INVALID_DATA);
479
480         } else {
481             removeCSSClass(field.widget.node, CSS_INVALID_DATA);
482         }
483     }
484
485 }
486
487 /* find a field object by object key */
488 function uEditFindFieldByKey(key) {
489     var fields = grep( dataFields,
490         function(item) { return (item.key == key); });
491     return (fields) ? fields[0] : null;
492 }
493
494 /* find a list of fields by object key */
495 function uEditFindFieldsByKey(key) {
496     return grep( dataFields,
497         function(item) { return (item.key == key); });
498 }
499
500 /* find a field object by widget id */
501 function uEditFindFieldByWId(id) {
502     var fields = grep( dataFields,
503         function(item) { return (item.widget.id == id); });
504     return (fields) ? fields[0] : null;
505 }
506
507
508 function uEditIterateFields(callback) {
509     for( var f in dataFields ) 
510         callback(dataFields[f]);
511 }
512
513
514 function uEditGetErrorStrings() {
515     var errors = [];
516     uEditIterateFields(
517         function(field) { 
518             if(field.errkey) {
519                 if( !field.object.isdeleted() ) {
520                     if( field.widget.node.className.indexOf(CSS_INVALID_DATA) != -1) {
521                         var str = $(field.errkey).innerHTML;
522                         if(str) errors.push(str);
523                     }
524                 }
525             }
526         }
527     );
528
529     /* munge up something for all of the required surveys 
530         (which are not registered with the fields) */
531     if( patron.isnew() ) {
532         var sel = $('ue_survey_table');
533
534         if( sel ) {
535             var rows = sel.getElementsByTagName('tr');
536
537             for( var r in rows ) {
538         
539                 var row = rows[r];
540                 var sel = $n(row, 'ue_survey_answer');
541                 if(!sel) continue;
542                 var qstn = row.getAttribute('question');
543         
544                 if(qstn) {
545                     qstn        = surveyQuestionsCache[qstn];
546                     survey    = surveysCache[qstn.survey()];
547                     var val    = getSelectorVal(sel);
548                     if(!val && isTrue(survey.required()))
549                         errors.push($('ue_bad_survey').innerHTML + ' : ' + qstn.question());
550                 }
551             }
552         }
553     }
554
555     /* ------------------------------------------------------------ */
556
557     if(errors[0]) return errors;
558     return null;
559 }
560
561 function uEditAlertErrors() {
562     var errors = uEditGetErrorStrings();
563     if(!errors) return false;
564     alert(errors.join("\n"));
565     return true;
566 }
567
568
569 /* send the user to the database */
570 function uEditSaveUser(cloneme) {
571
572     if(uEditGetErrorStrings()) {
573         uEditAlertErrors();
574         return;
575     }
576
577     /* null is unique in the db, but '' is not */
578     if( ! patron.ident_value() ) patron.ident_value(null);
579     //if( ! patron.ident_type2() ) patron.ident_type2(null);
580     if( ! patron.ident_value2() ) patron.ident_value2(null);
581     patron.ident_type2(null);
582
583     if(! patron.dob() ) patron.dob(null);
584
585     _debug("Saving patron with card: " + js2JSON(patron.card()));
586     _debug("Saving full patron: " + js2JSON(patron));
587
588     //for( var c in patron
589
590     var req = new Request(UPDATE_PATRON, SESSION, patron);
591     req.alertEvent = false;
592     req.send(true);
593     var newuser = req.result();
594
595    uEditClearUnload();
596
597     var evt;
598     if( (evt = checkILSEvent(newuser)) || ! newuser ) {
599         if(evt) {
600             evt = newuser;
601             if( evt.textcode == 'XACT_COLLISION' ) {
602                 if( confirmId('ue_xact_collision') )
603                     location.href = location.href;
604                 return;
605             }
606             var j = js2JSON(evt);
607             alert(j);
608             _debug("USER UPDATE FAILED:\n" + j);
609         }
610         return;
611     } 
612
613     alert($('ue_success').innerHTML);
614
615     if(cloneme) {
616         /* if the user we just created was a clone, and we want to clone it,
617         we really want to clone the original */
618         if( clone ) cloneme = clone;
619         else cloneme = newuser.id();
620     }
621
622
623     if( cloneme ) {
624
625         if(window.xulG &&
626             typeof window.xulG.spawn_editor == 'function' && 
627
628             !patron.isnew() ) {
629                 _debug("xulG clone spawning new interface...");
630                 var ses = cgi.param('ses'); 
631                 if (xulG) if (xulG.ses) ses = xulG.ses;
632                 if (xulG) if (xulG.params) if (xulG.params.ses) ses = xulG.params.ses;
633                 window.xulG.spawn_editor({ses:ses,clone:cloneme});
634                 uEditRefresh();
635
636         } else {
637
638             var href = location.href;
639             href = href.replace(/\&?usr=\d+/, '');
640             href = href.replace(/\&?clone=\d+/, '');
641             href += '&clone=' + cloneme;
642             location.href = href;
643         }
644
645     } else {
646
647         uEditRefresh();
648     }
649
650     uEditRefreshXUL(newuser);
651 }
652
653
654 function uEditRefreshXUL(newuser) {
655     if (window.xulG && typeof window.xulG.on_save == 'function') 
656         window.xulG.on_save(newuser);
657 }
658
659 function uEditRefresh() {
660     var href = location.href;
661     href = href.replace(/\&?clone=\d+/, '');
662     location.href = href;
663 }
664
665
666 function uEditCancel() {
667     var href = location.href;
668     href = href.replace(/\&?usr=\d+/, '');
669     href = href.replace(/\&?clone=\d+/, '');
670     var id = cgi.param('usr'); 
671     if (xulG) if (xulG.usr) id = xulG.usr;
672     if (xulG) if (xulG.params) if (xulG.params.usr) id = xulG.params.usr;
673     /* reload the current user if available */
674     if( id ) href += (href.match(/\?/) ? "&" : "?") + "usr=" + id;
675     location.href = href;
676 }
677
678
679 var uEditDupHashes = {};
680 var uEditDupTemplate;
681
682 function uEditRunDupeSearch(type, search_hash) {
683
684     if(!patron.isnew()) return;
685
686     _debug('dup search: ' + js2JSON(search_hash));
687
688     var req = new Request(PATRON_SEARCH, SESSION, search_hash);
689
690     var container = $('dup_div_container');
691     if(!uEditDupTemplate)
692         uEditDupTemplate = container.removeChild($('dup_div'));
693
694     /* clear any existing dups for this type */
695     iterate( container.getElementsByTagName('div'),
696         function(d) {
697             if( d.getAttribute('type') == type ) {
698                 container.removeChild(d)
699                 return;
700             }
701         }
702     );
703
704     req.callback(
705         function(r) {
706             uEditHandleDupResults( r.getResultObject(), search_hash, type, container );
707         }
708     );
709     req.send();
710 }
711
712
713 function uEditHandleDupResults(ids, search_hash, type, container) {
714
715     _debug('dup search results: ' + js2JSON(ids));
716
717     if(!(ids && ids[0]))  /* no results */
718         return uEditDupHashes[type] = null;
719
720     /* add a dup link to the UI and plug in the data */
721     var node = uEditDupTemplate.cloneNode(true);
722     container.appendChild(node);
723     node.setAttribute('type', type);
724
725     var link = $n(node, 'link');
726     link.setAttribute('type', type);
727     unHideMe(link);
728     $n(node,'count').appendChild(text(ids.length));
729
730     for( var o in search_hash ) 
731         $n(node, 'data').appendChild(
732             text(search_hash[o].value + ' '));
733
734     uEditDupHashes[type] = search_hash;
735
736     switch(type) {
737         case 'ident' :
738             if(confirm($('ue_dup_ident1').innerHTML)) 
739                 uEditShowSearch(null, type);
740             break;
741     }
742 }
743
744
745 function uEditShowSearch(link,type) {
746     if(!type) type = link.getAttribute('type');
747     if(window.xulG)
748         window.xulG.spawn_search(uEditDupHashes[type]);    
749     else alert($("patronStrings").getString('web.staff.patron.ue.uedit_show_search.search_would_be', js2JSON(uEditDupHashes[type])));
750 }
751
752 function uEditMarkCardLost() {
753
754     for( var c in patron.cards() ) {
755
756         var card = patron.cards()[c];
757         if( patron.card().id() == card.id() ) {
758
759             /* de-activite the current card */
760             card.ischanged(1);
761             card.active(0);
762
763             if( !card.barcode() ) {
764                 /* a card exists in the array with no barcode */
765                 ueRemoveCard(card.id());
766
767             } else if( card.isnew() && card.active() == 0 ) {
768                 /* a new card was created, then never used, removing.. */
769                 _debug("removing new inactive card "+card.barcode());
770                 ueRemoveCard(card.id());
771             }
772
773             /* create a new card for the patron */
774             var newcard = new ac();
775             newcard.id(uEditCardVirtId--);
776             newcard.isnew(1);
777             patron.card(newcard);
778             patron.cards().push(newcard);
779
780
781             /* reset the widget */
782             var field = uEditFindFieldByWId('ue_barcode');
783             field.widget.node.disabled = false;
784             field.widget.node.value = "";
785             field.widget.node.onchange();
786             field.object = newcard;
787             _debug("uEditMarkCardLost(): created new card object for user");
788         }
789     }
790 }
791
792
793 function ueRemoveCard(id) {
794     _debug("removing card from cards() array: " + id);
795     var cds = grep( patron.cards(), function(c){return (c.id() != id)});
796     if(!cds) cds = [];
797     for( var j = 0; j < cds.length; j++ )
798         _debug("patron card array now has :  "+cds[j].id());
799     patron.cards(cds);
800 }
801
802
803
804 function compactArray(arr) {
805     var a = [];
806     for( var i = 0; arr && i < arr.length; i++ ) {
807         if( arr[i] != null )
808             a.push(arr[i]);
809     }
810     return a;
811 }