1 dump('entering patron.summary.js\n');
3 function $(id) { return document.getElementById(id); }
4 var patronStrings = $('patronStrings');
6 if (typeof patron == 'undefined') patron = {};
7 patron.summary = function (params) {
9 JSAN.use('util.error'); this.error = new util.error();
10 JSAN.use('util.window'); this.window = new util.window();
11 JSAN.use('util.network'); this.network = new util.network();
15 patron.summary.prototype = {
17 'init' : function( params ) {
21 obj.barcode = params['barcode'];
22 obj.id = params['id'];
23 if (params['show_name']) {
24 document.getElementById('patron_name').hidden = false;
25 document.getElementById('patron_name').setAttribute('hidden','false');
28 JSAN.use('OpenILS.data'); this.OpenILS = {};
29 obj.OpenILS.data = new OpenILS.data(); obj.OpenILS.data.init({'via':'stash'});
31 JSAN.use('util.controller'); obj.controller = new util.controller();
37 function() { alert($("commonStrings").getString('common.unimplemented')); }
43 JSAN.use('util.widgets');
44 util.widgets.remove_children( e );
45 if (obj.patron.alert_message()) {
47 document.createTextNode(
48 obj.patron.alert_message()
51 e.parentNode.hidden = false;
53 e.parentNode.hidden = true;
62 e.setAttribute('value',obj.patron.usrname());
70 e.setAttribute('value',
71 obj.OpenILS.data.hash.pgt[
78 'patron_net_access' : [
82 e.setAttribute('value',
83 patronStrings.getString('staff.patron.summary.patron_net_access') +
84 ' ' + obj.OpenILS.data.hash.cnal[
85 obj.patron.net_access_level()
91 'patron_standing_penalties' : [
95 JSAN.use('util.widgets');
96 util.widgets.remove_children(e);
97 var penalties = obj.patron.standing_penalties();
98 if (penalties.length == 0) {
99 var row = document.createElement('row');
100 var label = document.createElement('label');
101 label.setAttribute('value',patronStrings.getString('staff.patron.summary.standing_penalty.none'));
102 addCSSClass(label,'NO_PENALTY');
103 row.appendChild(label);
106 for (var i = 0; i < penalties.length; i++) {
108 var row = document.createElement('row');
109 var label = document.createElement('label');
111 //x.setAttribute('value',penalties[i].penalty_type());
112 label.setAttribute('value',penalties[i].standing_penalty().label());
113 row.appendChild(label);
115 var button = document.createElement('button');
116 button.setAttribute('label', patronStrings.getString('staff.patron.summary.standing_penalty.remove'));
117 button.setAttribute('image','/xul/server/skin/media/images/icon_delete.gif');
118 button.setAttribute('disabled','true');
119 button.setAttribute('hidden','true');
120 button.setAttribute('retrieve_ausp_id',penalties[i].id());
121 row.appendChild(button);
123 // XXX check a permission here? How to fire the remove action ??? XXX
124 if (penalties[i].standing_penalty().id() > 100) {
125 button.setAttribute('disabled','false');
126 button.setAttribute('hidden','false');
127 button.addEventListener(
131 JSAN.use('util.functional');
132 var id = ev.target.getAttribute('retrieve_ausp_id');
133 var penalty = util.functional.find_list( obj.patron.standing_penalties(), function(o) { return o.id() == id; } );
134 penalty.isdeleted(1);
136 var req = obj.network.simple_request( 'FM_AUSP_REMOVE', [ ses(), penalty ] );
137 if (typeof req.ilsevent != 'undefined' || String(req) != '1') {
138 obj.error.standard_unexpected_error_alert(
139 patronStrings.getFormattedString(
140 'staff.patron.standing_penalty.remove_error',
141 [obj.data.hash.csp[id].name()]
146 if (typeof xulG.refresh == 'function') { xulG.refresh(); }
148 obj.error.standard_unexpected_error_alert(
149 patronStrings.getFormattedString(
150 'staff.patron.standing_penalty.remove_error',
151 [ev.target.getAttribute('retrieve_ausp_id')]
161 if (penalties[i].standing_penalty().block_list()) {
162 if (penalties[i].standing_penalty().block_list().match(/RENEW/)) addCSSClass(label,'PENALTY_RENEW');
163 if (penalties[i].standing_penalty().block_list().match(/HOLD/)) addCSSClass(label,'PENALTY_HOLD');
164 if (penalties[i].standing_penalty().block_list().match(/CIRC/)) addCSSClass(label,'PENALTY_CIRC');
176 JSAN.use('util.money');
177 e.setAttribute('value',
180 obj.patron.credit_forward_balance()
190 e.setAttribute('value','...');
191 obj.network.simple_request(
192 'FM_MOUS_RETRIEVE.authoritative',
193 [ ses(), obj.patron.id() ],
195 JSAN.use('util.money');
196 var robj = req.getResultObject();
197 e.setAttribute('value', patronStrings.getFormattedString('staff.patron.summary.patron_bill.money', [util.money.sanitize( robj.balance_owed() )]));
201 obj.network.simple_request(
202 'FM_MBTS_IDS_RETRIEVE_ALL_HAVING_BALANCE.authoritative',
203 [ ses(), obj.patron.id() ],
205 JSAN.use('util.money');
206 var list = req.getResultObject();
207 if (typeof list.ilsevent != 'undefined') {
208 e.setAttribute('value', '??? See Bills');
212 for (var i = 0; i < list.length; i++) {
213 var robj = typeof list[i] == 'object' ? list[i] : obj.network.simple_request('FM_MBTS_RETRIEVE.authoritative',[ses(),list[i]]);
214 sum += util.money.dollars_float_to_cents_integer( robj.balance_owed() );
216 if (sum > 0) addCSSClass(document.documentElement,'PATRON_HAS_BILLS');
217 JSAN.use('util.money');
218 e.setAttribute('value', '$' + util.money.sanitize( util.money.cents_as_dollars( sum ) ));
225 'patron_checkouts' : [
229 e.setAttribute('value','...');
230 var e2 = document.getElementById( 'patron_overdue' ); if (e2) e2.setAttribute('value','...');
231 var e3 = document.getElementById( 'patron_claimed_returned' ); if (e3) e3.setAttribute('value','...');
232 var e4 = document.getElementById( 'patron_long_overdue' ); if (e4) e4.setAttribute('value','...');
233 var e5 = document.getElementById( 'patron_lost' ); if (e5) e5.setAttribute('value','...');
234 var e6 = document.getElementById( 'patron_noncat' ); if (e6) e6.setAttribute('value','...');
235 obj.network.simple_request(
236 'FM_CIRC_COUNT_RETRIEVE_VIA_USER.authoritative',
237 [ ses(), obj.patron.id() ],
240 var robj = req.getResultObject();
241 e.setAttribute('value', robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
242 if (e2) e2.setAttribute('value', robj.overdue );
243 if (e3) e3.setAttribute('value', robj.claims_returned );
244 if (e4) e4.setAttribute('value', robj.long_overdue );
245 if (e5) e5.setAttribute('value', robj.lost );
251 obj.network.simple_request(
252 'FM_ANCC_RETRIEVE_VIA_USER.authoritative',
253 [ ses(), obj.patron.id() ],
255 var robj = req.getResultObject();
256 if (e6) e6.setAttribute('value',robj.length);
266 /* handled by 'patron_checkouts' */
274 e.setAttribute('value','...');
275 var e2 = document.getElementById('patron_holds_available');
276 if (e2) e2.setAttribute('value','...');
277 obj.network.simple_request(
278 'FM_AHR_COUNT_RETRIEVE.authoritative',
279 [ ses(), obj.patron.id() ],
281 e.setAttribute('value',
282 req.getResultObject().total
284 if (e2) e2.setAttribute('value',
285 req.getResultObject().ready
292 'patron_holds_available' : [
296 /* handled by 'patron_holds' */
304 e.setAttribute('value',
305 obj.patron.card().barcode()
310 'patron_ident_type_1' : [
314 var ident_string = '';
315 var ident = obj.OpenILS.data.hash.cit[
316 obj.patron.ident_type()
318 if (ident) ident_string = ident.name()
319 e.setAttribute('value',
325 'patron_ident_value_1' : [
329 var val = obj.patron.ident_value();
330 val = val.replace(/.+(\d\d\d\d)$/,'xxxx$1');
331 e.setAttribute('value', val);
335 'patron_ident_type_2' : [
339 var ident_string = '';
340 var ident = obj.OpenILS.data.hash.cit[
341 obj.patron.ident_type2()
343 if (ident) ident_string = ident.name()
344 e.setAttribute('value',
350 'patron_ident_value_2' : [
354 var val = obj.patron.ident_value2();
355 val = val.replace(/.+(\d\d\d\d)$/,'xxxx$1');
356 e.setAttribute('value', val);
360 'patron_date_of_exp' : [
364 e.setAttribute('value',
365 patronStrings.getString('staff.patron.summary.expires_on') + ' ' + (
366 obj.patron.expire_date() ?
367 obj.patron.expire_date().substr(0,10) :
374 'patron_date_of_birth' : [
378 e.setAttribute('value',
380 obj.patron.dob().substr(0,10) :
386 'patron_day_phone' : [
390 e.setAttribute('value',
391 obj.patron.day_phone()
396 'patron_evening_phone' : [
400 e.setAttribute('value',
401 obj.patron.evening_phone()
406 'patron_other_phone' : [
410 e.setAttribute('value',
411 obj.patron.other_phone()
420 e.setAttribute('value',
430 e.setAttribute('value',
436 'patron_photo_url' : [
440 e.setAttribute('src',
441 obj.patron.photo_url()
450 e.setAttribute('value',
451 obj.OpenILS.data.hash.aou[
455 e.setAttribute('tooltiptext',
456 obj.OpenILS.data.hash.aou[
463 'patron_last_library' : [
467 e.setAttribute('value',
468 obj.OpenILS.data.hash.aou[
472 e.setAttribute('tooltiptext',
473 obj.OpenILS.data.hash.aou[
480 'patron_mailing_address_street1' : [
484 e.setAttribute('value',
485 obj.patron.mailing_address().street1()
487 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
491 'patron_mailing_address_street2' : [
495 e.setAttribute('value',
496 obj.patron.mailing_address().street2()
498 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
502 'patron_mailing_address_city' : [
506 e.setAttribute('value',
507 obj.patron.mailing_address().city()
509 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
513 'patron_mailing_address_state' : [
517 e.setAttribute('value',
518 obj.patron.mailing_address().state()
520 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
524 'patron_mailing_address_post_code' : [
528 e.setAttribute('value',
529 obj.patron.mailing_address().post_code()
531 if (!get_bool(obj.patron.mailing_address().valid())){e.setAttribute('style','color: red');}
535 'patron_physical_address_street1' : [
539 e.setAttribute('value',
540 obj.patron.billing_address().street1()
542 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
546 'patron_physical_address_street2' : [
550 e.setAttribute('value',
551 obj.patron.billing_address().street2()
553 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
557 'patron_physical_address_city' : [
561 e.setAttribute('value',
562 obj.patron.billing_address().city()
564 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
568 'patron_physical_address_state' : [
572 e.setAttribute('value',
573 obj.patron.billing_address().state()
575 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
579 'patron_physical_address_post_code' : [
583 e.setAttribute('value',
584 obj.patron.billing_address().post_code()
586 if (!get_bool(obj.patron.billing_address().valid())){e.setAttribute('style','color: red');}
597 var caption = document.getElementById("PatronSummaryContact_caption");
598 var arrow = document.getAnonymousNodes(caption)[0];
599 var gb_content = document.getAnonymousNodes(caption.parentNode)[1];
600 arrow.addEventListener(
605 //alert('setting shrink_state to ' + gb_content.hidden);
606 //caption.setAttribute('shrink_state',gb_content.hidden);
607 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
608 JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
609 file.set_object(String(gb_content.hidden)); file.close();
614 //var shrink_state = caption.getAttribute('shrink_state');
615 var shrink_state = false;
616 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
617 JSAN.use('util.file'); var file = new util.file('patron_id_shrink');
618 if (file._file.exists()) {
619 shrink_state = file.get_object(); file.close();
621 //alert('shrink_state retrieved as ' + shrink_state);
622 if (shrink_state != 'false' && shrink_state) {
623 JSAN.use('util.widgets');
624 //alert('clicking the widget');
625 util.widgets.click( arrow );
628 obj.error.sdump('D_ERROR','with shrink_state in summary.js: ' + E);
632 'retrieve' : function() {
640 // Retrieve the patron
641 function blah_retrieve() {
644 if (obj.barcode && obj.barcode != 'null') {
645 robj = obj.network.simple_request(
646 'FM_AU_RETRIEVE_VIA_BARCODE.authoritative',
647 [ ses(), obj.barcode ]
649 } else if (obj.id && obj.id != 'null') {
650 robj = obj.network.simple_request(
651 'FM_AU_FLESHED_RETRIEVE_VIA_ID',
655 throw(patronStrings.getString('staff.patron.summary.retrieve.no_barcode'));
659 if (instanceOf(robj,au)) {
662 JSAN.use('patron.util');
663 document.getElementById('patron_name').setAttribute('value',
664 ( obj.patron.prefix() ? obj.patron.prefix() + ' ' : '') +
665 obj.patron.family_name() + ', ' +
666 obj.patron.first_given_name() + ' ' +
667 ( obj.patron.second_given_name() ? obj.patron.second_given_name() + ' ' : '' ) +
668 ( obj.patron.suffix() ? obj.patron.suffix() : '')
670 patron.util.set_penalty_css(obj.patron);
671 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
672 data.last_patron = obj.patron.id(); data.stash('last_patron');
692 // Retrieve the survey responses for required surveys
696 var surveys = obj.OpenILS.data.list.my_asv;
697 var survey_responses = {};
698 for (var i = 0; i < surveys.length; i++) {
699 var s = obj.network.request(
700 api.FM_ASVR_RETRIEVE.app,
701 api.FM_ASVR_RETRIEVE.method,
702 [ ses(), surveys[i].id(), obj.patron.id() ]
704 survey_responses[ surveys[i].id() ] = s;
706 obj.patron.survey_responses( survey_responses );
708 var error = ('patron.summary.retrieve : ' + js2JSON(E));
709 obj.error.sdump('D_ERROR',error);
717 chain.push( function() { obj.controller.render(); } );
721 chain.push( function() {
723 if (typeof window.xulG == 'object' && typeof window.xulG.on_finished == 'function') {
724 obj.error.sdump('D_PATRON_SUMMARY',
725 'patron.summary: Calling external .on_finished()\n');
726 window.xulG.on_finished(obj.patron);
728 obj.error.sdump('D_PATRON_SUMMARY','patron.summary: No external .on_finished()\n');
734 JSAN.use('util.exec'); obj.exec = new util.exec();
735 obj.exec.on_error = function(E) {
737 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
738 window.xulG.on_error(E);
744 this.exec.chain( chain );
747 if (typeof window.xulG == 'object' && typeof window.xulG.on_error == 'function') {
748 window.xulG.on_error(E);
756 dump('exiting patron.summary.js\n');