1 dojo.require('dojo.data.ItemFileReadStore');
2 dojo.require('dijit.form.Form');
3 dojo.require('dijit.form.Textarea');
4 dojo.require('dijit.form.FilteringSelect');
5 dojo.require('dijit.form.ComboBox');
6 dojo.require('dijit.form.NumberSpinner');
7 dojo.require('fieldmapper.IDL');
8 dojo.require('openils.PermaCrud');
9 dojo.require('openils.widget.AutoGrid');
10 dojo.require('openils.widget.AutoFieldWidget');
11 dojo.require('dijit.form.CheckBox');
12 dojo.require('dijit.form.Button');
13 dojo.require('dojo.date');
14 dojo.require('openils.CGI');
15 dojo.require('openils.XUL');
16 dojo.require('openils.Util');
17 dojo.require('openils.Event');
19 dojo.requireLocalization('openils.actor', 'register');
20 var localeStrings = dojo.i18n.getLocalization('openils.actor', 'register');
24 var fmClasses = ['au', 'ac', 'aua', 'actsc', 'asv', 'asvq', 'asva'];
31 var uEditUsePhonePw = false;
33 var uEditCardVirtId = -1;
34 var uEditAddrVirtId = -1;
36 var userSettings = {};
37 var userSettingsToUpdate = {};
47 var uEditCloneCopyAddr; // if true, copy addrs on clone instead of link
50 var dupeUsrname = false;
51 var dupeBarcode = false;
53 if(!window.xulG) var xulG = null;
54 var lock_ready = false;
55 var already_locked = false;
58 staff = new openils.User().user;
59 pcrud = new openils.PermaCrud();
60 cgi = new openils.CGI();
61 cloneUser = cgi.param('clone');
62 var userId = cgi.param('usr');
63 var stageUname = cgi.param('stage');
65 saveButton.attr("label", localeStrings.SAVE);
66 saveCloneButton.attr("label", localeStrings.SAVE_CLONE);
67 replaceBarcode.attr("label", localeStrings.REPLACE_BARCODE);
68 dojo.byId('uedit-show-required').innerHTML = localeStrings.SHOW_REQUIRED;
69 dojo.byId('uedit-show-suggested').innerHTML = localeStrings.SHOW_SUGGESTED;
70 dojo.byId('uedit-show-all').innerHTML = localeStrings.SHOW_ALL;
71 dojo.byId('uedit-dupe-barcode-warning').innerHTML = localeStrings.BARCODE_IN_USE;
72 allCards.attr("label", localeStrings.SEE_ALL);
73 dojo.byId('uedit-dupe-username-warning').innerHTML = localeStrings.DUPE_USERNAME;
74 generatePassword.attr("label", localeStrings.RESET_PASSWORD);
75 dojo.byId('verifyPassword').innerHTML = localeStrings.VERIFY_PASSWORD;
76 dojo.byId('parentGuardian').innerHTML = localeStrings.PARENT_OR_GUARDIAN;
77 dojo.byId('userSettings').innerHTML = localeStrings.USER_SETTINGS;
78 dojo.byId('statCats').innerHTML = localeStrings.STAT_CATS;
80 dojo.query("td[name='addressHeader']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_HEADER; });
81 dojo.query("span[name='mailingAddress']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_MAILING; });
82 dojo.query("span[name='billingAddress']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_BILLING; });
83 dojo.query("span[name='addressPending']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_PENDING; });
84 dojo.query("button[name='approve-button']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_APPROVE; });
85 dojo.query("span[name='address-already-owned']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_OWNED; });
86 dojo.query("button[name='addressNew']").forEach( function(item) { item.innerHTML = localeStrings.ADDRESS_NEW; });
89 if(xulG.ses) openils.User.authtoken = xulG.ses;
90 if(typeof xulG.clone != 'undefined') cloneUser = xulG.clone;
91 if(typeof xulG.usr != 'undefined') userId = xulG.usr
92 if(typeof xulG.params != 'undefined') {
93 var parms = xulG.params;
94 if(typeof parms.ses != 'undefined')
95 openils.User.authtoken = parms.ses;
96 if(typeof parms.clone != 'undefined')
97 cloneUser = parms.clone;
98 if(typeof parms.usr != 'undefined')
100 if(typeof parms.stage != 'undefined')
101 stageUname = parms.stage
105 orgSettings = fieldmapper.aou.fetchOrgSettingBatch(staff.ws_ou(), [
106 'global.password_regex',
107 'global.juvenile_age_threshold',
108 'patron.password.use_phone',
109 'ui.patron.default_inet_access_level',
110 'ui.patron.default_ident_type',
111 'ui.patron.default_country',
112 'ui.patron.registration.require_address',
113 'circ.holds.behind_desk_pickup_supported',
114 'circ.patron_edit.clone.copy_address',
115 'ui.patron.edit.au.second_given_name.show',
116 'ui.patron.edit.au.second_given_name.suggest',
117 'ui.patron.edit.au.suffix.show',
118 'ui.patron.edit.au.suffix.suggest',
119 'ui.patron.edit.au.alias.show',
120 'ui.patron.edit.au.alias.suggest',
121 'ui.patron.edit.au.dob.require',
122 'ui.patron.edit.au.dob.show',
123 'ui.patron.edit.au.dob.suggest',
124 'ui.patron.edit.au.dob.calendar',
125 'ui.patron.edit.au.juvenile.show',
126 'ui.patron.edit.au.juvenile.suggest',
127 'ui.patron.edit.au.ident_value.show',
128 'ui.patron.edit.au.ident_value.suggest',
129 'ui.patron.edit.au.ident_value2.show',
130 'ui.patron.edit.au.ident_value2.suggest',
131 'ui.patron.edit.au.email.require',
132 'ui.patron.edit.au.email.show',
133 'ui.patron.edit.au.email.suggest',
134 'ui.patron.edit.au.email.regex',
135 'ui.patron.edit.au.email.example',
136 'ui.patron.edit.au.day_phone.require',
137 'ui.patron.edit.au.day_phone.show',
138 'ui.patron.edit.au.day_phone.suggest',
139 'ui.patron.edit.au.day_phone.regex',
140 'ui.patron.edit.au.day_phone.example',
141 'ui.patron.edit.au.evening_phone.require',
142 'ui.patron.edit.au.evening_phone.show',
143 'ui.patron.edit.au.evening_phone.suggest',
144 'ui.patron.edit.au.evening_phone.regex',
145 'ui.patron.edit.au.evening_phone.example',
146 'ui.patron.edit.au.other_phone.require',
147 'ui.patron.edit.au.other_phone.show',
148 'ui.patron.edit.au.other_phone.suggest',
149 'ui.patron.edit.au.other_phone.regex',
150 'ui.patron.edit.au.other_phone.example',
151 'ui.patron.edit.phone.regex',
152 'ui.patron.edit.phone.example',
153 'ui.patron.edit.au.active.show',
154 'ui.patron.edit.au.active.suggest',
155 'ui.patron.edit.au.barred.show',
156 'ui.patron.edit.au.barred.suggest',
157 'ui.patron.edit.au.master_account.show',
158 'ui.patron.edit.au.master_account.suggest',
159 'ui.patron.edit.au.claims_returned_count.show',
160 'ui.patron.edit.au.claims_returned_count.suggest',
161 'ui.patron.edit.au.claims_never_checked_out_count.show',
162 'ui.patron.edit.au.claims_never_checked_out_count.suggest',
163 'ui.patron.edit.au.alert_message.show',
164 'ui.patron.edit.au.alert_message.suggest',
165 'ui.patron.edit.aua.post_code.regex',
166 'ui.patron.edit.aua.post_code.example',
167 'ui.patron.edit.aua.county.require',
169 'ui.patron.edit.default_suggested',
170 'opac.barcode_regex',
171 'opac.username_regex'
174 for(k in orgSettings)
176 orgSettings[k] = orgSettings[k].value;
178 uEditCloneCopyAddr = orgSettings['circ.patron_edit.clone.copy_address'];
179 uEditUsePhonePw = orgSettings['patron.password.use_phone'];
180 uEditFetchUserSettings(userId);
183 patron = uEditLoadUser(userId);
186 patron = uEditLoadStageUser(stageUname);
188 patron = uEditNewPatron();
190 uEditCopyCloneData(patron);
195 var list = pcrud.search('fdoc', {fm_class:fmClasses});
198 if(!fieldDoc[doc.fm_class()])
199 fieldDoc[doc.fm_class()] = {};
200 fieldDoc[doc.fm_class()][doc.field()] = doc;
203 list = pcrud.search('aout', {can_have_users: 'true'});
206 homeOuTypes[type.id()] = true;
209 tbody = dojo.byId('uedit-tbody');
211 if(orgSettings['ui.patron.edit.default_suggested'])
212 uEditToggleRequired(2);
214 addrTemplateRows = dojo.query('tr[type=addr-template]', tbody);
215 dojo.forEach(addrTemplateRows, function(row) { row.parentNode.removeChild(row); } );
216 statCatTemplate = tbody.removeChild(dojo.byId('stat-cat-row-template'));
217 surveyTemplate = tbody.removeChild(dojo.byId('survey-row-template'));
218 surveyQuestionTemplate = tbody.removeChild(dojo.byId('survey-question-row-template'));
220 checkGrpAppPerm(); // to do the initial load
224 if(patron.isnew() && patron.addresses().length == 0)
225 uEditNewAddr(null, uEditAddrVirtId, true);
229 checkClaimsReturnCountPerm();
230 checkClaimsNoCheckoutCountPerm();
232 dojo.connect(replaceBarcode, 'onClick', replaceCardHandler);
233 dojo.connect(allCards, 'onClick', drawAllCards);
234 if(patron.cards().length > 1)
235 dojo.removeClass(dojo.byId('uedit-all-barcodes'), 'hidden');
237 var input = findWidget('ac', 'barcode');
238 if (patron.isnew()) {
239 replaceBarcode.attr('disabled', true);
241 input.widget.attr('disabled', true).attr('readOnly', true);
244 dojo.connect(generatePassword, 'onClick', generatePasswordHandler);
246 if(!patron.isnew() && !checkGrpAppPerm(patron.profile()) && patron.id() != openils.User.user.id()) {
247 // we are not allowed to edit this user, so disable the save option
248 saveButton.attr('disabled', true);
249 saveCloneButton.attr('disabled', true);
256 var noPermGroups = [];
257 // Returns true if the user is allowed to edit the selected group
258 function checkGrpAppPerm(grpId) {
263 permGroups = new openils.PermaCrud().retrieveAll('pgt');
264 var permGroupPerms = []
266 // collect the group permissions
267 dojo.forEach(permGroups,
269 if(grp.application_perm())
270 permGroupPerms.push(grp.application_perm());
274 // see which of the group application perms I do not have
275 var myPerms = fieldmapper.standardRequest(
276 ['open-ils.actor', 'open-ils.actor.user.has_work_perm_at.batch'],
277 [openils.User.authtoken, permGroupPerms]
280 var failedPerms = [];
281 for(var p in myPerms) {
282 if(myPerms[p].length == 0)
286 // identify which groups I cannot edit because I do not have permisssion
288 function checkTree(grp, failed) {
289 failed = failed || failedPerms.indexOf(grp.application_perm()) > -1;
290 if(failed) noPermGroups.push(grp.id()+'');
292 permGroups.filter(function(g) { return g.parent() == grp.id() } ),
294 checkTree(child, failed);
299 checkTree(permGroups.filter(function(g) { return g.parent() == null })[0]);
302 return noPermGroups.indexOf(grpId+'') == -1;
306 function drawAllCards() {
308 var tbody = dojo.byId('uedit-all-cards-tbody');
309 if(!allCardsTemplate) {
310 allCardsTemplate = tbody.removeChild(dojo.byId('uedit-all-cards-tr-template'));
312 while(tbody.childNodes[0])
313 tbody.removeChild(tbody.childNodes[0]);
318 [patron.card()].concat(patron.cards()), // grab the main card first
321 if(card.id() == patron.card().id())
324 var row = allCardsTemplate.cloneNode(true);
325 getByName(row, 'barcode').innerHTML = card.barcode();
326 getByName(row, 'active').appendChild(
327 openils.Util.isTrue(card.active()) ?
328 dojo.byId('true').cloneNode(true) :
329 dojo.byId('false').cloneNode(true)
332 tbody.appendChild(row);
337 allCardsDialog.show();
341 * Mark the current card inactive, create a new primary card
343 function replaceCardHandler() {
344 var input = findWidget('ac', 'barcode');
345 input.widget.attr('disabled', false).attr('readOnly', false).attr('value', null).focus();
346 replaceBarcode.attr('disabled', true);
348 // pull old card off the cards list so we don't have a dupe sitting in there
349 if (patron.cards().length > 0) {
350 var old = patron.cards().filter(function(c){return (c.id() == patron.card().id())})[0];
355 var newc = new fieldmapper.ac();
356 newc.id(uEditCardVirtId--);
360 var t = patron.cards();
367 * Generate a random password for the patron.
369 function generatePasswordHandler() {
370 uEditMakeRandomPw(patron);
371 var f = findWidget('au', 'passwd');
372 f.widget.attr('value', patron.passwd());
373 f = findWidget('au', 'passwd2');
374 f.widget.attr('value', patron.passwd());
378 * Loads a staged user and turns them into something the editor can understand
380 function uEditLoadStageUser(stageUname) {
382 var data = fieldmapper.standardRequest(
383 ['open-ils.actor', 'open-ils.actor.user.stage.retrieve.by_username'],
384 { params : [openils.User.authtoken, stageUname] }
387 stageUser = data.user;
388 patron = uEditNewPatron();
393 // copy the data into our new user object
394 for(var key in fieldmapper.IDL.fmclasses.stgu.field_map) {
395 if(fieldmapper.IDL.fmclasses.au.field_map[key] && !fieldmapper.IDL.fmclasses.stgu.field_map[key].virtual) {
396 if(data.user[key]() !== null)
397 patron[key]( data.user[key]() );
401 // copy the data into our new address objects
402 // TODO: uses the first mailing address only
403 if(data.mailing_addresses.length) {
405 var mail_addr = new fieldmapper.aua();
406 mail_addr.id(-1); // virtual ID
409 patron.mailing_address(mail_addr);
410 var t = patron.addresses();
415 for(var key in fieldmapper.IDL.fmclasses.stgma.field_map) {
416 if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgma.field_map[key].virtual) {
417 if(data.mailing_addresses[0][key]() !== null)
418 mail_addr[key]( data.mailing_addresses[0][key]() );
423 // copy the data into our new address objects
424 // TODO uses the first billing address only
425 if(data.billing_addresses.length) {
427 var bill_addr = new fieldmapper.aua();
428 bill_addr.id(-2); // virtual ID
431 patron.billing_address(bill_addr);
432 var t = patron.addresses();
437 for(var key in fieldmapper.IDL.fmclasses.stgba.field_map) {
438 if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgba.field_map[key].virtual) {
439 if(data.billing_addresses[0][key]() !== null)
440 bill_addr[key]( data.billing_addresses[0][key]() );
445 // TODO: uses the first card only
446 if(data.cards.length) {
447 var card = new fieldmapper.ac();
448 card.id(-1); // virtual ID
449 patron.card().barcode(data.cards[0].barcode());
456 * clone the home org, phone numbers, and billing/mailing address
458 function uEditCopyCloneData(patron) {
459 cloneUserObj = uEditLoadUser(cloneUser);
469 if(!uEditCloneCopyAddr)
470 cloneFields = cloneFields.concat(['mailing_address', 'billing_address']);
475 patron[field](cloneUserObj[field]());
479 if(uEditCloneCopyAddr) {
480 var billAddr, mailAddr;
482 // copy the billing and mailing addresses into new addresses
483 function cloneAddr(addr) {
484 var newAddr = addr.clone();
486 newAddr.id(uEditAddrVirtId--);
487 newAddr.usr(patron.id());
488 patron.addresses().push(newAddr);
492 if(billAddr = cloneUserObj.billing_address())
493 patron.billing_address(cloneAddr(billAddr));
495 if(mailAddr = cloneUserObj.mailing_address()) {
496 if (billAddr && billAddr.id() == mailAddr.id()) {
497 patron.mailing_address(patron.billing_address());
499 patron.mailing_address(cloneAddr(mailAddr));
503 if(!billAddr) // if there was no billing addr, use the mailing addr
504 patron.billing_address(patron.mailing_address());
508 // link the billing and mailing addresses
509 if(patron.billing_address()) {
510 var t = patron.addresses();
512 t.push(patron.billing_address());
516 if(patron.mailing_address() && (
517 patron.addresses().length == 0 ||
518 patron.mailing_address().id() != patron.billing_address().id()) ) {
519 var t = patron.addresses();
521 t.push(patron.mailing_address());
528 function uEditFetchUserSettings(userId) {
530 var baseNode = fieldmapper.aou.findOrgUnit(staff.ws_ou());
531 var orgs = fieldmapper.aou.orgNodeTrail(baseNode);
532 orgs = orgs.map(function(node) { return node.id(); });
534 /* fetch any user setting types we need + any that offer opt-in */
535 userSettingTypes = pcrud.search('cust', {
537 {name:['circ.holds_behind_desk', 'circ.collections.exempt']},
540 select : {atevdef : ['opt_in_setting']},
542 // we only care about opt-in settings for event_defs our users encounter
543 where : {'+atevdef' : {owner : orgs}}
549 var names = userSettingTypes.map(function(obj) { return obj.name() });
551 /* fetch any values set for this user */
553 userSettings = fieldmapper.standardRequest(
554 ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative'],
555 {params : [openils.User.authtoken, userId, names]});
560 function uEditLoadUser(userId) {
561 var patron = fieldmapper.standardRequest(
562 ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve.authoritative'],
563 {params : [openils.User.authtoken, userId]}
565 openils.Event.parse_and_raise(patron);
569 function loadStaticFields() {
570 for(var idx = 0; tbody.childNodes[idx]; idx++) {
571 var row = tbody.childNodes[idx];
572 if(row.nodeType != row.ELEMENT_NODE) continue;
573 var fmcls = row.getAttribute('fmclass');
575 fleshFMRow(row, fmcls);
578 if(row.id == 'uedit-settings-divider') {
580 var template = tbody.removeChild(dojo.byId('uedit-user-setting-template'));
581 dojo.forEach(userSettingTypes, function(type) { uEditDrawSettingRow(tbody, row, template, type); } );
583 if(userSettingTypes.length > 1 || orgSettings['circ.holds.behind_desk_pickup_supported']) {
584 openils.Util.show('uedit-settings-divider', 'table-row');
591 function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
592 var row = template.cloneNode(true);
593 row.setAttribute('user_setting', stype.name());
594 getByName(row, 'label').innerHTML = stype.label();
595 var cb = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'widget'));
596 cb.attr('value', userSettings[stype.name()]);
597 dojo.connect(cb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; });
598 tbody.insertBefore(row, dividerRow.nextSibling);
599 openils.Util.show(row, 'table-row');
601 if(stype.name() == 'circ.collections.exempt') {
602 checkCollectionsExemptPerm(cb);
606 function uEditUpdateUserSettings(userId) {
607 return fieldmapper.standardRequest(
608 ['open-ils.actor', 'open-ils.actor.patron.settings.update'],
609 {params : [openils.User.authtoken, userId, userSettingsToUpdate]});
612 function loadAllAddrs() {
613 dojo.forEach(patron.addresses(),
615 uEditNewAddr(null, addr.id());
620 function loadStatCats() {
622 statCats = fieldmapper.standardRequest(
623 ['open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all'],
624 {params : [openils.User.authtoken, staff.ws_ou()]}
628 for(var idx in statCats) {
629 var stat = statCats[idx];
630 var row = statCatTemplate.cloneNode(true);
631 row.id = 'stat-cat-row-' + idx;
632 row.setAttribute('stat_cat_owner',stat.owner());
633 row.setAttribute('stat_cat_name',stat.name());
634 row.setAttribute('stat_cat_id',stat.id());
635 tbody.appendChild(row);
636 getByName(row, 'name').innerHTML = stat.name();
637 var valtd = getByName(row, 'widget');
638 var span = valtd.appendChild(document.createElement('span'));
639 var store = new dojo.data.ItemFileReadStore(
640 {data:fieldmapper.actsc.toStoreData(stat.entries())});
641 var comboBox = new dijit.form.ComboBox({store:store,scrollOnFocus:false,fetchProperties:{sort:[{attribute: 'value'}]}}, span);
642 comboBox.labelAttr = 'value';
643 comboBox.searchAttr = 'value';
645 comboBox._wtype = 'statcat';
646 comboBox._statcat = stat.id();
647 widgetPile.push(comboBox);
649 // populate existing cats
650 var map = patron.stat_cat_entries().filter(
651 function(mp) { return (mp.stat_cat() == stat.id()) })[0];
652 if(map) comboBox.attr('value', map.stat_cat_entry());
657 function loadSurveys() {
659 surveys = fieldmapper.standardRequest(
660 ['open-ils.circ', 'open-ils.circ.survey.retrieve.all'],
661 {params : [openils.User.authtoken]}
665 for(var idx in surveys) {
666 var survey = surveys[idx];
667 var required = openils.Util.isTrue(survey.required());
668 var srow = surveyTemplate.cloneNode(true);
669 if(required) srow.setAttribute('required','required');
670 tbody.appendChild(srow);
671 getByName(srow, 'name').innerHTML = survey.name();
673 for(var q in survey.questions()) {
674 var quest = survey.questions()[q];
675 var qrow = surveyQuestionTemplate.cloneNode(true);
676 if(required) qrow.setAttribute('required','required');
677 tbody.appendChild(qrow);
678 getByName(qrow, 'question').innerHTML = quest.question();
680 var span = getByName(qrow, 'answers').appendChild(document.createElement('span'));
681 var store = new dojo.data.ItemFileReadStore(
682 {data:fieldmapper.asva.toStoreData(quest.answers())});
683 var select = new dijit.form.FilteringSelect({store:store,scrollOnFocus:false}, span);
685 select.isValid = function() { return true; };
687 select.labelAttr = 'answer';
688 select.searchAttr = 'answer';
690 select._wtype = 'survey';
691 select._survey = survey.id();
692 select._question = quest.id();
693 widgetPile.push(select);
699 function fleshFMRow(row, fmcls, args) {
700 var fmfield = row.getAttribute('fmfield');
701 var wclass = row.getAttribute('wclass');
702 var wstyle = row.getAttribute('wstyle');
703 var wconstraints = row.getAttribute('wconstraints');
704 /* use CSS to set the zindex for widgets you want to disable. */
705 var disabled = dojo.style(row, 'zIndex') == -1 ? true : false;
706 var isphone = (fmcls == 'au') && (fmfield.search('_phone') != -1);
708 var isPasswd2 = (fmfield == 'passwd2');
709 if(isPasswd2) fmfield = 'passwd';
710 var fieldIdl = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield];
713 var existing = dojo.query('td', row);
714 var htd = existing[0] || row.appendChild(document.createElement('td'));
715 var ltd = existing[1] || row.appendChild(document.createElement('td'));
716 var wtd = existing[2] || row.appendChild(document.createElement('td'));
717 var ftd = existing[3] || row.appendChild(document.createElement('td'));
719 openils.Util.addCSSClass(htd, 'uedit-help');
720 if(fieldDoc[fmcls] && fieldDoc[fmcls][fmfield]) {
721 var link = dojo.byId('uedit-help-template').cloneNode(true);
723 link.onclick = function() { ueLoadContextHelp(fmcls, fmfield) };
724 openils.Util.removeCSSClass(link, 'hidden');
725 htd.appendChild(link);
728 if(!ltd.textContent) {
729 ltd.appendChild(document.createTextNode(fieldIdl.label));
732 if(!ftd.textContent) {
733 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.example']) {
734 ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.example']));
736 else if(isphone && orgSettings['ui.patron.edit.phone.example']) {
737 ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + orgSettings['ui.patron.edit.phone.example']));
739 else if(fieldIdl.datatype == 'timestamp') {
740 ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + dojo.date.locale.format(new Date(1970,0,31),{selector: "date", fullYear: true, datePattern: (orgSettings['format.date'] ? orgSettings['format.date'] : null)})));
744 var span = document.createElement('span');
745 wtd.appendChild(span);
749 case 'au' : fmObject = patron; break;
750 case 'ac' : fmObject = patron.card(); break;
752 fmObject = patron.addresses().filter(
753 function(i) { return (i.id() == args.addr) })[0];
754 if(fmObject && fmObject.usr() != patron.id())
759 // Adjust required value by org settings
760 var curRequired = row.getAttribute('required');
761 var required = curRequired == 'required';
762 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.require']) {
763 row.setAttribute('required', 'required');
766 else if (curRequired != 'required' && orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.show']) {
767 row.setAttribute('required', 'show');
769 else if (curRequired != 'required' && curRequired != 'show' && orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.suggest']) {
770 row.setAttribute('required', 'suggested');
773 // password data is not fetched/required/displayed for existing users
774 if(!patron.isnew() && 'passwd' == fmfield)
780 constraints : (wconstraints) ? eval('('+wconstraints+')') : {}, // the ()'s prevent Invalid Label errors with eval
784 // Org settings provided regex?
785 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.regex']) {
786 dijitArgs.regExp = orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.regex'];
788 else if(isphone && orgSettings['ui.patron.edit.phone.regex']) {
789 dijitArgs.regExp = orgSettings['ui.patron.edit.phone.regex'];
792 if(fmcls == 'au' && fmfield == 'passwd') {
793 if (orgSettings['global.password_regex']) {
794 dijitArgs.regExp = orgSettings['global.password_regex'];
798 if(fmcls == 'au' && fmfield == 'dob' && !orgSettings['ui.patron.edit.au.dob.calendar'])
799 dijitArgs.popupClass = "";
801 var value = row.getAttribute('wvalue');
803 dijitArgs.value = value;
810 widgetClass : wclass,
811 dijitArgs : dijitArgs,
812 orgDefaultsToWs : true,
813 orgLimitPerms : ['UPDATE_USER'],
816 if(fmfield == 'profile') {
817 // fetch profile groups non-async so existing expire_date is
818 // not overwritten when the profile groups arrive and update
819 wargs.forceSync = true;
820 wargs.disableQuery = {usergroup : 'f'};
821 if(!patron.isnew() && !checkGrpAppPerm(patron.profile()))
822 wargs.readOnly = true;
824 wargs.forceSync = false;
827 if(fmcls == 'au' && fmfield == 'home_ou'){
828 wargs.labelAttr = 'name';
829 wargs.searchAttr = 'name';
832 var widget = new openils.widget.AutoFieldWidget(wargs);
835 if(fmfield == 'profile') { trimGrpTree(ww); }
839 // now put it back before we register the widget
840 if(isPasswd2) fmfield = 'passwd2';
842 widget._wtype = fmcls;
843 widget._fmfield = fmfield;
844 widget._addr = args.addr;
845 widgetPile.push(widget);
846 attachWidgetEvents(fmcls, fmfield, widget);
850 function trimGrpTree(autoWidget) {
851 var store = autoWidget.widget.store;
853 // remove all groups that this user are not allowed to edit,
854 // except the profile group of an existing user
855 store.fetch({onItem :
857 if(!checkGrpAppPerm(item.id[0]) && patron.profile() != item.id[0])
858 store.deleteItem(item);
863 function findWidget(wtype, fmfield, callback) {
864 return widgetPile.filter(
866 if(i._wtype == wtype && i._fmfield == fmfield) {
867 if(callback) return callback(i);
875 * if the user does not have the UPDATE_PATRON_CLAIM_RETURN_COUNT,
876 * they are not allowed to directly alter the claim return count.
877 * This function checks the perm and disable/enables the widget.
879 function checkClaimsReturnCountPerm() {
880 new openils.User().getPermOrgList(
881 'UPDATE_PATRON_CLAIM_RETURN_COUNT',
883 var cr = findWidget('au', 'claims_returned_count');
884 if(orgList.indexOf(patron.home_ou()) == -1)
885 cr.widget.attr('disabled', true);
887 cr.widget.attr('disabled', false);
895 function checkClaimsNoCheckoutCountPerm() {
896 new openils.User().getPermOrgList(
897 'UPDATE_PATRON_CLAIM_NEVER_CHECKED_OUT_COUNT',
899 var cr = findWidget('au', 'claims_never_checked_out_count');
900 if(orgList.indexOf(patron.home_ou()) == -1)
901 cr.widget.attr('disabled', true);
903 cr.widget.attr('disabled', false);
910 var collectExemptCBox;
911 function checkCollectionsExemptPerm(cbox) {
912 if(cbox) collectExemptCBox = cbox;
913 new openils.User().getPermOrgList(
914 'UPDATE_PATRON_COLLECTIONS_EXEMPT',
916 if(orgList.indexOf(patron.home_ou()) == -1)
917 collectExemptCBox.attr('disabled', true);
919 collectExemptCBox.attr('disabled', false);
926 function usePhonePw(newVal) {
929 matches = RegExp(this.regExp).exec(newVal);
930 if(matches.length > 1) newPw = matches[1];
932 if(!newPw && newVal && newVal.length >= 4) {
933 newPw = newVal.substring(newVal.length - 4);
936 var p1 = findWidget('au', 'passwd');
937 var p2 = findWidget('au', 'passwd2');
939 p1.widget.attr('value', newPw);
940 p2.widget.attr('value', newPw);
948 function attachWidgetEvents(fmcls, fmfield, widget) {
954 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
955 if (!(ev.altKey || ev.ctrlKey || ev.metaKey)) {
956 if (lock_ready && xulG && typeof xulG.lock_tab == 'function') {
957 if (! already_locked) {
959 already_locked = true;
969 if (lock_ready && xulG && typeof xulG.lock_tab == 'function') {
970 if (! already_locked) {
972 already_locked = true;
980 if(fmfield == 'barcode') {
981 dojo.connect(widget.widget, 'onChange',
983 var barcode = this.attr('value');
985 dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
986 fieldmapper.standardRequest(
987 ['open-ils.actor', 'open-ils.actor.barcode.exists'],
989 params: [openils.User.authtoken, barcode],
990 oncomplete : function(r) {
991 var res = openils.Util.readResponse(r);
994 dojo.removeClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
997 dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
998 var un = findWidget('au', 'usrname');
999 if(!un.widget.attr('value'))
1000 un.widget.attr('value', barcode);
1015 widget.widget.isValid = function() {
1017 if(this.attr("value").match(/\s/)) {
1020 // Can look like a barcode (for initial value)
1021 if(orgSettings['opac.barcode_regex']) {
1022 var test_regexp = new RegExp(orgSettings['opac.barcode_regex']);
1023 if(test_regexp.test(this.attr("value"))) {
1027 // Can look like a username
1028 if(orgSettings['opac.username_regex']) {
1029 var test_regexp = new RegExp(orgSettings['opac.username_regex']);
1030 if(test_regexp.test(this.attr("value"))) {
1034 // If we know what a barcode and username look like and we got here, reject
1035 if(orgSettings['opac.barcode_regex'] && orgSettings['opac.username_regex'])
1037 // Otherwise we don't have enough info to say either way, let it through.
1040 dojo.connect(widget.widget, 'onChange',
1042 var input = findWidget('au', 'usrname');
1043 var usrname = input.widget.attr('value');
1046 dupeUsrname = false;
1047 dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1051 fieldmapper.standardRequest(
1052 ['open-ils.actor', 'open-ils.actor.username.exists'],
1054 params: [openils.User.authtoken, usrname],
1055 oncomplete : function(r) {
1056 var res = openils.Util.readResponse(r);
1059 dojo.removeClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1061 dupeUsrname = false;
1062 dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1072 case 'profile': // when the profile changes, update the expire date
1073 dojo.connect(widget.widget, 'onChange',
1076 var expireWidget = findWidget('au', 'expire_date');
1077 function found(items) {
1078 if(items.length == 0) return;
1079 var item = items[0];
1080 var interval = self.store.getValue(item, 'perm_interval');
1081 expireWidget.widget.attr('value', dojo.date.add(new Date(),
1082 'second', openils.Util.intervalToSeconds(interval)));
1084 this.store.fetch({onComplete:found, query:{id:this.attr('value')}});
1090 widget.widget.isValid = function() {
1091 return this.attr("value") < new Date();
1093 dojo.connect(widget.widget, 'onChange',
1096 var oldDob = patron.dob();
1097 if(dojo.date.stamp.fromISOString(oldDob) == newDob) return;
1099 var juvInterval = orgSettings['global.juvenile_age_threshold'] || '18 years';
1100 var juvWidget = findWidget('au', 'juvenile');
1101 var base = new Date();
1102 base.setTime(base.getTime() - Number(openils.Util.intervalToSeconds(juvInterval) + '000'));
1104 if(newDob <= base) // older than global.juvenile_age_threshold
1105 juvWidget.widget.attr('value', false);
1107 juvWidget.widget.attr('value', true);
1112 case 'first_given_name':
1114 dojo.connect(widget.widget, 'onChange',
1115 function(newVal) { uEditDupeSearch('name', newVal); });
1119 dojo.connect(widget.widget, 'onChange',
1120 function(newVal) { uEditDupeSearch('email', newVal); });
1124 case 'ident_value2':
1125 dojo.connect(widget.widget, 'onChange',
1126 function(newVal) { uEditDupeSearch('ident', newVal); });
1130 // if configured, use the last four digits of the day phone number as the password
1131 // Alt, use the first capture group of the validator regex
1132 if(uEditUsePhonePw && patron.isnew()) {
1133 dojo.connect(widget.widget, 'onChange', widget.widget, usePhonePw);
1134 if (patron.day_phone()) {
1135 usePhonePw(patron.day_phone());
1138 case 'evening_phone':
1140 dojo.connect(widget.widget, 'onChange',
1141 function(newVal) { uEditDupeSearch('phone', newVal); });
1145 widget.widget.isValid = function() {
1147 if(homeOuTypes[this.store.getValue(this.item, 'ou_type')]) {
1154 dojo.connect(widget.widget, 'onChange',
1156 checkClaimsReturnCountPerm();
1157 checkClaimsNoCheckoutCountPerm();
1158 checkCollectionsExemptPerm();
1164 dojo.connect(widget.widget, 'onChange',
1166 var pw1 = findWidget('au', 'passwd').widget;
1167 var pw2 = findWidget('au', 'passwd2').widget;
1168 var preserved_value = pw2.attr('value');
1169 // Ensure that the pw2 field match the pw1 field to validate
1170 pw2.regExp = newVal.replace(/([.\\^$*+?\(\)\[\]\{\}])/g, '\\$1');
1172 pw2.attr('value',preserved_value);
1178 if(fmclass = 'aua') {
1181 dojo.connect(widget.widget, 'onChange',
1183 fieldmapper.standardRequest(
1184 ['open-ils.search', 'open-ils.search.zip'],
1187 oncomplete : function(r) {
1188 var res = openils.Util.readResponse(r);
1190 var callback = function(w) { return w._addr == widget._addr; };
1191 if(res.city) findWidget('aua', 'city', callback).widget.attr('value', res.city);
1192 if(res.state) findWidget('aua', 'state', callback).widget.attr('value', res.state);
1193 if(res.county) findWidget('aua', 'county', callback).widget.attr('value', res.county);
1194 if(res.alert) alert(res.alert);
1205 dojo.connect(widget.widget, 'onChange',
1207 var callback = function(w) { return w._addr == widget._addr; };
1209 street1 : findWidget('aua', 'street1', callback).widget.attr('value'),
1210 street2 : findWidget('aua', 'street2', callback).widget.attr('value'),
1211 city : findWidget('aua', 'city', callback).widget.attr('value'),
1212 post_code : findWidget('aua', 'post_code', callback).widget.attr('value')
1214 if(args.street1 && args.city && args.post_code)
1215 uEditDupeSearch('address', args);
1223 function uEditDupeSearch(type, value) {
1229 openils.Util.hide('uedit-dupe-names-link');
1230 var fname = findWidget('au', 'first_given_name').widget.attr('value');
1231 var lname = findWidget('au', 'family_name').widget.attr('value');
1232 if( !(fname && lname) ) return;
1234 first_given_name : {value : fname, group : 0},
1235 family_name : {value : lname, group : 0},
1240 openils.Util.hide('uedit-dupe-email-link');
1241 search = {email : {value : value, group : 0}};
1245 openils.Util.hide('uedit-dupe-ident-link');
1246 search = {ident : {value : value, group : 2}};
1250 openils.Util.hide('uedit-dupe-phone-link');
1251 search = {phone : {value : value, group : 2}};
1255 openils.Util.hide('uedit-dupe-address-link');
1257 dojo.forEach(['street1', 'street2', 'city', 'post_code'],
1260 search[field] = {value : value[field], group: 1};
1266 // find possible duplicate patrons
1267 fieldmapper.standardRequest(
1268 ['open-ils.actor', 'open-ils.actor.patron.search.advanced'],
1270 params: [openils.User.authtoken, search],
1271 oncomplete : function(r) {
1272 var resp = openils.Util.readResponse(r);
1273 resp = resp.filter(function(id) { return (id != patron.id()); });
1275 if(resp && resp.length > 0) {
1277 openils.Util.hide('uedit-help-div');
1278 openils.Util.show('uedit-dupe-div');
1283 link = dojo.byId('uedit-dupe-names-link');
1284 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_NAME, [resp.length]);
1287 link = dojo.byId('uedit-dupe-email-link');
1288 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_EMAIL, [resp.length]);
1291 link = dojo.byId('uedit-dupe-ident-link');
1292 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_IDENT, [resp.length]);
1295 link = dojo.byId('uedit-dupe-phone-link');
1296 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_PHONE, [resp.length]);
1299 link = dojo.byId('uedit-dupe-address-link');
1300 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_ADDR, [resp.length]);
1304 openils.Util.show(link);
1305 link.onclick = function() {
1306 search.search_sort = js2JSON(["penalties", "family_name", "first_given_name"]);
1308 window.xulG.spawn_search(search);
1310 console.log("running XUL patron search " + js2JSON(search));
1318 function getByName(node, name) {
1319 return dojo.query('[name='+name+']', node)[0];
1323 function ueLoadContextHelp(fmcls, fmfield) {
1324 openils.Util.hide('uedit-dupe-div');
1325 openils.Util.show('uedit-help-div');
1326 dojo.byId('uedit-help-field').innerHTML = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield].label;
1327 dojo.byId('uedit-help-text').innerHTML = fieldDoc[fmcls][fmfield].string();
1331 /* creates a new patron object with card attached */
1332 function uEditNewPatron() {
1337 card.id(uEditCardVirtId--);
1341 patron.cards([card]);
1342 patron.net_access_level(orgSettings['ui.patron.default_inet_access_level'] || 1);
1343 patron.ident_type(orgSettings['ui.patron.default_ident_type']);
1344 patron.stat_cat_entries([]);
1345 patron.survey_responses([]);
1346 patron.addresses([]);
1347 uEditMakeRandomPw(patron);
1351 function uEditMakeRandomPw(patron) {
1352 var rand = Math.random();
1353 rand = parseInt(rand * 10000) + '';
1354 while(rand.length < 4) rand += '0';
1356 appendClear($('ue_password_plain'),text(rand));
1357 unHideMe($('ue_password_gen'));
1359 patron.passwd(rand);
1363 function uEditWidgetVal(w) {
1364 var val = (w.getFormattedValue) ? w.getFormattedValue() : w.attr('value');
1365 if(val === '') val = null;
1369 function uEditSave() { _uEditSave(); }
1370 function uEditSaveClone() { _uEditSave(true); }
1372 function _uEditSave(doClone) {
1374 if ( (! myForm.isValid()) || dupeUsrname || dupeBarcode ) {
1375 alert(localeStrings.INVALID_FORM);
1379 for(var idx in widgetPile) {
1380 var w = widgetPile[idx];
1381 var val = uEditWidgetVal(w);
1385 if(w._fmfield != 'passwd2')
1386 patron[w._fmfield](val);
1390 patron.card()[w._fmfield](val);
1394 var addr = patron.addresses().filter(function(i){return (i.id() == w._addr)})[0];
1396 addr = new fieldmapper.aua();
1399 addr.usr(patron.id());
1400 addr.country(orgSettings['ui.patron.default_country']);
1401 var t = patron.addresses();
1404 patron.addresses(t);
1406 if(addr[w._fmfield]() != val)
1409 addr[w._fmfield](val);
1411 if(dojo.byId('uedit-billing-address-' + addr.id()).checked)
1412 patron.billing_address(addr.id());
1414 if(dojo.byId('uedit-mailing-address-' + addr.id()).checked)
1415 patron.mailing_address(addr.id());
1420 if(val == null) break;
1421 var resp = new fieldmapper.asvr();
1423 resp.survey(w._survey)
1424 resp.usr(patron.id());
1425 resp.question(w._question)
1427 var t = patron.survey_responses();
1430 patron.survey_responses(t);
1434 var map = patron.stat_cat_entries().filter(
1436 return (m.stat_cat() == w._statcat) })[0];
1439 if(map.stat_cat_entry() == val)
1450 map = new fieldmapper.actscecm();
1454 map.stat_cat(w._statcat);
1455 map.stat_cat_entry(val);
1456 map.target_usr(patron.id());
1457 var t = patron.stat_cat_entries();
1460 patron.stat_cat_entries(t);
1465 patron.ischanged(1);
1466 fieldmapper.standardRequest(
1467 ['open-ils.actor', 'open-ils.actor.patron.update'],
1469 params: [openils.User.authtoken, patron],
1470 oncomplete: function(r) {
1472 if (xulG && typeof xulG.unlock_tab == 'function') {
1474 already_locked = false;
1476 newPatron = openils.Util.readResponse(r);
1478 uEditUpdateUserSettings(newPatron.id());
1479 if(stageUser) uEditRemoveStage();
1480 uEditFinishSave(newPatron, doClone);
1487 function uEditRemoveStage() {
1488 var resp = fieldmapper.standardRequest(
1489 ['open-ils.actor', 'open-ils.actor.user.stage.delete'],
1490 { params : [openils.User.authtoken, stageUser.row_id()] }
1494 function uEditFinishSave(newPatron, doClone) {
1496 if(doClone && cloneUser == null)
1497 cloneUser = newPatron.id();
1501 if(xulG && typeof xulG.spawn_editor == 'function' && !patron.isnew() ) {
1502 window.xulG.spawn_editor({ses:openils.User.authtoken,clone:cloneUser});
1506 location.href = location.href.replace(/\?.*/, '') + '?clone=' + cloneUser;
1514 uEditRefreshXUL(newPatron);
1517 function uEditRefresh() {
1518 var usr = cgi.param('usr');
1519 var href = location.href.replace(/\?.*/, '');
1520 href += ((usr) ? '?usr=' + usr : '');
1521 location.href = href;
1524 function uEditRefreshXUL(newuser) {
1525 if (window.xulG && typeof window.xulG.on_save == 'function')
1526 window.xulG.on_save(newuser);
1531 * Create a new address and insert it into the DOM
1532 * @param evt ignored
1533 * @param id The address id
1534 * @param mkLinks If true, set the new address as the
1535 * mailing/billing address for the user
1537 function uEditNewAddr(evt, id, mkLinks) {
1540 id = --uEditAddrVirtId; // new address
1542 var addr = patron.addresses().filter(
1543 function(i) { return (i.id() == id) })[0];
1545 dojo.forEach(addrTemplateRows,
1548 row = tbody.insertBefore(row.cloneNode(true), dojo.byId('new-addr-row'));
1549 row.setAttribute('type', '');
1550 row.setAttribute('addr', id+'');
1552 if(row.getAttribute('fmclass')) {
1553 var widget = fleshFMRow(row, 'aua', {addr:id});
1555 // make new addresses a default address type
1556 if(id < 0 && row.getAttribute('fmfield') == 'address_type')
1557 widget.widget.attr('value', localeStrings.DEFAULT_ADDRESS_TYPE);
1559 // make new addresses valid by default
1560 if(id < 0 && row.getAttribute('fmfield') == 'valid')
1561 widget.widget.attr('value', true);
1563 // make new addresses use the org setting for default country
1564 if(id < 0 && row.getAttribute('fmfield') == 'country')
1565 widget.widget.attr('value',orgSettings['ui.patron.default_country']);
1567 } else if(row.getAttribute('name') == 'uedit-addr-pending-row') {
1569 // if it's a pending address, show the 'approve' button
1570 if(addr && openils.Util.isTrue(addr.pending())) {
1571 openils.Util.show(row, 'table-row');
1572 dojo.query('[name=approve-button]', row)[0].onclick =
1573 function() { uEditApproveAddress(addr); };
1575 if(addr.replaces()) {
1576 var div = dojo.query('[name=replaced-addr]', row)[0]
1577 var replaced = patron.addresses().filter(
1578 function(i) { return (i.id() == addr.replaces()) })[0];
1580 div.innerHTML = dojo.string.substitute(localeStrings.REPLACED_ADDRESS, [
1581 replaced.address_type() || '',
1582 replaced.street1() || '',
1583 replaced.street2() || '',
1584 replaced.city() || '',
1585 replaced.state() || '',
1586 replaced.post_code() || ''
1590 openils.Util.hide(dojo.query('[name=replaced-addr-div]', row)[0]);
1594 } else if(row.getAttribute('name') == 'uedit-addr-owner-row') {
1595 // address is owned by someone else. provide option to load the
1596 // user in a different tab
1598 if(addr && addr.usr() != patron.id()) {
1599 openils.Util.show(row, 'table-row');
1600 var link = getByName(row, 'addr-owner');
1602 // fetch the linked user so we can present their name in the UI
1604 if(cloneUserObj && cloneUserObj.id() == addr.usr()) {
1606 cloneUserObj.first_given_name(),
1607 cloneUserObj.second_given_name(),
1608 cloneUserObj.family_name()
1611 addrUser = fieldmapper.standardRequest(
1612 ['open-ils.actor', 'open-ils.actor.user.retrieve.parts'],
1614 openils.User.authtoken,
1616 ['first_given_name', 'second_given_name', 'family_name']
1621 link.innerHTML = (addrUser.map(function(name) { return (name) ? name+' ' : '' })+'').replace(/,/g,''); // TODO i18n
1622 link.onclick = function() {
1623 if(openils.XUL.isXUL()) {
1624 window.xulG.spawn_editor({ses:openils.User.authtoken, usr:addr.usr()})
1626 parent.location.href = location.href.replace(/clone=\d+/, 'usr=' + addr.usr());
1631 } else if(row.getAttribute('name') == 'uedit-addr-divider') {
1632 // link up the billing/mailing address and give the inputs IDs so we can access the later
1635 var ba = getByName(row, 'billing_address');
1636 ba.id = 'uedit-billing-address-' + id;
1637 if(mkLinks || (patron.billing_address() && patron.billing_address().id() == id))
1641 var ma = getByName(row, 'mailing_address');
1642 ma.id = 'uedit-mailing-address-' + id;
1643 if(mkLinks || (patron.mailing_address() && patron.mailing_address().id() == id))
1646 var btn = dojo.query('[name=delete-button]', row)[0];
1647 if(btn) btn.onclick = function(){ uEditDeleteAddr(id) };
1653 function uEditApproveAddress(addr) {
1654 fieldmapper.standardRequest(
1655 ['open-ils.actor', 'open-ils.actor.user.pending_address.approve'],
1657 params: [openils.User.authtoken, addr],
1659 oncomplete : function(r) {
1660 var oldId = openils.Util.readResponse(r);
1662 // remove addrs from UI
1665 function(addr) { uEditDeleteAddr(addr.id(), true); }
1670 // remove the replaced address
1671 if(oldId != addr.id()) {
1673 patron.addresses().filter(
1674 function(i) { return (i.id() != oldId); }
1679 // fix the the new address
1681 addr.replaces(null);
1694 function uEditDeleteAddr(id, noAlert) {
1695 if (patron.isnew() && orgSettings['ui.patron.registration.require_address']) {
1696 if (dojo.query('tr[name=uedit-addr-divider]').length < 2) {
1697 alert(localeStrings.NEED_ADDRESS);
1702 if(!confirm(dojo.string.substitute(localeStrings.DELETE_ADDRESS, [id]))) return;
1704 var addr = patron.addresses().filter(function(i){return (i.id() == id)})[0];
1705 if (addr) { addr.isdeleted(1); }
1706 var m_a = patron.mailing_address();
1707 if (typeof m_a == 'object' && m_a != null) { m_a = m_a.id(); }
1708 if (m_a == id) { patron.mailing_address(null); }
1709 var b_a = patron.billing_address();
1710 if (typeof b_a == 'object' && b_a != null) { b_a = b_a.id(); }
1711 if (b_a == id) { patron.billing_address(null); }
1713 var rows = dojo.query('tr[addr='+id+']', tbody);
1714 for(var i = 0; i < rows.length; i++)
1715 rows[i].parentNode.removeChild(rows[i]);
1716 widgetPile = widgetPile.filter(function(w){return (w._addr != id)});
1719 function uEditToggleRequired(level) {
1720 openils.Util.removeCSSClass(tbody, 'hide-non-required');
1721 openils.Util.removeCSSClass(tbody, 'hide-non-suggested');
1722 openils.Util.show('uedit-show-required');
1723 openils.Util.show('uedit-show-required-br');
1724 openils.Util.show('uedit-show-suggested');
1725 openils.Util.show('uedit-show-suggested-br');
1726 openils.Util.show('uedit-show-all');
1729 openils.Util.hide('uedit-show-required');
1730 openils.Util.hide('uedit-show-required-br');
1731 openils.Util.addCSSClass(tbody, 'hide-non-required');
1734 openils.Util.hide('uedit-show-suggested');
1735 openils.Util.hide('uedit-show-suggested-br');
1736 openils.Util.addCSSClass(tbody, 'hide-non-suggested');
1739 openils.Util.hide('uedit-show-all');
1744 function printable_output() {
1745 var temp; var s = '=-=-=-=\r\n';
1746 for (var idx in widgetPile) {
1747 var w = widgetPile[idx];
1748 var val = uEditWidgetVal(w);
1750 if (typeof w.idlField == 'undefined') {
1752 if (w._wtype == 'statcat') {
1753 var stat = statCats.filter(
1755 return (m.id() == w._statcat) })[0];
1756 label = stat.name();
1757 } else if (w._wtype == 'survey') {
1758 var survey = surveys.filter(
1760 return (m.id() == w._survey) })[0];
1761 var question = survey.questions().filter(
1763 return (m.id() == w._question) })[0];
1764 label = survey.name() + ' : ' + question.question();
1769 label = w.idlField.label;
1771 if (temp != w._wtype) {
1775 s += label + ':\t' + (typeof val == 'object' ? '' : val) + '\r\n';
1781 openils.Util.addOnLoad(load);