]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/actor/user/register.js
added duplicate phone / address searching. added and started using locale strings...
[working/Evergreen.git] / Open-ILS / web / js / ui / default / actor / user / register.js
1 dojo.require('dojo.data.ItemFileReadStore');
2 dojo.require('dijit.form.Textarea');
3 dojo.require('dijit.form.FilteringSelect');
4 dojo.require('dijit.form.ComboBox');
5 dojo.require('fieldmapper.IDL');
6 dojo.require('openils.PermaCrud');
7 dojo.require('openils.widget.AutoGrid');
8 dojo.require('openils.widget.AutoFieldWidget');
9 dojo.require('dijit.form.CheckBox');
10 dojo.require('dijit.form.Button');
11 dojo.require('dojo.date');
12 dojo.require('openils.CGI');
13 dojo.require('openils.XUL');
14
15 dojo.requireLocalization('openils.actor', 'register');
16 var localeStrings = dojo.i18n.getLocalization('openils.actor', 'register');
17
18
19 var pcrud;
20 var fmClasses = ['au', 'ac', 'aua', 'actsc', 'asv', 'asvq', 'asva'];
21 var fieldDoc = {};
22 var statCats;
23 var statCatTempate;
24 var surveys;
25 var staff;
26 var patron;
27 var uEditUsePhonePw = false;
28 var widgetPile = [];
29 var uEditCardVirtId = -1;
30 var uEditAddrVirtId = -1;
31 var orgSettings = {};
32 var tbody;
33 var addrTemplateRows;
34 var cgi;
35 var cloneUser;
36
37
38 if(!window.xulG) var xulG = null;
39
40
41 function load() {
42     staff = new openils.User().user;
43     pcrud = new openils.PermaCrud();
44     cgi = new openils.CGI();
45     cloneUser = cgi.param('clone');
46     var userId = cgi.param('usr');
47
48     if(xulG) {
49             if(xulG.ses) openils.User.authtoken = xulG.ses;
50             if(xulG.clone !== null) cloneUser = xulG.clone;
51         if(xulG.usr !== null) userId = xulG.usr
52         if(xulG.params) {
53             var parms = xulG.params;
54                 if(parms.ses) 
55                 openils.User.authtoken = parms.ses;
56                 if(parms.clone) 
57                 cloneUser = parms.clone;
58             if(parms.usr !== null)
59                 userId = parms.usr
60         }
61     }
62
63     orgSettings = fieldmapper.aou.fetchOrgSettingBatch(staff.ws_ou(), [
64         'global.juvenile_age_threshold',
65         'patron.password.use_phone',
66         'ui.patron.default_inet_access_level'
67     ]);
68     for(k in orgSettings)
69         if(orgSettings[k])
70             orgSettings[k] = orgSettings[k].value;
71
72     uEditLoadUser(userId);
73
74     var list = pcrud.search('fdoc', {fm_class:fmClasses});
75     for(var i in list) {
76         var doc = list[i];
77         if(!fieldDoc[doc.fm_class()])
78             fieldDoc[doc.fm_class()] = {};
79         fieldDoc[doc.fm_class()][doc.field()] = doc;
80     }
81
82     tbody = dojo.byId('uedit-tbody');
83
84     addrTemplateRows = dojo.query('tr[type=addr-template]', tbody);
85     dojo.forEach(addrTemplateRows, function(row) { row.parentNode.removeChild(row); } );
86     statCatTemplate = tbody.removeChild(dojo.byId('stat-cat-row-template'));
87     surveyTemplate = tbody.removeChild(dojo.byId('survey-row-template'));
88     surveyQuestionTemplate = tbody.removeChild(dojo.byId('survey-question-row-template'));
89
90     loadStaticFields();
91     if(patron.isnew()) 
92         uEditNewAddr(null, uEditAddrVirtId);
93     else loadAllAddrs();
94     loadStatCats();
95     loadSurveys();
96 }
97
98 function uEditLoadUser(userId) {
99     if(!userId) return uEditNewPatron();
100     patron = fieldmapper.standardRequest(
101         ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve'],
102         {params : [openils.User.authtoken, userId]}
103     );
104 }
105
106 function loadStaticFields() {
107     for(var idx = 0; tbody.childNodes[idx]; idx++) {
108         var row = tbody.childNodes[idx];
109         if(row.nodeType != row.ELEMENT_NODE) continue;
110         var fmcls = row.getAttribute('fmclass');
111         if(!fmcls) continue;
112         fleshFMRow(row, fmcls);
113     }
114 }
115
116 function loadAllAddrs() {
117     dojo.forEach(patron.addresses(),
118         function(addr) {
119             uEditNewAddr(null, addr.id());
120         }
121     );
122 }
123
124 function loadStatCats() {
125
126     statCats = fieldmapper.standardRequest(
127         ['open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all'],
128         {params : [openils.User.authtoken, staff.ws_ou()]}
129     );
130
131     // draw stat cats
132     for(var idx in statCats) {
133         var stat = statCats[idx];
134         var row = statCatTemplate.cloneNode(true);
135         row.id = 'stat-cat-row-' + idx;
136         tbody.appendChild(row);
137         getByName(row, 'name').innerHTML = stat.name();
138         var valtd = getByName(row, 'widget');
139         var span = valtd.appendChild(document.createElement('span'));
140         var store = new dojo.data.ItemFileReadStore(
141                 {data:fieldmapper.actsc.toStoreData(stat.entries())});
142         var comboBox = new dijit.form.ComboBox({store:store}, span);
143         comboBox.labelAttr = 'value';
144         comboBox.searchAttr = 'value';
145
146         comboBox._wtype = 'statcat';
147         comboBox._statcat = stat.id();
148         widgetPile.push(comboBox); 
149
150         // populate existing cats
151         var map = patron.stat_cat_entries().filter(
152             function(mp) { return (mp.stat_cat() == stat.id()) })[0];
153         if(map) comboBox.attr('value', map.stat_cat_entry()); 
154
155     }
156 }
157
158 function loadSurveys() {
159
160     surveys = fieldmapper.standardRequest(
161         ['open-ils.circ', 'open-ils.circ.survey.retrieve.all'],
162         {params : [openils.User.authtoken]}
163     );
164
165     // draw surveys
166     for(var idx in surveys) {
167         var survey = surveys[idx];
168         var srow = surveyTemplate.cloneNode(true);
169         tbody.appendChild(srow);
170         getByName(srow, 'name').innerHTML = survey.name();
171
172         for(var q in survey.questions()) {
173             var quest = survey.questions()[q];
174             var qrow = surveyQuestionTemplate.cloneNode(true);
175             tbody.appendChild(qrow);
176             getByName(qrow, 'question').innerHTML = quest.question();
177
178             var span = getByName(qrow, 'answers').appendChild(document.createElement('span'));
179             var store = new dojo.data.ItemFileReadStore(
180                 {data:fieldmapper.asva.toStoreData(quest.answers())});
181             var select = new dijit.form.FilteringSelect({store:store}, span);
182             select.labelAttr = 'answer';
183             select.searchAttr = 'answer';
184
185             select._wtype = 'survey';
186             select._survey = survey.id();
187             select._question = quest.id();
188             widgetPile.push(select); 
189         }
190     }
191 }
192
193
194 function fleshFMRow(row, fmcls, args) {
195     var fmfield = row.getAttribute('fmfield');
196     var wclass = row.getAttribute('wclass');
197     var wstyle = row.getAttribute('wstyle');
198     var fieldIdl = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield];
199     if(!args) args = {};
200
201     var existing = dojo.query('td', row);
202     var htd = existing[0] || row.appendChild(document.createElement('td'));
203     var ltd = existing[1] || row.appendChild(document.createElement('td'));
204     var wtd = existing[2] || row.appendChild(document.createElement('td'));
205
206     openils.Util.addCSSClass(htd, 'uedit-help');
207     if(fieldDoc[fmcls] && fieldDoc[fmcls][fmfield]) {
208         var link = dojo.byId('uedit-help-template').cloneNode(true);
209         link.id = '';
210         link.onclick = function() { ueLoadContextHelp(fmcls, fmfield) };
211         openils.Util.removeCSSClass(link, 'hidden');
212         htd.appendChild(link);
213     }
214
215     if(!ltd.textContent) {
216         var span = document.createElement('span');
217         ltd.appendChild(document.createTextNode(fieldIdl.label));
218     }
219
220     span = document.createElement('span');
221     wtd.appendChild(span);
222
223     var fmObject = null;
224     switch(fmcls) {
225         case 'au' : fmObject = patron; break;
226         case 'ac' : fmObject = patron.card(); break;
227         case 'aua' : 
228             fmObject = patron.addresses().filter(
229                 function(i) { return (i.id() == args.addr) })[0];
230             break;
231     }
232     
233     var required = row.getAttribute('required') == 'required';
234     var widget = new openils.widget.AutoFieldWidget({
235         idlField : fieldIdl,
236         fmObject : fmObject,
237         fmClass : fmcls,
238         parentNode : span,
239         widgetClass : wclass,
240         dijitArgs : {
241             style: wstyle, 
242             required : required
243         },
244         orgLimitPerms : ['UPDATE_USER'],
245     });
246
247     widget.build();
248
249     widget._wtype = fmcls;
250     widget._fmfield = fmfield;
251     widget._addr = args.addr;
252     widgetPile.push(widget);
253     attachWidgetEvents(fmcls, fmfield, widget);
254     return widget;
255 }
256
257 function findWidget(wtype, fmfield, callback) {
258     return widgetPile.filter(
259         function(i){
260             if(i._wtype == wtype && i._fmfield == fmfield) {
261                 if(callback) return callback(i);
262                 return true;
263             }
264         }
265     ).pop();
266 }
267
268 function attachWidgetEvents(fmcls, fmfield, widget) {
269
270     if(fmcls == 'ac') {
271         if(fmfield == 'barcode') {
272             dojo.connect(widget.widget, 'onChange',
273                 function() {
274                     var un = findWidget('au', 'usrname');
275                     if(!un.widget.attr('value'))
276                         un.widget.attr('value', this.attr('value'));
277                 }
278             );
279             return;
280         }
281     }
282
283     if(fmcls == 'au') {
284         switch(fmfield) {
285
286             case 'profile': // when the profile changes, update the expire date
287                 dojo.connect(widget.widget, 'onChange', 
288                     function() {
289                         var self = this;
290                         var expireWidget = findWidget('au', 'expire_date');
291                         function found(items) {
292                             if(items.length == 0) return;
293                             var item = items[0];
294                             var interval = self.store.getValue(item, 'perm_interval');
295                             expireWidget.widget.attr('value', dojo.date.add(new Date(), 
296                                 'second', openils.Util.intervalToSeconds(interval)));
297                         }
298                         this.store.fetch({onComplete:found, query:{id:this.attr('value')}});
299                     }
300                 );
301                 return;
302
303             case 'dob':
304                 dojo.connect(widget.widget, 'onChange',
305                     function(newDob) {
306                         if(!newDob) return;
307                         var oldDob = patron.dob();
308                         if(dojo.date.stamp.fromISOString(oldDob) == newDob) return;
309
310                         var juvInterval = orgSettings['global.juvenile_age_threshold'] || '18 years';
311                         var juvWidget = findWidget('au', 'juvenile');
312                         var base = new Date();
313                         base.setTime(base.getTime() - Number(openils.Util.intervalToSeconds(juvInterval) + '000'));
314
315                         if(newDob <= base) // older than global.juvenile_age_threshold
316                             juvWidget.widget.attr('value', false);
317                         else
318                             juvWidget.widget.attr('value', true);
319                     }
320                 );
321                 return;
322
323             case 'first_given_name':
324             case 'family_name':
325                 dojo.connect(widget.widget, 'onChange',
326                     function(newVal) { uEditDupeSearch('name', newVal); });
327                 return;
328
329             case 'email':
330                 dojo.connect(widget.widget, 'onChange',
331                     function(newVal) { uEditDupeSearch('email', newVal); });
332                 return;
333
334             case 'ident_value':
335             case 'ident_value2':
336                 dojo.connect(widget.widget, 'onChange',
337                     function(newVal) { uEditDupeSearch('ident', newVal); });
338                 return;
339
340             case 'day_phone':
341             case 'evening_phone':
342             case 'other_phone':
343                 dojo.connect(widget.widget, 'onChange',
344                     function(newVal) { uEditDupeSearch('phone', newVal); });
345                 return;
346
347         }
348     }
349
350     if(fmclass = 'aua') {
351         switch(fmfield) {
352             case 'post_code':
353                 dojo.connect(widget.widget, 'onChange',
354                     function(e) { 
355                         fieldmapper.standardRequest(
356                             ['open-ils.search', 'open-ils.search.zip'],
357                             {   async: true,
358                                 params: [e],
359                                 oncomplete : function(r) {
360                                     var res = openils.Util.readResponse(r);
361                                     if(!res) return;
362                                     var callback = function(w) { return w._addr == widget._addr; };
363                                     if(res.city) findWidget('aua', 'city', callback).widget.attr('value', res.city);
364                                     if(res.state) findWidget('aua', 'state', callback).widget.attr('value', res.state);
365                                     if(res.county) findWidget('aua', 'county', callback).widget.attr('value', res.county);
366                                     if(res.alert) alert(res.alert);
367                                 }
368                             }
369                         );
370                     }
371                 );
372                 return;
373
374             case 'street1':
375             case 'street2':
376             case 'city':
377                 dojo.connect(widget.widget, 'onChange',
378                     function(e) {
379                         var callback = function(w) { return w._addr == widget._addr; };
380                         var args = {
381                             street1 : findWidget('aua', 'street1', callback).widget.attr('value'),
382                             street2 : findWidget('aua', 'street2', callback).widget.attr('value'),
383                             city : findWidget('aua', 'city', callback).widget.attr('value'),
384                             post_code : findWidget('aua', 'post_code', callback).widget.attr('value')
385                         };
386                         if(args.street1 && args.city && args.post_code)
387                             uEditDupeSearch('address', args); 
388                     }
389                 );
390                 return;
391         }
392     }
393 }
394
395 function uEditDupeSearch(type, value) {
396     var search;
397     switch(type) {
398
399         case 'name':
400             openils.Util.hide('uedit-dupe-names-link');
401             var fname = findWidget('au', 'first_given_name').widget.attr('value');
402             var lname = findWidget('au', 'family_name').widget.attr('value');
403             if( !(fname && lname) ) return;
404             search = {
405                 first_given_name : {value : fname, group : 0},
406                 family_name : {value : lname, group : 0},
407             };
408             break;
409
410         case 'email':
411             openils.Util.hide('uedit-dupe-email-link');
412             search = {email : {value : value, group : 0}};
413             break;
414
415         case 'ident':
416             openils.Util.hide('uedit-dupe-ident-link');
417             search = {ident : {value : value, group : 2}};
418             break;
419
420         case 'phone':
421             openils.Util.hide('uedit-dupe-phone-link');
422             search = {phone : {value : value, group : 2}};
423             break;
424
425         case 'address':
426             openils.Util.hide('uedit-dupe-address-link');
427             search = {};
428             dojo.forEach(['street1', 'street2', 'city', 'post_code'],
429                 function(field) {
430                     if(value[field])
431                         search[field] = {value : value[field], group: 1};
432                 }
433             );
434             break;
435     }
436
437     // find possible duplicate patrons
438     fieldmapper.standardRequest(
439         ['open-ils.actor', 'open-ils.actor.patron.search.advanced'],
440         {   async: true,
441             params: [openils.User.authtoken, search],
442             oncomplete : function(r) {
443                 var resp = openils.Util.readResponse(r);
444                 resp = resp.filter(function(id) { return (id != patron.id()); });
445
446                 if(resp && resp.length > 0) {
447
448                     openils.Util.hide('uedit-help-div');
449                     openils.Util.show('uedit-dupe-div');
450                     var link;
451
452                     switch(type) {
453                         case 'name':
454                             link = dojo.byId('uedit-dupe-names-link');
455                             link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_NAME, [resp.length]);
456                             break;
457                         case 'email':
458                             link = dojo.byId('uedit-dupe-email-link');
459                             link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_EMAIL, [resp.length]);
460                             break;
461                         case 'ident':
462                             link = dojo.byId('uedit-dupe-ident-link');
463                             link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_IDENT, [resp.length]);
464                             break;
465                         case 'phone':
466                             link = dojo.byId('uedit-dupe-phone-link');
467                             link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_PHONE, [resp.length]);
468                             break;
469                         case 'address':
470                             link = dojo.byId('uedit-dupe-address-link');
471                             link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_ADDR, [resp.length]);
472                             break;
473                     }
474
475                     openils.Util.show(link);
476                     link.onclick = function() {
477                         if(window.xulG)
478                             window.xulG.spawn_search(search);
479                         else
480                             console.log("running XUL patron search " + js2JSON(search));
481                     }
482                 }
483             }
484         }
485     );
486 }
487
488 function getByName(node, name) {
489     return dojo.query('[name='+name+']', node)[0];
490 }
491
492
493 function ueLoadContextHelp(fmcls, fmfield) {
494     openils.Util.hide('uedit-dupe-div');
495     openils.Util.show('uedit-help-div');
496     dojo.byId('uedit-help-field').innerHTML = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield].label;
497     dojo.byId('uedit-help-text').innerHTML = fieldDoc[fmcls][fmfield].string();
498 }
499
500
501 /* creates a new patron object with card attached */
502 function uEditNewPatron() {
503     patron = new au();
504     patron.isnew(1);
505     patron.id(-1);
506     card = new ac();
507     card.id(uEditCardVirtId);
508     card.isnew(1);
509     patron.card(card);
510     patron.cards([card]);
511     patron.net_access_level(orgSettings['ui.patron.default_inet_access_level'] || 1);
512     patron.stat_cat_entries([]);
513     patron.survey_responses([]);
514     patron.addresses([]);
515     uEditMakeRandomPw(patron);
516 }
517
518 function uEditMakeRandomPw(patron) {
519     if(uEditUsePhonePw) return;
520     var rand  = Math.random();
521     rand = parseInt(rand * 10000) + '';
522     while(rand.length < 4) rand += '0';
523 /*
524     appendClear($('ue_password_plain'),text(rand));
525     unHideMe($('ue_password_gen'));
526 */
527     patron.passwd(rand);
528     return rand;
529 }
530
531 function uEditWidgetVal(w) {
532     var val = (w.getFormattedValue) ? w.getFormattedValue() : w.attr('value');
533     if(val === '') val = null;
534     return val;
535 }
536
537 function uEditSave() { _uEditSave(); }
538 function uEditSaveClone() { _uEditSave(true); }
539
540 function _uEditSave(doClone) {
541
542     for(var idx in widgetPile) {
543         var w = widgetPile[idx];
544         var val = uEditWidgetVal(w);
545
546         switch(w._wtype) {
547             case 'au':
548                 patron[w._fmfield](val);
549                 break;
550
551             case 'ac':
552                 patron.card()[w._fmfield](val);
553                 break;
554
555             case 'aua':
556                 var addr = patron.addresses().filter(function(i){return (i.id() == w._addr)})[0];
557                 if(!addr) {
558                     addr = new fieldmapper.aua();
559                     addr.id(w._addr);
560                     addr.isnew(1);
561                     addr.usr(patron.id());
562                     patron.addresses().push(addr);
563                 } else {
564                     if(addr[w._fmfield]() != val)
565                         addr.ischanged(1);
566                 }
567                 addr[w._fmfield](val);
568                 break;
569
570             case 'survey':
571                 if(val == null) break;
572                 var resp = new fieldmapper.asvr();
573                 resp.isnew(1);
574                 resp.survey(w._survey)
575                 resp.usr(patron.id());
576                 resp.question(w._question)
577                 resp.answer(val);
578                 patron.survey_responses().push(resp);
579                 break;
580
581             case 'statcat':
582                 if(val == null) break;
583
584                 var map = patron.stat_cat_entries().filter(
585                     function(m){
586                         return (m.stat_cat() == w._statcat) })[0];
587
588                 if(map) {
589                     if(map.stat_cat_entry() == val) 
590                         break;
591                     map.ischanged(1);
592                 } else {
593                     map = new fieldmapper.actscecm();
594                     map.isnew(1);
595                 }
596
597                 map.stat_cat(w._statcat);
598                 map.stat_cat_entry(val);
599                 map.target_usr(patron.id());
600                 patron.stat_cat_entries().push(map);
601                 break;
602         }
603     }
604
605     patron.ischanged(1);
606     fieldmapper.standardRequest(
607         ['open-ils.actor', 'open-ils.actor.patron.update'],
608         {   async: true,
609             params: [openils.User.authtoken, patron],
610             oncomplete: function(r) {
611                 newPatron = openils.Util.readResponse(r);
612                 if(newPatron) uEditFinishSave(newPatron, doClone);
613             }
614         }
615     );
616 }
617
618 function uEditFinishSave(newPatron, doClone) {
619
620     if(doClone &&cloneUser == null)
621         cloneUser = newPatron.id();
622
623         if( doClone ) {
624
625                 if(xulG && typeof xulG.spawn_editor == 'function' && !patron.isnew() ) {
626             window.xulG.spawn_editor({ses:openils.User.authtoken,clone:cloneUser});
627             uEditRefresh();
628
629                 } else {
630                         location.href = href.replace(/\?.*/, '') + '?clone=' + cloneUser;
631                 }
632
633         } else {
634
635                 uEditRefresh();
636         }
637
638         uEditRefreshXUL(newPatron);
639 }
640
641 function uEditRefresh() {
642     var usr = cgi.param('usr');
643     var href = location.href.replace(/\?.*/, '');
644     href += ((usr) ? '?usr=' + usr : '');
645     location.href = href;
646 }
647
648 function uEditRefreshXUL(newuser) {
649         if (window.xulG && typeof window.xulG.on_save == 'function') 
650                 window.xulG.on_save(newuser);
651 }
652
653
654 function uEditNewAddr(evt, id) {
655     if(id == null) id = --uEditAddrVirtId;
656     dojo.forEach(addrTemplateRows, 
657         function(row) {
658
659             row = tbody.insertBefore(row.cloneNode(true), dojo.byId('new-addr-row'));
660             row.setAttribute('type', '');
661             row.setAttribute('addr', id+'');
662
663             if(row.getAttribute('fmclass')) {
664                 fleshFMRow(row, 'aua', {addr:id});
665
666             } else if(row.getAttribute('name') == 'uedit-addr-pending-row') {
667
668                 var addr =  patron.addresses().filter(
669                     function(i) { return (i.id() == id) })[0];
670                 
671                 // if it's a pending address, show the 'approve' button
672                 if(addr && openils.Util.isTrue(addr.pending())) {
673                     openils.Util.show(row, 'table-row');
674                     dojo.query('[name=approve-button]', row)[0].onclick = 
675                         function() { uEditApproveAddress(addr); };
676
677                     if(addr.replaces()) {
678                         var div = dojo.query('[name=replaced-addr]', row)[0]
679                         div.innerHTML = addr.replaces();
680                     } else {
681                         openils.Util.hide(dojo.query('[name=replaced-addr-div]', row)[0]);
682                     }
683                 }
684
685             } else {
686                 var btn = dojo.query('[name=delete-button]', row)[0];
687                 if(btn) btn.onclick = function(){ uEditDeleteAddr(id) };
688             }
689         }
690     );
691 }
692
693 function uEditApproveAddress(addr) {
694     fieldmapper.standardRequest(
695         ['open-ils.actor', 'open-ils.actor.user.pending_address.approve'],
696         {   async: true,
697             params:  [openils.User.authtoken, addr],
698
699             oncomplete : function(r) {
700                 var oldId = openils.Util.readResponse(r);
701                     
702                 // remove addrs from UI
703                 dojo.forEach(
704                     patron.addresses(), 
705                     function(addr) { uEditDeleteAddr(addr.id(), true); }
706                 );
707
708                 if(oldId != null) {
709                     
710                     // remove the replaced address 
711                     if(oldId != addr.id()) {
712                                 patron.addresses(
713                             patron.addresses().filter(
714                                                 function(i) { return (i.id() != oldId); }
715                                         )
716                                 );
717                     }
718                     
719                     // fix the the new address
720                     addr.id(oldId);
721                     addr.replaces(null);
722                     addr.pending('f');
723
724                 }
725
726                 // redraw addrs
727                 loadAllAddrs();
728             }
729         }
730     );
731 }
732
733
734 function uEditDeleteAddr(id, noAlert) {
735     if(!noAlert) {
736         if(!confirm('Delete address ' + id)) return; /* XXX i18n */
737     }
738     var rows = dojo.query('tr[addr='+id+']', tbody);
739     for(var i = 0; i < rows.length; i++)
740         rows[i].parentNode.removeChild(rows[i]);
741     widgetPile = widgetPile.filter(function(w){return (w._addr != id)});
742 }
743
744 function uEditToggleRequired() {
745     if((tbody.className +'').match(/hide-non-required/)) 
746         openils.Util.removeCSSClass(tbody, 'hide-non-required');
747     else
748         openils.Util.addCSSClass(tbody, 'hide-non-required');
749     openils.Util.toggle('uedit-show-required');
750     openils.Util.toggle('uedit-show-all');
751 }
752
753
754
755 openils.Util.addOnLoad(load);