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