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