]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/ue.js
e029118c67d393f4db6dea53a103efd304fb4bdf
[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) {
286         if(uEditUsePhonePw) {
287             if( (pw = patron.day_phone()) ||
288                 (pw = patron.evening_phone()) || (pw = patron.other_phone()) ) {
289                     pw = pw.substring(pw.length - 4); // this is iffy
290                     uEditResetPw(pw);
291                         appendClear($('ue_password_plain'), text(pw));
292                         unHideMe($('ue_password_gen'));
293              }
294         } else {
295             pw = uEditMakeRandomPw(patron);
296         }
297         $('ue_password1').value = pw;
298         $('ue_password2').value = pw;
299         $('ue_password1').onchange();
300     }
301 }
302
303
304 function uEditClone(clone) {
305
306     var cloneUser = fetchFleshedUser(clone);
307     patron.usrgroup(cloneUser.usrgroup());
308
309     if( cloneUser.day_phone() ) {
310         $('ue_day_phone').value = cloneUser.day_phone();
311         $('ue_day_phone').onchange();
312     }
313
314     if( cloneUser.evening_phone() ) {
315         $('ue_night_phone').value = cloneUser.evening_phone();
316         $('ue_night_phone').onchange();
317     }
318
319     if( cloneUser.other_phone() ) {
320         $('ue_other_phone').value = cloneUser.other_phone();
321         $('ue_other_phone').onchange();
322     }
323
324     setSelector($('ue_org_selector'), cloneUser.home_ou());
325     setSelector($('ue_profile'), cloneUser.profile());
326
327     /* force the expire date to be set */
328     $('ue_profile').onchange();
329     $('ue_org_selector').onchange();
330
331     for( var a in cloneUser.addresses() ) {
332         var addr = cloneUser.addresses()[a];
333         if( cloneUser.mailing_address && 
334                 addr.id() == cloneUser.mailing_address().id() )
335             patron.mailing_address(addr);
336         if( cloneUser.billing_address() &&
337                 addr.id() == cloneUser.billing_address().id() )
338             patron.billing_address(addr);
339         patron.addresses().push(addr);
340     }
341
342     uEditBuildAddrs(patron);
343 }
344
345
346 /* Creates a new blank address, 
347     adds it to the user and the fields array */
348 var uEditVirtualAddrId = -1;
349 function uEditCreateNewAddr() {
350     var addr = new aua();
351
352     addr.id(uEditVirtualAddrId--);
353     addr.isnew(1);
354     addr.usr(patron.id());
355     addr.country(defaultCountry);
356
357     if(!patron.addresses()) 
358         patron.addresses([]);
359
360     if(patron.addresses().length == 0) {
361         patron.mailing_address(addr);
362         patron.billing_address(addr);
363     }
364
365     addr.valid(1);
366     addr.within_city_limits(1);
367
368     uEditBuildAddrFields(patron, addr);
369     patron.addresses().push(addr);
370     uEditIterateFields(function(f) { uEditCheckValid(f); });
371     uEditCheckErrors();
372 }
373
374
375 /* kicks off the UI drawing */
376 function uEditDraw(identTypes, groups, statCats, surveys, netLevels ) {
377     hideMe($('uedit_loading'));
378     unHideMe($('ue_maintd'));
379
380     dataFields = [];
381     uEditDrawIDTypes(identTypes);
382     uEditDrawGroups(groups, null, null, true);
383     uEditDrawStatCats(statCats);
384     uEditDrawSurveys(surveys);
385     uEditDrawNetLevels(netLevels);
386     uEditDefineData(patron);
387
388     uEditIterateFields(function(f) { uEditActivateField(f) });
389     uEditIterateFields(function(f) { uEditCheckValid(f); });
390     uEditCheckErrors();
391 }
392
393
394 /** Applies the event handlers and sets the data for the field */
395 function uEditActivateField(field) {
396
397     if( field.widget.id ) {
398         field.widget.node = $(field.widget.id);
399
400     } else {
401         field.widget.node = 
402             $n(field.widget.base, field.widget.name);
403     }
404
405     uEditSetOnchange(field);
406
407     if(field.widget.onblur) {
408         field.widget.node.onblur = 
409             function() { field.widget.onblur(field); };
410     }
411
412     field.widget.node.disabled = field.widget.disabled;
413     if(field.object == null) return;
414     var val = field.object[field.key]();
415     if(val == null) return;
416
417     if( field.widget.type == 'input' )
418         field.widget.node.value = val;
419
420     if( field.widget.type == 'select' )
421         setSelector(field.widget.node, val);
422
423     if( field.widget.type == 'checkbox' )
424         field.widget.node.checked = 
425             (val && val != 'f') ? true : false;
426
427     if( field.widget.onload ) 
428         field.widget.onload(val);
429 }
430
431
432 /* set up the onchange event for the field */
433 function uEditSetOnchange(field) {
434     var func = function() {uEditOnChange( field );}
435     field.widget.node.onchange = func;
436
437     if(field.widget.type != 'select')
438         field.widget.node.onkeyup = func;
439 }
440
441 /* find the current value of the field object's widget */
442 function uEditNodeVal(field) {
443     if(field.widget.type == 'input')
444         return field.widget.node.value;
445
446     if(field.widget.type == 'checkbox')
447         return field.widget.node.checked;
448
449     if(field.widget.type == 'select')
450         return getSelectorVal(field.widget.node);
451 }
452
453
454 /* update a field value */
455 function uEditOnChange(field) {
456
457     var newval = uEditNodeVal(field);
458     field.object[field.key](newval);
459     field.object.ischanged(1);
460
461     if(field.widget.onpostchange)
462         field.widget.onpostchange(field, newval);
463
464     //_debug(field.key+' = '+newval);
465
466     uEditIterateFields(function(f) { uEditCheckValid(f); });
467     uEditCheckErrors();
468
469    uEditSetUnload();
470 }
471
472
473 function uEditCheckValid(field) {
474     var newval = uEditNodeVal(field);
475
476     if(newval) {
477
478         if(field.widget.regex) { 
479             if(newval.match(field.widget.regex)) 
480                 removeCSSClass(field.widget.node, CSS_INVALID_DATA);
481             else
482                 addCSSClass(field.widget.node, CSS_INVALID_DATA);
483
484         } else {
485             removeCSSClass(field.widget.node, CSS_INVALID_DATA);
486         }
487
488     } else {
489
490         if(field.required) {
491             addCSSClass(field.widget.node, CSS_INVALID_DATA);
492
493         } else {
494             removeCSSClass(field.widget.node, CSS_INVALID_DATA);
495         }
496     }
497
498 }
499
500 /* find a field object by object key */
501 function uEditFindFieldByKey(key) {
502     var fields = grep( dataFields,
503         function(item) { return (item.key == key); });
504     return (fields) ? fields[0] : null;
505 }
506
507 /* find a list of fields by object key */
508 function uEditFindFieldsByKey(key) {
509     return grep( dataFields,
510         function(item) { return (item.key == key); });
511 }
512
513 /* find a field object by widget id */
514 function uEditFindFieldByWId(id) {
515     var fields = grep( dataFields,
516         function(item) { return (item.widget.id == id); });
517     return (fields) ? fields[0] : null;
518 }
519
520
521 function uEditIterateFields(callback) {
522     for( var f in dataFields ) 
523         callback(dataFields[f]);
524 }
525
526
527 function uEditGetErrorStrings() {
528     var errors = [];
529     uEditIterateFields(
530         function(field) { 
531             if(field.errkey) {
532                 if( !field.object.isdeleted() ) {
533                     if( field.widget.node.className.indexOf(CSS_INVALID_DATA) != -1) {
534                         var str = $(field.errkey).innerHTML;
535                         if(str) errors.push(str);
536                     }
537                 }
538             }
539         }
540     );
541
542     /* munge up something for all of the required surveys 
543         (which are not registered with the fields) */
544     if( patron.isnew() ) {
545         var sel = $('ue_survey_table');
546
547         if( sel ) {
548             var rows = sel.getElementsByTagName('tr');
549
550             for( var r in rows ) {
551         
552                 var row = rows[r];
553                 var sel = $n(row, 'ue_survey_answer');
554                 if(!sel) continue;
555                 var qstn = row.getAttribute('question');
556         
557                 if(qstn) {
558                     qstn        = surveyQuestionsCache[qstn];
559                     survey    = surveysCache[qstn.survey()];
560                     var val    = getSelectorVal(sel);
561                     if(!val && isTrue(survey.required()))
562                         errors.push($('ue_bad_survey').innerHTML + ' : ' + qstn.question());
563                 }
564             }
565         }
566     }
567
568     /* ------------------------------------------------------------ */
569
570     if(errors[0]) return errors;
571     return null;
572 }
573
574 function uEditAlertErrors() {
575     var errors = uEditGetErrorStrings();
576     if(!errors) return false;
577     alert(errors.join("\n"));
578     return true;
579 }
580
581
582 /* send the user to the database */
583 function uEditSaveUser(cloneme) {
584
585     if(uEditGetErrorStrings()) {
586         uEditAlertErrors();
587         return;
588     }
589
590     /* null is unique in the db, but '' is not */
591     if( ! patron.ident_value() ) patron.ident_value(null);
592     //if( ! patron.ident_type2() ) patron.ident_type2(null);
593     if( ! patron.ident_value2() ) patron.ident_value2(null);
594     patron.ident_type2(null);
595
596     if(! patron.dob() ) patron.dob(null);
597
598     _debug("Saving patron with card: " + js2JSON(patron.card()));
599     _debug("Saving full patron: " + js2JSON(patron));
600
601     //for( var c in patron
602
603     var req = new Request(UPDATE_PATRON, SESSION, patron);
604     req.alertEvent = false;
605     req.send(true);
606     var newuser = req.result();
607
608    uEditClearUnload();
609
610     var evt;
611     if( (evt = checkILSEvent(newuser)) || ! newuser ) {
612         if(evt) {
613             evt = newuser;
614             if( evt.textcode == 'XACT_COLLISION' ) {
615                 if( confirmId('ue_xact_collision') )
616                     location.href = location.href;
617                 return;
618             }
619             var j = js2JSON(evt);
620             alert(j);
621             _debug("USER UPDATE FAILED:\n" + j);
622         }
623         return;
624     } 
625
626     alert($('ue_success').innerHTML);
627
628     if(cloneme) {
629         /* if the user we just created was a clone, and we want to clone it,
630         we really want to clone the original */
631         if( clone ) cloneme = clone;
632         else cloneme = newuser.id();
633     }
634
635
636     if( cloneme ) {
637
638         if(window.xulG &&
639             typeof window.xulG.spawn_editor == 'function' && 
640
641             !patron.isnew() ) {
642                 _debug("xulG clone spawning new interface...");
643                 var ses = cgi.param('ses'); 
644                 if (xulG) if (xulG.ses) ses = xulG.ses;
645                 if (xulG) if (xulG.params) if (xulG.params.ses) ses = xulG.params.ses;
646                 window.xulG.spawn_editor({ses:ses,clone:cloneme});
647                 uEditRefresh();
648
649         } else {
650
651             var href = location.href;
652             href = href.replace(/\&?usr=\d+/, '');
653             href = href.replace(/\&?clone=\d+/, '');
654             href += (href.match(/\?/) ? "&" : "?") + 'clone=' + cloneme;
655             location.href = href;
656         }
657
658     } else {
659
660         uEditRefresh();
661     }
662
663     uEditRefreshXUL(newuser);
664 }
665
666
667 function uEditRefreshXUL(newuser) {
668     if (window.xulG && typeof window.xulG.on_save == 'function') 
669         window.xulG.on_save(newuser);
670 }
671
672 function uEditRefresh() {
673     var href = location.href;
674     href = href.replace(/\&?clone=\d+/, '');
675     location.href = href;
676 }
677
678
679 function uEditCancel() {
680     var href = location.href;
681     href = href.replace(/\&?usr=\d+/, '');
682     href = href.replace(/\&?clone=\d+/, '');
683     var id = cgi.param('usr'); 
684     if (xulG) if (xulG.usr) id = xulG.usr;
685     if (xulG) if (xulG.params) if (xulG.params.usr) id = xulG.params.usr;
686     /* reload the current user if available */
687     if( id ) href += (href.match(/\?/) ? "&" : "?") + "usr=" + id;
688     location.href = href;
689 }
690
691
692 var uEditDupHashes = {};
693 var uEditDupTemplate;
694
695 function uEditRunDupeSearch(type, search_hash) {
696
697     if(!patron.isnew()) return;
698
699     _debug('dup search: ' + js2JSON(search_hash));
700
701     var req = new Request(PATRON_SEARCH, SESSION, search_hash);
702
703     var container = $('dup_div_container');
704     if(!uEditDupTemplate)
705         uEditDupTemplate = container.removeChild($('dup_div'));
706
707     /* clear any existing dups for this type */
708     iterate( container.getElementsByTagName('div'),
709         function(d) {
710             if( d.getAttribute('type') == type ) {
711                 container.removeChild(d)
712                 return;
713             }
714         }
715     );
716
717     req.callback(
718         function(r) {
719             uEditHandleDupResults( r.getResultObject(), search_hash, type, container );
720         }
721     );
722     req.send();
723 }
724
725
726 function uEditHandleDupResults(ids, search_hash, type, container) {
727
728     _debug('dup search results: ' + js2JSON(ids));
729
730     if(!(ids && ids[0]))  /* no results */
731         return uEditDupHashes[type] = null;
732
733     /* add a dup link to the UI and plug in the data */
734     var node = uEditDupTemplate.cloneNode(true);
735     container.appendChild(node);
736     node.setAttribute('type', type);
737
738     var link = $n(node, 'link');
739     link.setAttribute('type', type);
740     unHideMe(link);
741     $n(node,'count').appendChild(text(ids.length));
742
743     for( var o in search_hash ) 
744         $n(node, 'data').appendChild(
745             text(search_hash[o].value + ' '));
746
747     uEditDupHashes[type] = search_hash;
748
749     switch(type) {
750         case 'ident' :
751             if(confirm($('ue_dup_ident1').innerHTML)) 
752                 uEditShowSearch(null, type);
753             break;
754     }
755 }
756
757
758 function uEditShowSearch(link,type) {
759     if(!type) type = link.getAttribute('type');
760     if(window.xulG)
761         window.xulG.spawn_search(uEditDupHashes[type]);    
762     else alert($("patronStrings").getString('web.staff.patron.ue.uedit_show_search.search_would_be', js2JSON(uEditDupHashes[type])));
763 }
764
765 function uEditMarkCardLost() {
766
767     for( var c in patron.cards() ) {
768
769         var card = patron.cards()[c];
770         if( patron.card().id() == card.id() ) {
771
772             /* de-activite the current card */
773             card.ischanged(1);
774             card.active(0);
775
776             if( !card.barcode() ) {
777                 /* a card exists in the array with no barcode */
778                 ueRemoveCard(card.id());
779
780             } else if( card.isnew() && card.active() == 0 ) {
781                 /* a new card was created, then never used, removing.. */
782                 _debug("removing new inactive card "+card.barcode());
783                 ueRemoveCard(card.id());
784             }
785
786             /* create a new card for the patron */
787             var newcard = new ac();
788             newcard.id(uEditCardVirtId--);
789             newcard.isnew(1);
790             patron.card(newcard);
791             patron.cards().push(newcard);
792
793
794             /* reset the widget */
795             var field = uEditFindFieldByWId('ue_barcode');
796             field.widget.node.disabled = false;
797             field.widget.node.value = "";
798             field.widget.node.onchange();
799             field.object = newcard;
800             _debug("uEditMarkCardLost(): created new card object for user");
801         }
802     }
803 }
804
805
806 function ueRemoveCard(id) {
807     _debug("removing card from cards() array: " + id);
808     var cds = grep( patron.cards(), function(c){return (c.id() != id)});
809     if(!cds) cds = [];
810     for( var j = 0; j < cds.length; j++ )
811         _debug("patron card array now has :  "+cds[j].id());
812     patron.cards(cds);
813 }
814
815
816
817 function compactArray(arr) {
818     var a = [];
819     for( var i = 0; arr && i < arr.length; i++ ) {
820         if( arr[i] != null )
821             a.push(arr[i]);
822     }
823     return a;
824 }