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 var old = patron.cards().filter(function(c){return (c.id() == patron.card().id())})[0];
353 var newc = new fieldmapper.ac();
354 newc.id(uEditCardVirtId--);
358 var t = patron.cards();
365 * Generate a random password for the patron.
367 function generatePasswordHandler() {
368 uEditMakeRandomPw(patron);
369 var f = findWidget('au', 'passwd');
370 f.widget.attr('value', patron.passwd());
371 f = findWidget('au', 'passwd2');
372 f.widget.attr('value', patron.passwd());
376 * Loads a staged user and turns them into something the editor can understand
378 function uEditLoadStageUser(stageUname) {
380 var data = fieldmapper.standardRequest(
381 ['open-ils.actor', 'open-ils.actor.user.stage.retrieve.by_username'],
382 { params : [openils.User.authtoken, stageUname] }
385 stageUser = data.user;
386 patron = uEditNewPatron();
391 // copy the data into our new user object
392 for(var key in fieldmapper.IDL.fmclasses.stgu.field_map) {
393 if(fieldmapper.IDL.fmclasses.au.field_map[key] && !fieldmapper.IDL.fmclasses.stgu.field_map[key].virtual) {
394 if(data.user[key]() !== null)
395 patron[key]( data.user[key]() );
399 // copy the data into our new address objects
400 // TODO: uses the first mailing address only
401 if(data.mailing_addresses.length) {
403 var mail_addr = new fieldmapper.aua();
404 mail_addr.id(-1); // virtual ID
407 patron.mailing_address(mail_addr);
408 var t = patron.addresses();
413 for(var key in fieldmapper.IDL.fmclasses.stgma.field_map) {
414 if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgma.field_map[key].virtual) {
415 if(data.mailing_addresses[0][key]() !== null)
416 mail_addr[key]( data.mailing_addresses[0][key]() );
421 // copy the data into our new address objects
422 // TODO uses the first billing address only
423 if(data.billing_addresses.length) {
425 var bill_addr = new fieldmapper.aua();
426 bill_addr.id(-2); // virtual ID
429 patron.billing_address(bill_addr);
430 var t = patron.addresses();
435 for(var key in fieldmapper.IDL.fmclasses.stgba.field_map) {
436 if(fieldmapper.IDL.fmclasses.aua.field_map[key] && !fieldmapper.IDL.fmclasses.stgba.field_map[key].virtual) {
437 if(data.billing_addresses[0][key]() !== null)
438 bill_addr[key]( data.billing_addresses[0][key]() );
443 // TODO: uses the first card only
444 if(data.cards.length) {
445 var card = new fieldmapper.ac();
446 card.id(-1); // virtual ID
447 patron.card().barcode(data.cards[0].barcode());
454 * clone the home org, phone numbers, and billing/mailing address
456 function uEditCopyCloneData(patron) {
457 cloneUserObj = uEditLoadUser(cloneUser);
467 if(!uEditCloneCopyAddr)
468 cloneFields = cloneFields.concat(['mailing_address', 'billing_address']);
473 patron[field](cloneUserObj[field]());
477 if(uEditCloneCopyAddr) {
478 var billAddr, mailAddr;
480 // copy the billing and mailing addresses into new addresses
481 function cloneAddr(addr) {
482 var newAddr = addr.clone();
484 newAddr.id(uEditAddrVirtId--);
485 newAddr.usr(patron.id());
486 patron.addresses().push(newAddr);
490 if(billAddr = cloneUserObj.billing_address())
491 patron.billing_address(cloneAddr(billAddr));
493 if(mailAddr = cloneUserObj.mailing_address()) {
494 if (billAddr && billAddr.id() == mailAddr.id()) {
495 patron.mailing_address(patron.billing_address());
497 patron.mailing_address(cloneAddr(mailAddr));
501 if(!billAddr) // if there was no billing addr, use the mailing addr
502 patron.billing_address(patron.mailing_address());
506 // link the billing and mailing addresses
507 if(patron.billing_address()) {
508 var t = patron.addresses();
510 t.push(patron.billing_address());
514 if(patron.mailing_address() && (
515 patron.addresses().length == 0 ||
516 patron.mailing_address().id() != patron.billing_address().id()) ) {
517 var t = patron.addresses();
519 t.push(patron.mailing_address());
526 function uEditFetchUserSettings(userId) {
528 var baseNode = fieldmapper.aou.findOrgUnit(staff.ws_ou());
529 var orgs = fieldmapper.aou.orgNodeTrail(baseNode);
530 orgs = orgs.map(function(node) { return node.id(); });
532 /* fetch any user setting types we need + any that offer opt-in */
533 userSettingTypes = pcrud.search('cust', {
535 {name:['circ.holds_behind_desk', 'circ.collections.exempt']},
538 select : {atevdef : ['opt_in_setting']},
540 // we only care about opt-in settings for event_defs our users encounter
541 where : {'+atevdef' : {owner : orgs}}
547 var names = userSettingTypes.map(function(obj) { return obj.name() });
549 /* fetch any values set for this user */
551 userSettings = fieldmapper.standardRequest(
552 ['open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative'],
553 {params : [openils.User.authtoken, userId, names]});
558 function uEditLoadUser(userId) {
559 var patron = fieldmapper.standardRequest(
560 ['open-ils.actor', 'open-ils.actor.user.fleshed.retrieve.authoritative'],
561 {params : [openils.User.authtoken, userId]}
563 openils.Event.parse_and_raise(patron);
567 function loadStaticFields() {
568 for(var idx = 0; tbody.childNodes[idx]; idx++) {
569 var row = tbody.childNodes[idx];
570 if(row.nodeType != row.ELEMENT_NODE) continue;
571 var fmcls = row.getAttribute('fmclass');
573 fleshFMRow(row, fmcls);
576 if(row.id == 'uedit-settings-divider') {
578 var template = tbody.removeChild(dojo.byId('uedit-user-setting-template'));
579 dojo.forEach(userSettingTypes, function(type) { uEditDrawSettingRow(tbody, row, template, type); } );
581 if(userSettingTypes.length > 1 || orgSettings['circ.holds.behind_desk_pickup_supported']) {
582 openils.Util.show('uedit-settings-divider', 'table-row');
589 function uEditDrawSettingRow(tbody, dividerRow, template, stype) {
590 var row = template.cloneNode(true);
591 row.setAttribute('user_setting', stype.name());
592 getByName(row, 'label').innerHTML = stype.label();
593 var cb = new dijit.form.CheckBox({scrollOnFocus:false}, getByName(row, 'widget'));
594 cb.attr('value', userSettings[stype.name()]);
595 dojo.connect(cb, 'onChange', function(newVal) { userSettingsToUpdate[stype.name()] = newVal; });
596 tbody.insertBefore(row, dividerRow.nextSibling);
597 openils.Util.show(row, 'table-row');
599 if(stype.name() == 'circ.collections.exempt') {
600 checkCollectionsExemptPerm(cb);
604 function uEditUpdateUserSettings(userId) {
605 return fieldmapper.standardRequest(
606 ['open-ils.actor', 'open-ils.actor.patron.settings.update'],
607 {params : [openils.User.authtoken, userId, userSettingsToUpdate]});
610 function loadAllAddrs() {
611 dojo.forEach(patron.addresses(),
613 uEditNewAddr(null, addr.id());
618 function loadStatCats() {
620 statCats = fieldmapper.standardRequest(
621 ['open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all'],
622 {params : [openils.User.authtoken, staff.ws_ou()]}
626 for(var idx in statCats) {
627 var stat = statCats[idx];
628 var row = statCatTemplate.cloneNode(true);
629 row.id = 'stat-cat-row-' + idx;
630 row.setAttribute('stat_cat_owner',stat.owner());
631 row.setAttribute('stat_cat_name',stat.name());
632 row.setAttribute('stat_cat_id',stat.id());
633 tbody.appendChild(row);
634 getByName(row, 'name').innerHTML = stat.name();
635 var valtd = getByName(row, 'widget');
636 var span = valtd.appendChild(document.createElement('span'));
637 var store = new dojo.data.ItemFileReadStore(
638 {data:fieldmapper.actsc.toStoreData(stat.entries())});
639 var comboBox = new dijit.form.ComboBox({store:store,scrollOnFocus:false,fetchProperties:{sort:[{attribute: 'value'}]}}, span);
640 comboBox.labelAttr = 'value';
641 comboBox.searchAttr = 'value';
643 comboBox._wtype = 'statcat';
644 comboBox._statcat = stat.id();
645 widgetPile.push(comboBox);
647 // populate existing cats
648 var map = patron.stat_cat_entries().filter(
649 function(mp) { return (mp.stat_cat() == stat.id()) })[0];
650 if(map) comboBox.attr('value', map.stat_cat_entry());
655 function loadSurveys() {
657 surveys = fieldmapper.standardRequest(
658 ['open-ils.circ', 'open-ils.circ.survey.retrieve.all'],
659 {params : [openils.User.authtoken]}
663 for(var idx in surveys) {
664 var survey = surveys[idx];
665 var required = openils.Util.isTrue(survey.required());
666 var srow = surveyTemplate.cloneNode(true);
667 if(required) srow.setAttribute('required','required');
668 tbody.appendChild(srow);
669 getByName(srow, 'name').innerHTML = survey.name();
671 for(var q in survey.questions()) {
672 var quest = survey.questions()[q];
673 var qrow = surveyQuestionTemplate.cloneNode(true);
674 if(required) qrow.setAttribute('required','required');
675 tbody.appendChild(qrow);
676 getByName(qrow, 'question').innerHTML = quest.question();
678 var span = getByName(qrow, 'answers').appendChild(document.createElement('span'));
679 var store = new dojo.data.ItemFileReadStore(
680 {data:fieldmapper.asva.toStoreData(quest.answers())});
681 var select = new dijit.form.FilteringSelect({store:store,scrollOnFocus:false}, span);
683 select.isValid = function() { return true; };
685 select.labelAttr = 'answer';
686 select.searchAttr = 'answer';
688 select._wtype = 'survey';
689 select._survey = survey.id();
690 select._question = quest.id();
691 widgetPile.push(select);
697 function fleshFMRow(row, fmcls, args) {
698 var fmfield = row.getAttribute('fmfield');
699 var wclass = row.getAttribute('wclass');
700 var wstyle = row.getAttribute('wstyle');
701 var wconstraints = row.getAttribute('wconstraints');
702 /* use CSS to set the zindex for widgets you want to disable. */
703 var disabled = dojo.style(row, 'zIndex') == -1 ? true : false;
704 var isphone = (fmcls == 'au') && (fmfield.search('_phone') != -1);
706 var isPasswd2 = (fmfield == 'passwd2');
707 if(isPasswd2) fmfield = 'passwd';
708 var fieldIdl = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield];
711 var existing = dojo.query('td', row);
712 var htd = existing[0] || row.appendChild(document.createElement('td'));
713 var ltd = existing[1] || row.appendChild(document.createElement('td'));
714 var wtd = existing[2] || row.appendChild(document.createElement('td'));
715 var ftd = existing[3] || row.appendChild(document.createElement('td'));
717 openils.Util.addCSSClass(htd, 'uedit-help');
718 if(fieldDoc[fmcls] && fieldDoc[fmcls][fmfield]) {
719 var link = dojo.byId('uedit-help-template').cloneNode(true);
721 link.onclick = function() { ueLoadContextHelp(fmcls, fmfield) };
722 openils.Util.removeCSSClass(link, 'hidden');
723 htd.appendChild(link);
726 if(!ltd.textContent) {
727 ltd.appendChild(document.createTextNode(fieldIdl.label));
730 if(!ftd.textContent) {
731 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.example']) {
732 ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.example']));
734 else if(isphone && orgSettings['ui.patron.edit.phone.example']) {
735 ftd.appendChild(document.createTextNode(localeStrings.EXAMPLE + orgSettings['ui.patron.edit.phone.example']));
737 else if(fieldIdl.datatype == 'timestamp') {
738 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)})));
742 var span = document.createElement('span');
743 wtd.appendChild(span);
747 case 'au' : fmObject = patron; break;
748 case 'ac' : fmObject = patron.card(); break;
750 fmObject = patron.addresses().filter(
751 function(i) { return (i.id() == args.addr) })[0];
752 if(fmObject && fmObject.usr() != patron.id())
757 // Adjust required value by org settings
758 var curRequired = row.getAttribute('required');
759 var required = curRequired == 'required';
760 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.require']) {
761 row.setAttribute('required', 'required');
764 else if (curRequired != 'required' && orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.show']) {
765 row.setAttribute('required', 'show');
767 else if (curRequired != 'required' && curRequired != 'show' && orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.suggest']) {
768 row.setAttribute('required', 'suggested');
771 // password data is not fetched/required/displayed for existing users
772 if(!patron.isnew() && 'passwd' == fmfield)
778 constraints : (wconstraints) ? eval('('+wconstraints+')') : {}, // the ()'s prevent Invalid Label errors with eval
782 // Org settings provided regex?
783 if(orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.regex']) {
784 dijitArgs.regExp = orgSettings['ui.patron.edit.' + fmcls + '.' + fmfield + '.regex'];
786 else if(isphone && orgSettings['ui.patron.edit.phone.regex']) {
787 dijitArgs.regExp = orgSettings['ui.patron.edit.phone.regex'];
790 if(fmcls == 'au' && fmfield == 'passwd') {
791 if (orgSettings['global.password_regex']) {
792 dijitArgs.regExp = orgSettings['global.password_regex'];
796 if(fmcls == 'au' && fmfield == 'dob' && !orgSettings['ui.patron.edit.au.dob.calendar'])
797 dijitArgs.popupClass = "";
799 var value = row.getAttribute('wvalue');
801 dijitArgs.value = value;
808 widgetClass : wclass,
809 dijitArgs : dijitArgs,
810 orgDefaultsToWs : true,
811 orgLimitPerms : ['UPDATE_USER'],
814 if(fmfield == 'profile') {
815 // fetch profile groups non-async so existing expire_date is
816 // not overwritten when the profile groups arrive and update
817 wargs.forceSync = true;
818 wargs.disableQuery = {usergroup : 'f'};
819 if(!patron.isnew() && !checkGrpAppPerm(patron.profile()))
820 wargs.readOnly = true;
822 wargs.forceSync = false;
825 if(fmcls == 'au' && fmfield == 'home_ou'){
826 wargs.labelAttr = 'name';
827 wargs.searchAttr = 'name';
830 var widget = new openils.widget.AutoFieldWidget(wargs);
833 if(fmfield == 'profile') { trimGrpTree(ww); }
837 // now put it back before we register the widget
838 if(isPasswd2) fmfield = 'passwd2';
840 widget._wtype = fmcls;
841 widget._fmfield = fmfield;
842 widget._addr = args.addr;
843 widgetPile.push(widget);
844 attachWidgetEvents(fmcls, fmfield, widget);
848 function trimGrpTree(autoWidget) {
849 var store = autoWidget.widget.store;
851 // remove all groups that this user are not allowed to edit,
852 // except the profile group of an existing user
853 store.fetch({onItem :
855 if(!checkGrpAppPerm(item.id[0]) && patron.profile() != item.id[0])
856 store.deleteItem(item);
861 function findWidget(wtype, fmfield, callback) {
862 return widgetPile.filter(
864 if(i._wtype == wtype && i._fmfield == fmfield) {
865 if(callback) return callback(i);
873 * if the user does not have the UPDATE_PATRON_CLAIM_RETURN_COUNT,
874 * they are not allowed to directly alter the claim return count.
875 * This function checks the perm and disable/enables the widget.
877 function checkClaimsReturnCountPerm() {
878 new openils.User().getPermOrgList(
879 'UPDATE_PATRON_CLAIM_RETURN_COUNT',
881 var cr = findWidget('au', 'claims_returned_count');
882 if(orgList.indexOf(patron.home_ou()) == -1)
883 cr.widget.attr('disabled', true);
885 cr.widget.attr('disabled', false);
893 function checkClaimsNoCheckoutCountPerm() {
894 new openils.User().getPermOrgList(
895 'UPDATE_PATRON_CLAIM_NEVER_CHECKED_OUT_COUNT',
897 var cr = findWidget('au', 'claims_never_checked_out_count');
898 if(orgList.indexOf(patron.home_ou()) == -1)
899 cr.widget.attr('disabled', true);
901 cr.widget.attr('disabled', false);
908 var collectExemptCBox;
909 function checkCollectionsExemptPerm(cbox) {
910 if(cbox) collectExemptCBox = cbox;
911 new openils.User().getPermOrgList(
912 'UPDATE_PATRON_COLLECTIONS_EXEMPT',
914 if(orgList.indexOf(patron.home_ou()) == -1)
915 collectExemptCBox.attr('disabled', true);
917 collectExemptCBox.attr('disabled', false);
924 function usePhonePw(newVal) {
927 matches = RegExp(this.regExp).exec(newVal);
928 if(matches.length > 1) newPw = matches[1];
930 if(!newPw && newVal && newVal.length >= 4) {
931 newPw = newVal.substring(newVal.length - 4);
934 var p1 = findWidget('au', 'passwd');
935 var p2 = findWidget('au', 'passwd2');
937 p1.widget.attr('value', newPw);
938 p2.widget.attr('value', newPw);
946 function attachWidgetEvents(fmcls, fmfield, widget) {
952 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
953 if (!(ev.altKey || ev.ctrlKey || ev.metaKey)) {
954 if (lock_ready && xulG && typeof xulG.lock_tab == 'function') {
955 if (! already_locked) {
957 already_locked = true;
967 if (lock_ready && xulG && typeof xulG.lock_tab == 'function') {
968 if (! already_locked) {
970 already_locked = true;
978 if(fmfield == 'barcode') {
979 dojo.connect(widget.widget, 'onChange',
981 var barcode = this.attr('value');
983 dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
984 fieldmapper.standardRequest(
985 ['open-ils.actor', 'open-ils.actor.barcode.exists'],
987 params: [openils.User.authtoken, barcode],
988 oncomplete : function(r) {
989 var res = openils.Util.readResponse(r);
992 dojo.removeClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
995 dojo.addClass(dojo.byId('uedit-dupe-barcode-warning'), 'hidden');
996 var un = findWidget('au', 'usrname');
997 if(!un.widget.attr('value'))
998 un.widget.attr('value', barcode);
1013 widget.widget.isValid = function() {
1015 if(this.attr("value").match(/\s/)) {
1018 // Can look like a barcode (for initial value)
1019 if(orgSettings['opac.barcode_regex']) {
1020 var test_regexp = new RegExp(orgSettings['opac.barcode_regex']);
1021 if(test_regexp.test(this.attr("value"))) {
1025 // Can look like a username
1026 if(orgSettings['opac.username_regex']) {
1027 var test_regexp = new RegExp(orgSettings['opac.username_regex']);
1028 if(test_regexp.test(this.attr("value"))) {
1032 // If we know what a barcode and username look like and we got here, reject
1033 if(orgSettings['opac.barcode_regex'] && orgSettings['opac.username_regex'])
1035 // Otherwise we don't have enough info to say either way, let it through.
1038 dojo.connect(widget.widget, 'onChange',
1040 var input = findWidget('au', 'usrname');
1041 var usrname = input.widget.attr('value');
1044 dupeUsrname = false;
1045 dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1049 fieldmapper.standardRequest(
1050 ['open-ils.actor', 'open-ils.actor.username.exists'],
1052 params: [openils.User.authtoken, usrname],
1053 oncomplete : function(r) {
1054 var res = openils.Util.readResponse(r);
1057 dojo.removeClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1059 dupeUsrname = false;
1060 dojo.addClass(dojo.byId('uedit-dupe-username-warning'), 'hidden');
1070 case 'profile': // when the profile changes, update the expire date
1071 dojo.connect(widget.widget, 'onChange',
1074 var expireWidget = findWidget('au', 'expire_date');
1075 function found(items) {
1076 if(items.length == 0) return;
1077 var item = items[0];
1078 var interval = self.store.getValue(item, 'perm_interval');
1079 expireWidget.widget.attr('value', dojo.date.add(new Date(),
1080 'second', openils.Util.intervalToSeconds(interval)));
1082 this.store.fetch({onComplete:found, query:{id:this.attr('value')}});
1088 widget.widget.isValid = function() {
1089 return this.attr("value") < new Date();
1091 dojo.connect(widget.widget, 'onChange',
1094 var oldDob = patron.dob();
1095 if(dojo.date.stamp.fromISOString(oldDob) == newDob) return;
1097 var juvInterval = orgSettings['global.juvenile_age_threshold'] || '18 years';
1098 var juvWidget = findWidget('au', 'juvenile');
1099 var base = new Date();
1100 base.setTime(base.getTime() - Number(openils.Util.intervalToSeconds(juvInterval) + '000'));
1102 if(newDob <= base) // older than global.juvenile_age_threshold
1103 juvWidget.widget.attr('value', false);
1105 juvWidget.widget.attr('value', true);
1110 case 'first_given_name':
1112 dojo.connect(widget.widget, 'onChange',
1113 function(newVal) { uEditDupeSearch('name', newVal); });
1117 dojo.connect(widget.widget, 'onChange',
1118 function(newVal) { uEditDupeSearch('email', newVal); });
1122 case 'ident_value2':
1123 dojo.connect(widget.widget, 'onChange',
1124 function(newVal) { uEditDupeSearch('ident', newVal); });
1128 // if configured, use the last four digits of the day phone number as the password
1129 // Alt, use the first capture group of the validator regex
1130 if(uEditUsePhonePw && patron.isnew()) {
1131 dojo.connect(widget.widget, 'onChange', widget.widget, usePhonePw);
1132 if (patron.day_phone()) {
1133 usePhonePw(patron.day_phone());
1136 case 'evening_phone':
1138 dojo.connect(widget.widget, 'onChange',
1139 function(newVal) { uEditDupeSearch('phone', newVal); });
1143 widget.widget.isValid = function() {
1145 if(homeOuTypes[this.store.getValue(this.item, 'ou_type')]) {
1152 dojo.connect(widget.widget, 'onChange',
1154 checkClaimsReturnCountPerm();
1155 checkClaimsNoCheckoutCountPerm();
1156 checkCollectionsExemptPerm();
1162 dojo.connect(widget.widget, 'onChange',
1164 var pw1 = findWidget('au', 'passwd').widget;
1165 var pw2 = findWidget('au', 'passwd2').widget;
1166 var preserved_value = pw2.attr('value');
1167 // Ensure that the pw2 field match the pw1 field to validate
1168 pw2.regExp = newVal.replace(/([.\\^$*+?\(\)\[\]\{\}])/g, '\\$1');
1170 pw2.attr('value',preserved_value);
1176 if(fmclass = 'aua') {
1179 dojo.connect(widget.widget, 'onChange',
1181 fieldmapper.standardRequest(
1182 ['open-ils.search', 'open-ils.search.zip'],
1185 oncomplete : function(r) {
1186 var res = openils.Util.readResponse(r);
1188 var callback = function(w) { return w._addr == widget._addr; };
1189 if(res.city) findWidget('aua', 'city', callback).widget.attr('value', res.city);
1190 if(res.state) findWidget('aua', 'state', callback).widget.attr('value', res.state);
1191 if(res.county) findWidget('aua', 'county', callback).widget.attr('value', res.county);
1192 if(res.alert) alert(res.alert);
1203 dojo.connect(widget.widget, 'onChange',
1205 var callback = function(w) { return w._addr == widget._addr; };
1207 street1 : findWidget('aua', 'street1', callback).widget.attr('value'),
1208 street2 : findWidget('aua', 'street2', callback).widget.attr('value'),
1209 city : findWidget('aua', 'city', callback).widget.attr('value'),
1210 post_code : findWidget('aua', 'post_code', callback).widget.attr('value')
1212 if(args.street1 && args.city && args.post_code)
1213 uEditDupeSearch('address', args);
1221 function uEditDupeSearch(type, value) {
1227 openils.Util.hide('uedit-dupe-names-link');
1228 var fname = findWidget('au', 'first_given_name').widget.attr('value');
1229 var lname = findWidget('au', 'family_name').widget.attr('value');
1230 if( !(fname && lname) ) return;
1232 first_given_name : {value : fname, group : 0},
1233 family_name : {value : lname, group : 0},
1238 openils.Util.hide('uedit-dupe-email-link');
1239 search = {email : {value : value, group : 0}};
1243 openils.Util.hide('uedit-dupe-ident-link');
1244 search = {ident : {value : value, group : 2}};
1248 openils.Util.hide('uedit-dupe-phone-link');
1249 search = {phone : {value : value, group : 2}};
1253 openils.Util.hide('uedit-dupe-address-link');
1255 dojo.forEach(['street1', 'street2', 'city', 'post_code'],
1258 search[field] = {value : value[field], group: 1};
1264 // find possible duplicate patrons
1265 fieldmapper.standardRequest(
1266 ['open-ils.actor', 'open-ils.actor.patron.search.advanced'],
1268 params: [openils.User.authtoken, search],
1269 oncomplete : function(r) {
1270 var resp = openils.Util.readResponse(r);
1271 resp = resp.filter(function(id) { return (id != patron.id()); });
1273 if(resp && resp.length > 0) {
1275 openils.Util.hide('uedit-help-div');
1276 openils.Util.show('uedit-dupe-div');
1281 link = dojo.byId('uedit-dupe-names-link');
1282 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_NAME, [resp.length]);
1285 link = dojo.byId('uedit-dupe-email-link');
1286 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_EMAIL, [resp.length]);
1289 link = dojo.byId('uedit-dupe-ident-link');
1290 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_IDENT, [resp.length]);
1293 link = dojo.byId('uedit-dupe-phone-link');
1294 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_PHONE, [resp.length]);
1297 link = dojo.byId('uedit-dupe-address-link');
1298 link.innerHTML = dojo.string.substitute(localeStrings.DUPE_PATRON_ADDR, [resp.length]);
1302 openils.Util.show(link);
1303 link.onclick = function() {
1304 search.search_sort = js2JSON(["penalties", "family_name", "first_given_name"]);
1306 window.xulG.spawn_search(search);
1308 console.log("running XUL patron search " + js2JSON(search));
1316 function getByName(node, name) {
1317 return dojo.query('[name='+name+']', node)[0];
1321 function ueLoadContextHelp(fmcls, fmfield) {
1322 openils.Util.hide('uedit-dupe-div');
1323 openils.Util.show('uedit-help-div');
1324 dojo.byId('uedit-help-field').innerHTML = fieldmapper.IDL.fmclasses[fmcls].field_map[fmfield].label;
1325 dojo.byId('uedit-help-text').innerHTML = fieldDoc[fmcls][fmfield].string();
1329 /* creates a new patron object with card attached */
1330 function uEditNewPatron() {
1335 card.id(uEditCardVirtId--);
1339 patron.cards([card]);
1340 patron.net_access_level(orgSettings['ui.patron.default_inet_access_level'] || 1);
1341 patron.ident_type(orgSettings['ui.patron.default_ident_type']);
1342 patron.stat_cat_entries([]);
1343 patron.survey_responses([]);
1344 patron.addresses([]);
1345 uEditMakeRandomPw(patron);
1349 function uEditMakeRandomPw(patron) {
1350 var rand = Math.random();
1351 rand = parseInt(rand * 10000) + '';
1352 while(rand.length < 4) rand += '0';
1354 appendClear($('ue_password_plain'),text(rand));
1355 unHideMe($('ue_password_gen'));
1357 patron.passwd(rand);
1361 function uEditWidgetVal(w) {
1362 var val = (w.getFormattedValue) ? w.getFormattedValue() : w.attr('value');
1363 if(val === '') val = null;
1367 function uEditSave() { _uEditSave(); }
1368 function uEditSaveClone() { _uEditSave(true); }
1370 function _uEditSave(doClone) {
1372 if ( (! myForm.isValid()) || dupeUsrname || dupeBarcode ) {
1373 alert(localeStrings.INVALID_FORM);
1377 for(var idx in widgetPile) {
1378 var w = widgetPile[idx];
1379 var val = uEditWidgetVal(w);
1383 if(w._fmfield != 'passwd2')
1384 patron[w._fmfield](val);
1388 patron.card()[w._fmfield](val);
1392 var addr = patron.addresses().filter(function(i){return (i.id() == w._addr)})[0];
1394 addr = new fieldmapper.aua();
1397 addr.usr(patron.id());
1398 addr.country(orgSettings['ui.patron.default_country']);
1399 var t = patron.addresses();
1402 patron.addresses(t);
1404 if(addr[w._fmfield]() != val)
1407 addr[w._fmfield](val);
1409 if(dojo.byId('uedit-billing-address-' + addr.id()).checked)
1410 patron.billing_address(addr.id());
1412 if(dojo.byId('uedit-mailing-address-' + addr.id()).checked)
1413 patron.mailing_address(addr.id());
1418 if(val == null) break;
1419 var resp = new fieldmapper.asvr();
1421 resp.survey(w._survey)
1422 resp.usr(patron.id());
1423 resp.question(w._question)
1425 var t = patron.survey_responses();
1428 patron.survey_responses(t);
1432 var map = patron.stat_cat_entries().filter(
1434 return (m.stat_cat() == w._statcat) })[0];
1437 if(map.stat_cat_entry() == val)
1448 map = new fieldmapper.actscecm();
1452 map.stat_cat(w._statcat);
1453 map.stat_cat_entry(val);
1454 map.target_usr(patron.id());
1455 var t = patron.stat_cat_entries();
1458 patron.stat_cat_entries(t);
1463 patron.ischanged(1);
1464 fieldmapper.standardRequest(
1465 ['open-ils.actor', 'open-ils.actor.patron.update'],
1467 params: [openils.User.authtoken, patron],
1468 oncomplete: function(r) {
1470 if (xulG && typeof xulG.unlock_tab == 'function') {
1472 already_locked = false;
1474 newPatron = openils.Util.readResponse(r);
1476 uEditUpdateUserSettings(newPatron.id());
1477 if(stageUser) uEditRemoveStage();
1478 uEditFinishSave(newPatron, doClone);
1485 function uEditRemoveStage() {
1486 var resp = fieldmapper.standardRequest(
1487 ['open-ils.actor', 'open-ils.actor.user.stage.delete'],
1488 { params : [openils.User.authtoken, stageUser.row_id()] }
1492 function uEditFinishSave(newPatron, doClone) {
1494 if(doClone && cloneUser == null)
1495 cloneUser = newPatron.id();
1499 if(xulG && typeof xulG.spawn_editor == 'function' && !patron.isnew() ) {
1500 window.xulG.spawn_editor({ses:openils.User.authtoken,clone:cloneUser});
1504 location.href = location.href.replace(/\?.*/, '') + '?clone=' + cloneUser;
1512 uEditRefreshXUL(newPatron);
1515 function uEditRefresh() {
1516 var usr = cgi.param('usr');
1517 var href = location.href.replace(/\?.*/, '');
1518 href += ((usr) ? '?usr=' + usr : '');
1519 location.href = href;
1522 function uEditRefreshXUL(newuser) {
1523 if (window.xulG && typeof window.xulG.on_save == 'function')
1524 window.xulG.on_save(newuser);
1529 * Create a new address and insert it into the DOM
1530 * @param evt ignored
1531 * @param id The address id
1532 * @param mkLinks If true, set the new address as the
1533 * mailing/billing address for the user
1535 function uEditNewAddr(evt, id, mkLinks) {
1538 id = --uEditAddrVirtId; // new address
1540 var addr = patron.addresses().filter(
1541 function(i) { return (i.id() == id) })[0];
1543 dojo.forEach(addrTemplateRows,
1546 row = tbody.insertBefore(row.cloneNode(true), dojo.byId('new-addr-row'));
1547 row.setAttribute('type', '');
1548 row.setAttribute('addr', id+'');
1550 if(row.getAttribute('fmclass')) {
1551 var widget = fleshFMRow(row, 'aua', {addr:id});
1553 // make new addresses a default address type
1554 if(id < 0 && row.getAttribute('fmfield') == 'address_type')
1555 widget.widget.attr('value', localeStrings.DEFAULT_ADDRESS_TYPE);
1557 // make new addresses valid by default
1558 if(id < 0 && row.getAttribute('fmfield') == 'valid')
1559 widget.widget.attr('value', true);
1561 // make new addresses use the org setting for default country
1562 if(id < 0 && row.getAttribute('fmfield') == 'country')
1563 widget.widget.attr('value',orgSettings['ui.patron.default_country']);
1565 } else if(row.getAttribute('name') == 'uedit-addr-pending-row') {
1567 // if it's a pending address, show the 'approve' button
1568 if(addr && openils.Util.isTrue(addr.pending())) {
1569 openils.Util.show(row, 'table-row');
1570 dojo.query('[name=approve-button]', row)[0].onclick =
1571 function() { uEditApproveAddress(addr); };
1573 if(addr.replaces()) {
1574 var div = dojo.query('[name=replaced-addr]', row)[0]
1575 var replaced = patron.addresses().filter(
1576 function(i) { return (i.id() == addr.replaces()) })[0];
1578 div.innerHTML = dojo.string.substitute(localeStrings.REPLACED_ADDRESS, [
1579 replaced.address_type() || '',
1580 replaced.street1() || '',
1581 replaced.street2() || '',
1582 replaced.city() || '',
1583 replaced.state() || '',
1584 replaced.post_code() || ''
1588 openils.Util.hide(dojo.query('[name=replaced-addr-div]', row)[0]);
1592 } else if(row.getAttribute('name') == 'uedit-addr-owner-row') {
1593 // address is owned by someone else. provide option to load the
1594 // user in a different tab
1596 if(addr && addr.usr() != patron.id()) {
1597 openils.Util.show(row, 'table-row');
1598 var link = getByName(row, 'addr-owner');
1600 // fetch the linked user so we can present their name in the UI
1602 if(cloneUserObj && cloneUserObj.id() == addr.usr()) {
1604 cloneUserObj.first_given_name(),
1605 cloneUserObj.second_given_name(),
1606 cloneUserObj.family_name()
1609 addrUser = fieldmapper.standardRequest(
1610 ['open-ils.actor', 'open-ils.actor.user.retrieve.parts'],
1612 openils.User.authtoken,
1614 ['first_given_name', 'second_given_name', 'family_name']
1619 link.innerHTML = (addrUser.map(function(name) { return (name) ? name+' ' : '' })+'').replace(/,/g,''); // TODO i18n
1620 link.onclick = function() {
1621 if(openils.XUL.isXUL()) {
1622 window.xulG.spawn_editor({ses:openils.User.authtoken, usr:addr.usr()})
1624 parent.location.href = location.href.replace(/clone=\d+/, 'usr=' + addr.usr());
1629 } else if(row.getAttribute('name') == 'uedit-addr-divider') {
1630 // link up the billing/mailing address and give the inputs IDs so we can access the later
1633 var ba = getByName(row, 'billing_address');
1634 ba.id = 'uedit-billing-address-' + id;
1635 if(mkLinks || (patron.billing_address() && patron.billing_address().id() == id))
1639 var ma = getByName(row, 'mailing_address');
1640 ma.id = 'uedit-mailing-address-' + id;
1641 if(mkLinks || (patron.mailing_address() && patron.mailing_address().id() == id))
1644 var btn = dojo.query('[name=delete-button]', row)[0];
1645 if(btn) btn.onclick = function(){ uEditDeleteAddr(id) };
1651 function uEditApproveAddress(addr) {
1652 fieldmapper.standardRequest(
1653 ['open-ils.actor', 'open-ils.actor.user.pending_address.approve'],
1655 params: [openils.User.authtoken, addr],
1657 oncomplete : function(r) {
1658 var oldId = openils.Util.readResponse(r);
1660 // remove addrs from UI
1663 function(addr) { uEditDeleteAddr(addr.id(), true); }
1668 // remove the replaced address
1669 if(oldId != addr.id()) {
1671 patron.addresses().filter(
1672 function(i) { return (i.id() != oldId); }
1677 // fix the the new address
1679 addr.replaces(null);
1692 function uEditDeleteAddr(id, noAlert) {
1693 if (patron.isnew() && orgSettings['ui.patron.registration.require_address']) {
1694 if (dojo.query('tr[name=uedit-addr-divider]').length < 2) {
1695 alert(localeStrings.NEED_ADDRESS);
1700 if(!confirm(dojo.string.substitute(localeStrings.DELETE_ADDRESS, [id]))) return;
1702 var addr = patron.addresses().filter(function(i){return (i.id() == id)})[0];
1703 if (addr) { addr.isdeleted(1); }
1704 var m_a = patron.mailing_address();
1705 if (typeof m_a == 'object' && m_a != null) { m_a = m_a.id(); }
1706 if (m_a == id) { patron.mailing_address(null); }
1707 var b_a = patron.billing_address();
1708 if (typeof b_a == 'object' && b_a != null) { b_a = b_a.id(); }
1709 if (b_a == id) { patron.billing_address(null); }
1711 var rows = dojo.query('tr[addr='+id+']', tbody);
1712 for(var i = 0; i < rows.length; i++)
1713 rows[i].parentNode.removeChild(rows[i]);
1714 widgetPile = widgetPile.filter(function(w){return (w._addr != id)});
1717 function uEditToggleRequired(level) {
1718 openils.Util.removeCSSClass(tbody, 'hide-non-required');
1719 openils.Util.removeCSSClass(tbody, 'hide-non-suggested');
1720 openils.Util.show('uedit-show-required');
1721 openils.Util.show('uedit-show-required-br');
1722 openils.Util.show('uedit-show-suggested');
1723 openils.Util.show('uedit-show-suggested-br');
1724 openils.Util.show('uedit-show-all');
1727 openils.Util.hide('uedit-show-required');
1728 openils.Util.hide('uedit-show-required-br');
1729 openils.Util.addCSSClass(tbody, 'hide-non-required');
1732 openils.Util.hide('uedit-show-suggested');
1733 openils.Util.hide('uedit-show-suggested-br');
1734 openils.Util.addCSSClass(tbody, 'hide-non-suggested');
1737 openils.Util.hide('uedit-show-all');
1742 function printable_output() {
1743 var temp; var s = '=-=-=-=\r\n';
1744 for (var idx in widgetPile) {
1745 var w = widgetPile[idx];
1746 var val = uEditWidgetVal(w);
1748 if (typeof w.idlField == 'undefined') {
1750 if (w._wtype == 'statcat') {
1751 var stat = statCats.filter(
1753 return (m.id() == w._statcat) })[0];
1754 label = stat.name();
1755 } else if (w._wtype == 'survey') {
1756 var survey = surveys.filter(
1758 return (m.id() == w._survey) })[0];
1759 var question = survey.questions().filter(
1761 return (m.id() == w._question) })[0];
1762 label = survey.name() + ' : ' + question.question();
1767 label = w.idlField.label;
1769 if (temp != w._wtype) {
1773 s += label + ':\t' + (typeof val == 'object' ? '' : val) + '\r\n';
1779 openils.Util.addOnLoad(load);