]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/actor/user/register.js
in duplicate patron search, sort patrons with penalties to the top, followed by last...
[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                         search.search_sort = js2JSON(["penalties", "family_name", "first_given_name"]);
478                         if(window.xulG)
479                             window.xulG.spawn_search(search);
480                         else
481                             console.log("running XUL patron search " + js2JSON(search));
482                     }
483                 }
484             }
485         }
486     );
487 }
488
489 function getByName(node, name) {
490     return dojo.query('[name='+name+']', node)[0];
491 }
492
493
494 function ueLoadContextHelp(fmcls, fmfield) {
495     openils.Util.hide('uedit-dupe-div');
496     openils.Util.show('uedit-help-div');
497     dojo.byId('uedit-help-field').innerHTML = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield].label;
498     dojo.byId('uedit-help-text').innerHTML = fieldDoc[fmcls][fmfield].string();
499 }
500
501
502 /* creates a new patron object with card attached */
503 function uEditNewPatron() {
504     patron = new au();
505     patron.isnew(1);
506     patron.id(-1);
507     card = new ac();
508     card.id(uEditCardVirtId);
509     card.isnew(1);
510     patron.card(card);
511     patron.cards([card]);
512     patron.net_access_level(orgSettings['ui.patron.default_inet_access_level'] || 1);
513     patron.stat_cat_entries([]);
514     patron.survey_responses([]);
515     patron.addresses([]);
516     uEditMakeRandomPw(patron);
517 }
518
519 function uEditMakeRandomPw(patron) {
520     if(uEditUsePhonePw) return;
521     var rand  = Math.random();
522     rand = parseInt(rand * 10000) + '';
523     while(rand.length < 4) rand += '0';
524 /*
525     appendClear($('ue_password_plain'),text(rand));
526     unHideMe($('ue_password_gen'));
527 */
528     patron.passwd(rand);
529     return rand;
530 }
531
532 function uEditWidgetVal(w) {
533     var val = (w.getFormattedValue) ? w.getFormattedValue() : w.attr('value');
534     if(val === '') val = null;
535     return val;
536 }
537
538 function uEditSave() { _uEditSave(); }
539 function uEditSaveClone() { _uEditSave(true); }
540
541 function _uEditSave(doClone) {
542
543     for(var idx in widgetPile) {
544         var w = widgetPile[idx];
545         var val = uEditWidgetVal(w);
546
547         switch(w._wtype) {
548             case 'au':
549                 patron[w._fmfield](val);
550                 break;
551
552             case 'ac':
553                 patron.card()[w._fmfield](val);
554                 break;
555
556             case 'aua':
557                 var addr = patron.addresses().filter(function(i){return (i.id() == w._addr)})[0];
558                 if(!addr) {
559                     addr = new fieldmapper.aua();
560                     addr.id(w._addr);
561                     addr.isnew(1);
562                     addr.usr(patron.id());
563                     patron.addresses().push(addr);
564                 } else {
565                     if(addr[w._fmfield]() != val)
566                         addr.ischanged(1);
567                 }
568                 addr[w._fmfield](val);
569                 break;
570
571             case 'survey':
572                 if(val == null) break;
573                 var resp = new fieldmapper.asvr();
574                 resp.isnew(1);
575                 resp.survey(w._survey)
576                 resp.usr(patron.id());
577                 resp.question(w._question)
578                 resp.answer(val);
579                 patron.survey_responses().push(resp);
580                 break;
581
582             case 'statcat':
583                 if(val == null) break;
584
585                 var map = patron.stat_cat_entries().filter(
586                     function(m){
587                         return (m.stat_cat() == w._statcat) })[0];
588
589                 if(map) {
590                     if(map.stat_cat_entry() == val) 
591                         break;
592                     map.ischanged(1);
593                 } else {
594                     map = new fieldmapper.actscecm();
595                     map.isnew(1);
596                 }
597
598                 map.stat_cat(w._statcat);
599                 map.stat_cat_entry(val);
600                 map.target_usr(patron.id());
601                 patron.stat_cat_entries().push(map);
602                 break;
603         }
604     }
605
606     patron.ischanged(1);
607     fieldmapper.standardRequest(
608         ['open-ils.actor', 'open-ils.actor.patron.update'],
609         {   async: true,
610             params: [openils.User.authtoken, patron],
611             oncomplete: function(r) {
612                 newPatron = openils.Util.readResponse(r);
613                 if(newPatron) uEditFinishSave(newPatron, doClone);
614             }
615         }
616     );
617 }
618
619 function uEditFinishSave(newPatron, doClone) {
620
621     if(doClone &&cloneUser == null)
622         cloneUser = newPatron.id();
623
624         if( doClone ) {
625
626                 if(xulG && typeof xulG.spawn_editor == 'function' && !patron.isnew() ) {
627             window.xulG.spawn_editor({ses:openils.User.authtoken,clone:cloneUser});
628             uEditRefresh();
629
630                 } else {
631                         location.href = href.replace(/\?.*/, '') + '?clone=' + cloneUser;
632                 }
633
634         } else {
635
636                 uEditRefresh();
637         }
638
639         uEditRefreshXUL(newPatron);
640 }
641
642 function uEditRefresh() {
643     var usr = cgi.param('usr');
644     var href = location.href.replace(/\?.*/, '');
645     href += ((usr) ? '?usr=' + usr : '');
646     location.href = href;
647 }
648
649 function uEditRefreshXUL(newuser) {
650         if (window.xulG && typeof window.xulG.on_save == 'function') 
651                 window.xulG.on_save(newuser);
652 }
653
654
655 function uEditNewAddr(evt, id) {
656     if(id == null) id = --uEditAddrVirtId;
657     dojo.forEach(addrTemplateRows, 
658         function(row) {
659
660             row = tbody.insertBefore(row.cloneNode(true), dojo.byId('new-addr-row'));
661             row.setAttribute('type', '');
662             row.setAttribute('addr', id+'');
663
664             if(row.getAttribute('fmclass')) {
665                 fleshFMRow(row, 'aua', {addr:id});
666
667             } else if(row.getAttribute('name') == 'uedit-addr-pending-row') {
668
669                 var addr =  patron.addresses().filter(
670                     function(i) { return (i.id() == id) })[0];
671                 
672                 // if it's a pending address, show the 'approve' button
673                 if(addr && openils.Util.isTrue(addr.pending())) {
674                     openils.Util.show(row, 'table-row');
675                     dojo.query('[name=approve-button]', row)[0].onclick = 
676                         function() { uEditApproveAddress(addr); };
677
678                     if(addr.replaces()) {
679                         var div = dojo.query('[name=replaced-addr]', row)[0]
680                         div.innerHTML = addr.replaces();
681                     } else {
682                         openils.Util.hide(dojo.query('[name=replaced-addr-div]', row)[0]);
683                     }
684                 }
685
686             } else {
687                 var btn = dojo.query('[name=delete-button]', row)[0];
688                 if(btn) btn.onclick = function(){ uEditDeleteAddr(id) };
689             }
690         }
691     );
692 }
693
694 function uEditApproveAddress(addr) {
695     fieldmapper.standardRequest(
696         ['open-ils.actor', 'open-ils.actor.user.pending_address.approve'],
697         {   async: true,
698             params:  [openils.User.authtoken, addr],
699
700             oncomplete : function(r) {
701                 var oldId = openils.Util.readResponse(r);
702                     
703                 // remove addrs from UI
704                 dojo.forEach(
705                     patron.addresses(), 
706                     function(addr) { uEditDeleteAddr(addr.id(), true); }
707                 );
708
709                 if(oldId != null) {
710                     
711                     // remove the replaced address 
712                     if(oldId != addr.id()) {
713                                 patron.addresses(
714                             patron.addresses().filter(
715                                                 function(i) { return (i.id() != oldId); }
716                                         )
717                                 );
718                     }
719                     
720                     // fix the the new address
721                     addr.id(oldId);
722                     addr.replaces(null);
723                     addr.pending('f');
724
725                 }
726
727                 // redraw addrs
728                 loadAllAddrs();
729             }
730         }
731     );
732 }
733
734
735 function uEditDeleteAddr(id, noAlert) {
736     if(!noAlert) {
737         if(!confirm('Delete address ' + id)) return; /* XXX i18n */
738     }
739     var rows = dojo.query('tr[addr='+id+']', tbody);
740     for(var i = 0; i < rows.length; i++)
741         rows[i].parentNode.removeChild(rows[i]);
742     widgetPile = widgetPile.filter(function(w){return (w._addr != id)});
743 }
744
745 function uEditToggleRequired() {
746     if((tbody.className +'').match(/hide-non-required/)) 
747         openils.Util.removeCSSClass(tbody, 'hide-non-required');
748     else
749         openils.Util.addCSSClass(tbody, 'hide-non-required');
750     openils.Util.toggle('uedit-show-required');
751     openils.Util.toggle('uedit-show-all');
752 }
753
754
755
756 openils.Util.addOnLoad(load);