broke the fines display into various parts. more work to come
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / myopac.js
1
2 attachEvt("common", "run", myOPACInit );
3 attachEvt("common", "loggedIn", myOPACInit );
4
5 attachEvt('common','locationUpdated', myopacReload );
6
7 var fleshedUser = null;
8 var fleshedContainers = {};
9
10
11 function clearNodes( node, keepArray ) {
12         if(!node) return;
13         for( var n in keepArray ) node.removeChild(keepArray[n]);
14         removeChildren(node);
15         for( var n in keepArray ) node.appendChild(keepArray[n]);
16 }
17
18 function myOPACInit() {
19         if(!(G.user && G.user.session)) initLogin();
20         else myOPACChangePage( "summary" );
21 }
22
23 function myopacReload() {
24         swapCanvas($('myopac_reloading'));
25         //alert($('myopac_reloading').className);
26         var a = {};
27         a[PARAM_LOCATION] = getNewSearchLocation();
28         a[PARAM_DEPTH] = getNewSearchDepth();
29         goTo(buildOPACLink(a, true));
30 }
31
32
33 function myOPACChangePage( page ) {
34         
35         var s = $("myopac_summary_td");
36         var c = $("myopac_checked_td");
37         var f = $("myopac_fines_td");
38         var h = $("myopac_holds_td");
39         var p = $("myopac_prefs_td");
40         var b = $('myopac_bookbag_td');
41
42         var ss = $("myopac_summary_div");
43         var cc = $("myopac_checked_div");
44         var ff = $("myopac_fines_div");
45         var hh = $("myopac_holds_div");
46         var pp = $("myopac_prefs_div");
47         var bb = $('myopac_bookbag_div');
48
49         var cls = "myopac_link";
50         var acls = "myopac_link_active";
51
52         hideMe(ss);
53         hideMe(cc); hideMe(ff);
54         hideMe(hh); hideMe(pp);
55         hideMe(bb);
56
57         removeCSSClass(s, acls );
58         removeCSSClass(c, acls );
59         removeCSSClass(f, acls );
60         removeCSSClass(h, acls );
61         removeCSSClass(p, acls );
62         removeCSSClass(b, acls );
63
64         switch( page ) {
65
66                 case "summary": 
67                         unHideMe(ss);
68                         addCSSClass(s, acls );
69                         myOPACShowSummary();
70                         break;
71
72                 case "checked": 
73                         unHideMe(cc);
74                         addCSSClass(c, acls );
75                         myOPACShowChecked();
76                         break;
77
78                 case "holds": 
79                         unHideMe(hh);
80                         addCSSClass(h, acls );
81                         myOPACShowHolds();
82                         break;
83
84                 case "fines": 
85                         unHideMe(ff);
86                         addCSSClass(f, acls );
87                         myOPACShowFines();
88                         break;
89
90                 case "prefs": 
91                         unHideMe(pp);
92                         addCSSClass(p, acls );
93                         myOPACShowPrefs();
94                         break;
95
96                 case 'bookbag':
97                         unHideMe(bb);
98                         addCSSClass(b, acls);
99                         myOPACShowBookbags();
100                         break;
101         }
102
103         /*
104         alert('Classes:\n' + s.className + '\n' + c.className + 
105                 '\n' + h.className + '\n' + f.className + '\n' + p.className);
106                 */
107 }
108
109 function myOPACShowChecked() {
110         if(checkedDrawn) return;
111         var req = new Request(FETCH_CHECKED_OUT_SLIM, G.user.session);  
112         req.callback(myOPACDrawCheckedOutSlim);
113         req.send();
114 }
115
116
117 var checkedRowTemplate;
118 var circsCache = new Array();
119 var checkedDrawn = false;
120
121 function myOPACDrawCheckedOutSlim(r) {
122
123         var checked                     = r.getResultObject();
124         var tbody                       = $("myopac_checked_tbody");
125         var loading                     = $("myopac_checked_loading");
126         var none                                = $("myopac_checked_none");
127
128         if(checkedDrawn) return;
129         checkedDrawn = true;
130         if(!checkedRowTemplate) 
131                 checkedRowTemplate = tbody.removeChild($("myopac_checked_row"));
132
133         clearNodes( tbody, [ loading, none ] );
134
135         hideMe(loading); /* remove all children and start over */
136         if(!(checked && checked[0])) unHideMe(none);
137
138         for( var idx in checked ) {
139
140                 var circ    = checked[idx]
141                 var row = checkedRowTemplate.cloneNode(true);
142                 row.id = 'myopac_checked_row_ ' + circ.id();
143
144                 var due = circ.due_date();
145       due = due.replace(/[0-9][0-9]:.*$/,"");
146
147                 var dlink = $n( row, "myopac_checked_due" );
148                 var rlink = $n( row, "myopac_checked_renewals" );
149                 var rnlink = $n( row, "myopac_checked_renew_link" );
150
151                 dlink.appendChild(text(due));
152                 rlink.appendChild(text(circ.renewal_remaining()));
153                 unHideMe(row);
154                 rnlink.setAttribute('href', 'javascript:myOPACRenewCirc("'+circ.id()+'");');
155                 circsCache.push(circ);
156
157                 tbody.appendChild(row);
158
159                 var req = new Request(FETCH_MODS_FROM_COPY, circ.target_copy() );
160                 req.request.circ = circ.id();
161                 req.request.copy = circ.target_copy();
162                 req.callback(myOPACDrawCheckedTitle);
163                 req.send();
164         }
165 }
166
167 function myOPACDrawCheckedTitle(r) {
168         var record = r.getResultObject();
169         var circid = r.circ;
170
171         if(!record || checkILSEvent(record)) {
172                 var req = new Request( FETCH_COPY, r.copy );
173                 req.request.circ = circid
174                 req.callback(myOPACDrawNonCatalogedItem);
175                 req.send();
176                 return;
177         }
178
179         var row = $('myopac_checked_row_ ' + circid);
180         var tlink = $n( row, "myopac_checked_title_link" );
181         var alink = $n( row, "myopac_checked_author_link" );
182         buildTitleDetailLink(record, tlink);
183         buildSearchLink(STYPE_AUTHOR, record.author(), alink);
184 }
185
186 function myOPACDrawNonCatalogedItem(r) {
187         var copy = r.getResultObject();
188         var circid = r.circ;
189         var row = $('myopac_checked_row_ ' + circid);
190         var tlink = $n( row, "myopac_checked_title_link" );
191         var alink = $n( row, "myopac_checked_author_link" );
192         //tlink.appendChild(text(copy.dummy_title()));
193         //alink.appendChild(text(copy.dummy_author()));
194
195         tlink.parentNode.appendChild(text(copy.dummy_title()));
196         alink.parentNode.appendChild(text(copy.dummy_author()));
197
198         /*
199         tlink.setAttribute('href', null);
200         alink.setAttribute('href', null);
201         alert(alink.getAttribute('href'));
202         */
203 }
204
205
206 function myOPACRenewCirc(circid) {
207         alert("Functionality currently under construction");
208         return;
209
210         var circ;
211         for( var i = 0; i != circsCache.length; i++ ) 
212                 if(circsCache[i].id() == circid)
213                         circ = circsCache[i];
214
215         var req = new Request(RENEW_CIRC, G.user.session, circ );
216         req.send(true);
217         var res = req.result();
218         if(res.status) {
219                 alert(res.text);
220                 return;
221         }
222         alert($('myopac_renew_success').innerHTML);     
223         checkedDrawn = false;
224         myOPACShowChecked();
225 }
226
227
228
229 function myOPACShowHolds() {
230         var req = new Request(FETCH_HOLDS, G.user.session, G.user.id());        
231         req.callback(myOPACDrawHolds);
232         req.send();
233 }
234
235 var holdsTemplateRowOrig;
236 var holdsTemplateRow;
237 function myOPACDrawHolds(r) {
238
239         var tbody = $("myopac_holds_tbody");
240         if(holdsTemplateRow) return;
241         if(holdsTemplateRowOrig) {
242                 holdsTemplateRow = holdsTemplateRowOrig;
243                 removeChildren(tbody);
244         } else {
245                 holdsTemplateRow = tbody.removeChild($("myopac_holds_row"));
246                 holdsTemplateRowOrig = holdsTemplateRow;
247         }
248
249         hideMe($('myopac_holds_loading'));
250
251         var holds = r.getResultObject();
252
253         if(!holds || holds.length < 1) unHideMe($('myopac_holds_none'));
254         for( var i = 0; i != holds.length; i++ ) {
255
256                 var h = holds[i];
257                 var row = holdsTemplateRow.cloneNode(true);
258                 row.id = "myopac_holds_row_" + h.id() + '_' + h.target();
259
260                 var formats = (h.holdable_formats()) ? h.holdable_formats() : null;
261                 var form = $n(row, "myopac_holds_formats");
262                 form.id = "myopac_holds_form_" + h.id() + '_' + h.target();
263                 if(formats) form.appendChild(text(formats));
264
265                 $n(row, "myopac_holds_location").
266                         appendChild(text(findOrgUnit(h.pickup_lib()).name()));
267                 $n(row, "myopac_holds_email_link").
268                         appendChild(text(h.email_notify()));
269                 $n(row, "myopac_holds_phone_link").
270                         appendChild(text(h.phone_notify()));
271                 tbody.appendChild(row);
272
273                 $n(row,'myopac_holds_cancel_link').setAttribute(
274                         'href','javascript:myOPACCancelHold("'+ h.id()+'");'); 
275                 unHideMe(row);
276
277                 myOPACDrawHoldTitle(h);
278         }
279 }
280
281 function myOPACCancelHold(holdid) {
282         if( confirm($('myopac_holds_cancel_verify').innerHTML) ) {
283                 holdsCancel(holdid);
284                 holdsTemplateRow = null
285                 myOPACShowHolds();
286         }
287 }
288
289
290
291 function myOPACDrawHoldTitle(hold) {
292         var method;
293         if(hold.hold_type() == "M") method = FETCH_MRMODS;
294         if(hold.hold_type() == "T") method = FETCH_RMODS;
295         var req = new Request(method, hold.target());
296         req.callback(myOPACFleshHoldTitle);
297         req.request.hold = hold.id();
298         req.send();
299 }
300
301 function myOPACFleshHoldTitle(r) {
302
303         var record = r.getResultObject();
304         var row = $("myopac_holds_row_" + r.hold + '_' + record.doc_id());
305         var title_link = $n(row, "myopac_holds_title_link");
306         var author_link = $n(row, "myopac_holds_author_link");
307
308         buildTitleDetailLink(record, title_link);
309         buildSearchLink(STYPE_AUTHOR, record.author(), author_link);
310
311         var form = $("myopac_holds_form_" + r.hold + '_' + record.doc_id());
312
313         if(form) {
314                 var img = elem("img");
315                 img.setAttribute("src", 
316                         buildImageLink('tor/' + record.types_of_resource()[0] + ".jpg"));
317                 addCSSClass(img, "myopac_form_pic");
318                 form.appendChild(img);
319         }
320 }
321
322 var finesShown = false;
323 function myOPACShowFines() {
324         if(finesShown) return; finesShown = true;
325         var req = new Request(FETCH_FINES_SUMMARY, G.user.session, G.user.id() );
326         req.callback(_myOPACShowFines);
327         req.send();
328 }
329
330 function _myOPACShowFines(r) {
331         hideMe($('myopac_fines_summary_loading'));
332         unHideMe($('myopac_fines_summary_row'));
333
334         var summary = r.getResultObject();
335         var total       = "0.00"; /* localization? */
336         var paid                = "0.00";
337         var balance = "0.00";
338         if( instanceOf(summary,mous) ) {
339
340                 total           = _finesFormatNumber(summary.total_owed());
341                 paid            = _finesFormatNumber(summary.total_paid());
342                 balance = _finesFormatNumber(summary.balance_owed());
343
344                 var req = new Request(FETCH_TRANSACTIONS, G.user.session, G.user.id() );
345                 req.callback(myOPACShowTransactions);
346                 req.send();
347         }
348
349         $('myopac_fines_summary_total').appendChild(text(total));
350         $('myopac_fines_summary_paid').appendChild(text(paid));
351         $('myopac_fines_summary_balance').appendChild(text(balance));
352 }
353
354 function _finesFormatNumber(num) {
355         if(isNull(num)) num = 0;
356         num = num + "";
357         if(num.length < 2 || !num.match(/\./)) num += ".00";
358         if(num.match(/\./) && num.charAt(num.length-2) == '.') num += "0";
359         return num;
360 }          
361
362 function _trimTime(time) { if(!time) return ""; return time.replace(/\ .*/,""); }
363
364 function _trimSeconds(time) { if(!time) return ""; return time.replace(/\..*/,""); }
365
366
367 function myOPACShowTransactions(r) {
368
369         if(myopacGenericTransTemplate || myopacCircTransTemplate) return;
370
371         var transactions = r.getResultObject();
372
373         for( var idx in transactions ) {
374
375                 var trans       = transactions[idx].transaction;
376                 var record      = transactions[idx].record;
377                 var circ                = transactions[idx].circ;
378
379                 if(trans.xact_type() == 'circulation') 
380                         myOPACShowCircTransaction(trans, record, circ);
381
382                 else if(trans.xact_type() == 'grocery' ) 
383                         myopacShowGenericTransaction( trans );
384         }
385 }
386
387 var myopacGenericTransTemplate;
388 function myopacShowGenericTransaction( trans ) {
389         var tbody = $('myopac_trans_tbody');
390
391         if(!myopacGenericTransTemplate) {
392                 myopacGenericTransTemplate = 
393                         tbody.removeChild($('myopac_trans_row'));
394                 removeChildren(tbody);
395         }
396
397         var row = myopacGenericTransTemplate.cloneNode(true);
398
399         $n(row,'myopac_trans_start').appendChild(
400                         text(_trimSeconds(trans.xact_start())));
401
402         $n(row,'myopac_trans_last_payment').appendChild(
403                         text(_trimSeconds(trans.last_payment_ts())));
404
405         $n(row,'myopac_trans_init_amount').appendChild(
406                         text(_finesFormatNumber(trans.total_owed())));
407
408         $n(row,'myopac_trans_total_paid').appendChild(
409                         text(_finesFormatNumber(trans.total_paid())));
410
411         $n(row,'myopac_trans_balance').appendChild(
412                         text(_finesFormatNumber(trans.balance_owed())));
413
414         var req = new Request(FETCH_MONEY_BILLING, G.user.session, trans.id());
415         req.send(true);
416         var bills = req.result();
417         if(bills && bills[0])
418                 $n(row,'myopac_trans_bill_type').appendChild(
419                                 text(bills[0].billing_type()));
420
421         tbody.appendChild(row);
422         unHideMe($('myopac_trans_table'));
423 }
424
425
426
427 /* draws a circulation transaction summary */
428 var myopacCircTransTemplate;
429 function myOPACShowCircTransaction(trans, record, circ) {
430         var tbody = $('myopac_circ_trans_tbody');
431
432         if(!myopacCircTransTemplate) {
433                 myopacCircTransTemplate = tbody.removeChild($('myopac_circ_trans_row'));
434                 removeChildren(tbody);
435         }
436
437         var row = myopacCircTransTemplate.cloneNode(true);
438
439         buildTitleDetailLink(record, $n(row,'myopac_circ_trans_title'));
440
441         $n(row,'myopac_circ_trans_author').appendChild(text(
442                 normalize(truncate(record.author(), 65))));
443
444         $n(row,'myopac_circ_trans_start').
445                 appendChild(text(_trimTime(trans.xact_start())));
446
447    var due = _trimTime(circ.due_date());
448         var checkin = _trimTime(circ.stop_fines_time());
449
450         $n(row,'myopac_circ_trans_due').appendChild(text(due))
451         $n(row,'myopac_circ_trans_finished').appendChild(text(checkin))
452
453         $n(row,'myopac_circ_trans_balance').
454                 appendChild(text(_finesFormatNumber(trans.balance_owed())));
455
456         tbody.appendChild(row);
457         unHideMe($('myopac_circ_trans_table'));
458 }
459
460
461 function myOPACSavePrefs() {
462         G.user.prefs[PREF_HITS_PER] = getSelectorVal($('prefs_hits_per'));
463         if(commitUserPrefs())
464                 alert($('prefs_update_success').innerHTML);
465         else alert($('prefs_update_failure').innerHTML);
466 }
467
468
469 function myOPACShowPrefs() {
470         grabUserPrefs();
471         myOPACShowHitsPer();
472         hideMe($('myopac_prefs_loading'));
473         unHideMe($('myopac_prefs_row'));
474 }
475
476 function myOPACShowHitsPer() {
477         var hits = 10;
478         if(G.user.prefs[PREF_HITS_PER])
479                 hits = G.user.prefs[PREF_HITS_PER];
480         var hitsSel = $('prefs_hits_per');
481         setSelector(hitsSel, hits);
482 }
483
484 var userShown = false;
485 function myOPACShowSummary() {
486         if(userShown) return; userShown = true;
487         var req = new Request(FETCH_FLESHED_USER,G.user.session, G.user.id());
488         req.callback(_myOPACSummaryShowUer);
489         req.send();
490 }
491
492 var addrRowTemplate;
493 function _myOPACSummaryShowUer(r) {
494
495         var user = r.getResultObject();
496         fleshedUser = user;
497
498         appendClear($('myopac_summary_first'),text(user.first_given_name()));
499         appendClear($('myopac_summary_middle'),text(user.second_given_name()));
500         appendClear($('myopac_summary_dayphone'),text(user.day_phone()));
501         appendClear($('myopac_summary_eveningphone'),text(user.evening_phone()));
502         appendClear($('myopac_summary_otherphone'),text(user.other_phone()));
503         appendClear($('myopac_summary_last'),text(user.family_name()));
504         appendClear($('myopac_summary_username'),text(user.usrname()));
505         appendClear($('myopac_summary_email'),text(user.email()));
506         appendClear($('myopac_summary_barcode'),text(user.card().barcode()));
507         appendClear($('myopac_summary_ident1'),text(user.ident_value()));
508         appendClear($('myopac_summary_ident2'),text(user.ident_value2()));
509         appendClear($('myopac_summary_homelib'),text(findOrgUnit(user.home_ou()).name()));
510         appendClear($('myopac_summary_create_date'),text(user.create_date()));
511
512         var tbody = $('myopac_addr_tbody');
513         var template;
514
515         if(addrRowTemplate) { 
516                 template = addrRowTemplate;
517         } else {
518                 template = tbody.removeChild($('myopac_addr_row'));
519                 addrRowTemplate = template;
520         }
521         removeChildren(tbody);
522
523         for( var a in user.addresses() ) {
524                 var row = template.cloneNode(true);
525                 myOPACDrawAddr(row, user.addresses()[a]);
526                 tbody.appendChild(row);
527         }
528 }
529
530 function myOPACDrawAddr(row, addr) {
531
532         appendClear($n(row, 'myopac_addr_type'),text(addr.address_type()));
533         var street = (addr.street2()) ? addr.street1() + ", " + addr.street2() : addr.street1();
534         appendClear($n(row, 'myopac_addr_street'),text(street));
535         appendClear($n(row, 'myopac_addr_city'),text(addr.city()));
536         appendClear($n(row, 'myopac_addr_county'),text(addr.county()));
537         appendClear($n(row, 'myopac_addr_state'),text(addr.state()));
538         appendClear($n(row, 'myopac_addr_zip'),text(addr.post_code()));
539 }
540
541
542 function myOPACUpdateUsername() {
543         var username = $('myopac_new_username').value;
544         if(username == null || username == "") {
545                 alert($('myopac_username_error').innerHTML);
546                 return;
547         }
548         var req = new Request(UPDATE_USERNAME, G.user.session, username );
549         req.send(true);
550         if(req.result()) {
551
552                 var evt;
553                 if(evt = checkILSEvent(req.result())) {
554                         alertILSEvent(evt);
555                         return;
556                 }
557
558                 G.user.usrname(username);
559                 hideMe($('myopac_update_username_row'));
560                 userShown = false;
561                 myOPACShowSummary();
562                 return;
563         }
564
565         alert($('myopac_username_failure').innerHTML);
566 }
567
568 function myOPACUpdateEmail() {
569         var email = $('myopac_new_email').value;
570         if(email == null || email == "") {
571                 alert($('myopac_email_error').innerHTML);
572                 return;
573         }
574
575         var req = new Request(UPDATE_EMAIL, G.user.session, email );
576         req.send(true);
577         if(req.result()) {
578                 G.user.usrname(email);
579                 hideMe($('myopac_update_email_row'));
580                 userShown = false;
581                 myOPACShowSummary();
582                 return;
583         }
584
585         alert($('myopac_email_failure').innerHTML);
586 }
587
588
589 function myOPACUpdatePassword() {
590         var curpassword = $('myopac_current_password').value;
591         var password = $('myopac_new_password').value;
592         var password2 = $('myopac_new_password2').value;
593
594         if(     curpassword == null || curpassword == "" || 
595                         password == null || password == "" || 
596                         password2 == null || password2 == "" || password != password2 ) {
597                 alert($('myopac_password_error').innerHTML);
598                 return;
599         }
600
601         var req = new Request(UPDATE_PASSWORD, G.user.session, password, curpassword );
602         req.send(true);
603         if(req.result()) {
604                 G.user.usrname(password);
605                 hideMe($('myopac_update_password_row'));
606                 userShown = false;
607                 myOPACShowSummary();
608                 return;
609         }
610
611         alert($('myopac_password_failure').innerHTML);
612 }
613
614
615
616
617 var containerTemplate;
618 function myOPACShowBookbags(force) {
619
620         var tbody =$('myopac_bookbag_tbody') ;
621
622         if(!containerTemplate) 
623                 containerTemplate = tbody.removeChild($('myopac_bookbag_tr'));
624         else if(!force) return;
625
626         removeChildren(tbody);
627
628         var containers = containerFetchAll();
629
630         var found = false;
631         for( var i in containers ) {
632                 found = true;
633                 var cont = containers[i];
634                 var row = containerTemplate.cloneNode(true);
635                 row.id = 'myopac_bookbag_row_' + cont.id();
636                 var link = $n(row, 'myopac_expand_bookbag');
637                 var dlink = $n(row, 'myopac_container_delete');
638                 link.appendChild( text(cont.name()) );
639                 link.setAttribute('href', 
640                         'javascript:myOPACExpandBookbag("' + cont.id() + '","' + cont.name() + '");');
641                 myOPACFetchBBItems( cont.id(), row );
642                 dlink.setAttribute('href', 'javascript:myOPACDeleteBookbag("'+cont.id()+'");');
643
644                 if( cont.pub() ) {
645                         unHideMe($n(row, 'myopac_bb_published_yes'));
646                         var link = $n(row, 'myopac_bb_published_view');
647                         link.setAttribute('href', buildExtrasLink( 'bbags.xml?bb='+cont.id(), false));  
648                         link.setAttribute('target', '_blank' );
649                         unHideMe(link);
650
651                 } else { 
652                         unHideMe($n(row, 'myopac_bb_published_no')); 
653                 }
654
655                 tbody.appendChild(row); 
656         }
657
658         if(!found) unHideMe($('myopac_bookbags_none'));
659         else unHideMe($('myopac_bookbag_table'));       
660 }
661
662 function myOPACDeleteBookbag(id) {
663         if( confirm( $('myopac_delete_bookbag_warn').innerHTML ) ) {
664                 var result = containerDelete(id);
665                 var code = checkILSEvent(result);
666                 if(code) { alertILSEvent(code); return; }
667                 hideMe($('myopac_bookbag_items_table'));
668                 hideMe($('myopac_bookbag_items_name'));
669                 hideMe($('myopac_bookbag_no_items'));
670                 myOPACShowBookbags(true);
671         }
672 }
673
674 function myOPACFetchBBItems( id, row, block ) {
675         if(!block) {
676                 containerFlesh( id, _myOPACSetBBItems, { row: row }  );
677         } else {
678                 var cont = containerFlesh(id);
679                 myOPACSetBBItems( cont, row );
680         }
681 }
682
683 function _myOPACSetBBItems(r) { myOPACSetBBItems( r.getResultObject(), r.args.row ); }
684
685 function myOPACSetBBItems( container, row ) {
686         fleshedContainers[container.id()] = container;
687         var node = $n(row, 'myopac_bookbag_item_count');
688         removeChildren(node);
689         node.appendChild( text(container.items().length) );
690 }
691
692 var BBItemsRow;
693 function myOPACExpandBookbag( id, name ) {
694         
695         var tbody = $('myopac_bookbag_items_tbody');
696         if(!BBItemsRow) BBItemsRow = tbody.removeChild($('myopac_bookbag_items_row'));
697         removeChildren(tbody);
698         removeChildren($('myopac_bookbag_items_name'));
699
700         $('myopac_bookbag_items_name').appendChild(text(name));
701
702         if( fleshedContainers[id] ) {
703                 var len = fleshedContainers[id].items().length;
704
705                 if( len == 0 ) {
706                         unHideMe($('myopac_bookbag_no_items'));
707                         hideMe($('myopac_bookbag_items_table'));
708                         return;
709                 }
710
711                 hideMe($('myopac_bookbag_no_items'));
712                 unHideMe($('myopac_bookbag_items_table'));
713
714                 for( var i = 0; i != len; i++ ) {
715                         var row = BBItemsRow.cloneNode(true);
716                         found = true;
717
718                         var item = fleshedContainers[id].items()[i];
719                         var tlink = $n(row,'myopac_bookbag_items_title');
720                         var alink = $n(row,'myopac_bookbag_items_author');
721
722                         var req = new Request( FETCH_RMODS, item.target_biblio_record_entry() );
723                         req.request.tlink = tlink;
724                         req.request.alink = alink;
725                         req.callback(myOPACShowBBItem);
726                         req.send();
727
728                         var clink = $n(row, 'myopac_bookbag_items_remove');
729                         clink.setAttribute('href', 'javascript:myOPACRemoveBBItem("'+item.id()+'","'+id+'","'+name+'");');
730
731                         tbody.appendChild(row);
732                 }
733         }
734 }
735
736 function myOPACRemoveBBItem( id, containerid, container_name ) {
737         containerRemoveItem( id );
738         myOPACFetchBBItems( containerid, $('myopac_bookbag_row_' + containerid), true);
739         myOPACExpandBookbag( containerid, container_name );
740 }
741
742 function myOPACShowBBItem(r) {
743         var record = r.getResultObject();
744         buildTitleDetailLink(record, r.tlink);
745         buildSearchLink(STYPE_AUTHOR, record.author(), r.alink);
746 }
747
748 function myOPACCreateBookbag() {
749         var name = $('myopac_bookbag_new_name').value;  
750         if(!name) return;
751         var result = containerCreate( name, $('bb_public_yes').checked );
752         var code = checkILSEvent(result);
753         if(code) { alertILSEvent(code); return; }
754         myOPACShowBookbags(true);
755 }
756
757