87fc3908e814415a65e2b88c3cffa8c4b769bac9
[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         if(!confirm($('myopac_renew_confirm').innerHTML)) return;
201
202         var req = new Request(RENEW_CIRC, G.user.session, 
203                 { patron : G.user.id(), copyid : circ.target_copy() } );
204         req.send(true);
205         var res = req.result();
206
207         if(evt = checkILSEvent(res)) {
208                 if( evt != 0 ) {
209                         alert(evt);
210                         alertILSEvent(evt);
211                         return;
212                 }
213         }
214
215         alert($('myopac_renew_success').innerHTML);     
216         checkedDrawn = false;
217         myOPACShowChecked();
218 }
219
220
221
222 function myOPACShowHolds() {
223         var req = new Request(FETCH_HOLDS, G.user.session, G.user.id());        
224         req.callback(myOPACDrawHolds);
225         req.send();
226 }
227
228 var holdsTemplateRowOrig;
229 var holdsTemplateRow;
230 function myOPACDrawHolds(r) {
231
232         var tbody = $("myopac_holds_tbody");
233         if(holdsTemplateRow) return;
234         if(holdsTemplateRowOrig) {
235                 holdsTemplateRow = holdsTemplateRowOrig;
236                 removeChildren(tbody);
237         } else {
238                 holdsTemplateRow = tbody.removeChild($("myopac_holds_row"));
239                 holdsTemplateRowOrig = holdsTemplateRow;
240         }
241
242         hideMe($('myopac_holds_loading'));
243
244         var holds = r.getResultObject();
245
246         if(!holds || holds.length < 1) unHideMe($('myopac_holds_none'));
247         for( var i = 0; i != holds.length; i++ ) {
248
249                 var h = holds[i];
250                 var row = holdsTemplateRow.cloneNode(true);
251                 row.id = "myopac_holds_row_" + h.id() + '_' + h.target();
252
253                 var formats = (h.holdable_formats()) ? h.holdable_formats() : null;
254                 var form = $n(row, "myopac_holds_formats");
255                 form.id = "myopac_holds_form_" + h.id() + '_' + h.target();
256                 if(formats) form.appendChild(text(formats));
257
258                 $n(row, "myopac_holds_location").
259                         appendChild(text(findOrgUnit(h.pickup_lib()).name()));
260                 $n(row, "myopac_holds_email_link").
261                         appendChild(text(h.email_notify()));
262                 $n(row, "myopac_holds_phone_link").
263                         appendChild(text(h.phone_notify()));
264                 tbody.appendChild(row);
265
266                 $n(row,'myopac_holds_cancel_link').setAttribute(
267                         'href','javascript:myOPACCancelHold("'+ h.id()+'");'); 
268                 unHideMe(row);
269
270                 myOPACDrawHoldTitle(h);
271         }
272 }
273
274 function myOPACCancelHold(holdid) {
275         if( confirm($('myopac_holds_cancel_verify').innerHTML) ) {
276                 holdsCancel(holdid);
277                 holdsTemplateRow = null
278                 myOPACShowHolds();
279         }
280 }
281
282
283
284 function myOPACDrawHoldTitle(hold) {
285         var method;
286         if(hold.hold_type() == "M") method = FETCH_MRMODS;
287         if(hold.hold_type() == "T") method = FETCH_RMODS;
288         var req = new Request(method, hold.target());
289         req.callback(myOPACFleshHoldTitle);
290         req.request.hold = hold.id();
291         req.send();
292 }
293
294 function myOPACFleshHoldTitle(r) {
295
296         var record = r.getResultObject();
297         var row = $("myopac_holds_row_" + r.hold + '_' + record.doc_id());
298         var title_link = $n(row, "myopac_holds_title_link");
299         var author_link = $n(row, "myopac_holds_author_link");
300
301         buildTitleDetailLink(record, title_link);
302         buildSearchLink(STYPE_AUTHOR, record.author(), author_link);
303
304         var form = $("myopac_holds_form_" + r.hold + '_' + record.doc_id());
305
306         if(form) {
307                 var img = elem("img");
308                 img.setAttribute("src", 
309                         buildImageLink('tor/' + record.types_of_resource()[0] + ".jpg"));
310                 addCSSClass(img, "myopac_form_pic");
311                 form.appendChild(img);
312         }
313 }
314
315 var finesShown = false;
316 function myOPACShowFines() {
317         if(finesShown) return; finesShown = true;
318         var req = new Request(FETCH_FINES_SUMMARY, G.user.session, G.user.id() );
319         req.callback(_myOPACShowFines);
320         req.send();
321 }
322
323 function _myOPACShowFines(r) {
324         hideMe($('myopac_fines_summary_loading'));
325         unHideMe($('myopac_fines_summary_row'));
326
327         var summary = r.getResultObject();
328         var total       = "0.00"; /* localization? */
329         var paid                = "0.00";
330         var balance = "0.00";
331         if( instanceOf(summary,mous) ) {
332
333                 total           = _finesFormatNumber(summary.total_owed());
334                 paid            = _finesFormatNumber(summary.total_paid());
335                 balance = _finesFormatNumber(summary.balance_owed());
336
337                 var req = new Request(FETCH_TRANSACTIONS, G.user.session, G.user.id() );
338                 req.callback(myOPACShowTransactions);
339                 req.send();
340         }
341
342         $('myopac_fines_summary_total').appendChild(text(total));
343         $('myopac_fines_summary_paid').appendChild(text(paid));
344         $('myopac_fines_summary_balance').appendChild(text(balance));
345 }
346
347 function _finesFormatNumber(num) {
348         if(isNull(num)) num = 0;
349         num = num + "";
350         if(num.length < 2 || !num.match(/\./)) num += ".00";
351         if(num.match(/\./) && num.charAt(num.length-2) == '.') num += "0";
352         return num;
353 }          
354
355 function _trimTime(time) { if(!time) return ""; return time.replace(/\ .*/,""); }
356
357 function _trimSeconds(time) { if(!time) return ""; return time.replace(/\..*/,""); }
358
359
360 function myOPACShowTransactions(r) {
361
362         if(myopacGenericTransTemplate || myopacCircTransTemplate) return;
363
364         var transactions = r.getResultObject();
365
366         for( var idx in transactions ) {
367
368                 var trans       = transactions[idx].transaction;
369                 var record      = transactions[idx].record;
370                 var circ                = transactions[idx].circ;
371
372                 if(trans.xact_type() == 'circulation') 
373                         myOPACShowCircTransaction(trans, record, circ);
374
375                 else if(trans.xact_type() == 'grocery' ) 
376                         myopacShowGenericTransaction( trans );
377         }
378 }
379
380 var myopacGenericTransTemplate;
381 function myopacShowGenericTransaction( trans ) {
382         var tbody = $('myopac_trans_tbody');
383
384         if(!myopacGenericTransTemplate) {
385                 myopacGenericTransTemplate = 
386                         tbody.removeChild($('myopac_trans_row'));
387                 removeChildren(tbody);
388         }
389
390         var row = myopacGenericTransTemplate.cloneNode(true);
391
392         $n(row,'myopac_trans_start').appendChild(
393                         text(_trimSeconds(trans.xact_start())));
394
395         $n(row,'myopac_trans_last_payment').appendChild(
396                         text(_trimSeconds(trans.last_payment_ts())));
397
398         $n(row,'myopac_trans_init_amount').appendChild(
399                         text(_finesFormatNumber(trans.total_owed())));
400
401         $n(row,'myopac_trans_total_paid').appendChild(
402                         text(_finesFormatNumber(trans.total_paid())));
403
404         $n(row,'myopac_trans_balance').appendChild(
405                         text(_finesFormatNumber(trans.balance_owed())));
406
407         var req = new Request(FETCH_MONEY_BILLING, G.user.session, trans.id());
408         req.send(true);
409         var bills = req.result();
410         if(bills && bills[0])
411                 $n(row,'myopac_trans_bill_type').appendChild(
412                                 text(bills[0].billing_type()));
413
414         tbody.appendChild(row);
415         unHideMe($('myopac_trans_table'));
416 }
417
418
419
420 /* draws a circulation transaction summary */
421 var myopacCircTransTemplate;
422 function myOPACShowCircTransaction(trans, record, circ) {
423         var tbody = $('myopac_circ_trans_tbody');
424
425         if(!myopacCircTransTemplate) {
426                 myopacCircTransTemplate = tbody.removeChild($('myopac_circ_trans_row'));
427                 removeChildren(tbody);
428         }
429
430         var row = myopacCircTransTemplate.cloneNode(true);
431
432         buildTitleDetailLink(record, $n(row,'myopac_circ_trans_title'));
433
434         $n(row,'myopac_circ_trans_author').appendChild(text(
435                 normalize(truncate(record.author(), 65))));
436
437         $n(row,'myopac_circ_trans_start').
438                 appendChild(text(_trimTime(trans.xact_start())));
439
440    var due = _trimTime(circ.due_date());
441         var checkin = _trimTime(circ.stop_fines_time());
442
443         $n(row,'myopac_circ_trans_due').appendChild(text(due))
444         $n(row,'myopac_circ_trans_finished').appendChild(text(checkin))
445
446         $n(row,'myopac_circ_trans_balance').
447                 appendChild(text(_finesFormatNumber(trans.balance_owed())));
448
449         tbody.appendChild(row);
450         unHideMe($('myopac_circ_trans_table'));
451 }
452
453
454 function myOPACSavePrefs() {
455         G.user.prefs[PREF_HITS_PER] = getSelectorVal($('prefs_hits_per'));
456         if(commitUserPrefs())
457                 alert($('prefs_update_success').innerHTML);
458         else alert($('prefs_update_failure').innerHTML);
459 }
460
461
462 function myOPACShowPrefs() {
463         grabUserPrefs();
464         myOPACShowHitsPer();
465         hideMe($('myopac_prefs_loading'));
466         unHideMe($('myopac_prefs_row'));
467 }
468
469 function myOPACShowHitsPer() {
470         var hits = 10;
471         if(G.user.prefs[PREF_HITS_PER])
472                 hits = G.user.prefs[PREF_HITS_PER];
473         var hitsSel = $('prefs_hits_per');
474         setSelector(hitsSel, hits);
475 }
476
477 var userShown = false;
478 function myOPACShowSummary() {
479         if(userShown) return; userShown = true;
480         var req = new Request(FETCH_FLESHED_USER,G.user.session, G.user.id());
481         req.callback(_myOPACSummaryShowUer);
482         req.send();
483 }
484
485 var addrRowTemplate;
486 function _myOPACSummaryShowUer(r) {
487
488         var user = r.getResultObject();
489         fleshedUser = user;
490         if(!user) return;
491
492         appendClear($('myopac_summary_first'),text(user.first_given_name()));
493         appendClear($('myopac_summary_middle'),text(user.second_given_name()));
494         appendClear($('myopac_summary_dayphone'),text(user.day_phone()));
495         appendClear($('myopac_summary_eveningphone'),text(user.evening_phone()));
496         appendClear($('myopac_summary_otherphone'),text(user.other_phone()));
497         appendClear($('myopac_summary_last'),text(user.family_name()));
498         appendClear($('myopac_summary_username'),text(user.usrname()));
499         appendClear($('myopac_summary_email'),text(user.email()));
500         appendClear($('myopac_summary_barcode'),text(user.card().barcode()));
501         appendClear($('myopac_summary_ident1'),text(user.ident_value()));
502         appendClear($('myopac_summary_ident2'),text(user.ident_value2()));
503         appendClear($('myopac_summary_homelib'),text(findOrgUnit(user.home_ou()).name()));
504         appendClear($('myopac_summary_create_date'),text(user.create_date()));
505
506         var tbody = $('myopac_addr_tbody');
507         var template;
508
509         if(addrRowTemplate) { 
510                 template = addrRowTemplate;
511         } else {
512                 template = tbody.removeChild($('myopac_addr_row'));
513                 addrRowTemplate = template;
514         }
515         removeChildren(tbody);
516
517         for( var a in user.addresses() ) {
518                 var row = template.cloneNode(true);
519                 myOPACDrawAddr(row, user.addresses()[a]);
520                 tbody.appendChild(row);
521         }
522 }
523
524 function myOPACDrawAddr(row, addr) {
525
526         appendClear($n(row, 'myopac_addr_type'),text(addr.address_type()));
527         var street = (addr.street2()) ? addr.street1() + ", " + addr.street2() : addr.street1();
528         appendClear($n(row, 'myopac_addr_street'),text(street));
529         appendClear($n(row, 'myopac_addr_city'),text(addr.city()));
530         appendClear($n(row, 'myopac_addr_county'),text(addr.county()));
531         appendClear($n(row, 'myopac_addr_state'),text(addr.state()));
532         appendClear($n(row, 'myopac_addr_zip'),text(addr.post_code()));
533 }
534
535
536 function myOPACUpdateUsername() {
537         var username = $('myopac_new_username').value;
538         if(username == null || username == "") {
539                 alert($('myopac_username_error').innerHTML);
540                 return;
541         }
542         var req = new Request(UPDATE_USERNAME, G.user.session, username );
543         req.send(true);
544         if(req.result()) {
545
546                 var evt;
547                 if(evt = checkILSEvent(req.result())) {
548                         alertILSEvent(evt);
549                         return;
550                 }
551
552                 G.user.usrname(username);
553                 hideMe($('myopac_update_username_row'));
554                 userShown = false;
555                 myOPACShowSummary();
556                 return;
557         }
558
559         alert($('myopac_username_failure').innerHTML);
560 }
561
562 function myOPACUpdateEmail() {
563         var email = $('myopac_new_email').value;
564         if(email == null || email == "") {
565                 alert($('myopac_email_error').innerHTML);
566                 return;
567         }
568
569         var req = new Request(UPDATE_EMAIL, G.user.session, email );
570         req.send(true);
571         if(req.result()) {
572                 G.user.usrname(email);
573                 hideMe($('myopac_update_email_row'));
574                 userShown = false;
575                 myOPACShowSummary();
576                 return;
577         }
578
579         alert($('myopac_email_failure').innerHTML);
580 }
581
582
583 function myOPACUpdatePassword() {
584         var curpassword = $('myopac_current_password').value;
585         var password = $('myopac_new_password').value;
586         var password2 = $('myopac_new_password2').value;
587
588         if(     curpassword == null || curpassword == "" || 
589                         password == null || password == "" || 
590                         password2 == null || password2 == "" || password != password2 ) {
591                 alert($('myopac_password_error').innerHTML);
592                 return;
593         }
594
595         var req = new Request(UPDATE_PASSWORD, G.user.session, password, curpassword );
596         req.send(true);
597         if(req.result()) {
598                 G.user.usrname(password);
599                 hideMe($('myopac_update_password_row'));
600                 userShown = false;
601                 myOPACShowSummary();
602                 return;
603         }
604
605         alert($('myopac_password_failure').innerHTML);
606 }
607
608
609
610
611 var containerTemplate;
612 function myOPACShowBookbags(force) {
613
614         var tbody =$('myopac_bookbag_tbody') ;
615
616         if(!containerTemplate) 
617                 containerTemplate = tbody.removeChild($('myopac_bookbag_tr'));
618         else if(!force) return;
619
620         removeChildren(tbody);
621
622         var containers = containerFetchAll();
623
624         var found = false;
625         for( var i in containers ) {
626                 found = true;
627                 var cont = containers[i];
628                 var row = containerTemplate.cloneNode(true);
629                 row.id = 'myopac_bookbag_row_' + cont.id();
630                 var link = $n(row, 'myopac_expand_bookbag');
631                 var dlink = $n(row, 'myopac_container_delete');
632                 link.appendChild( text(cont.name()) );
633                 link.setAttribute('href', 
634                         'javascript:myOPACExpandBookbag("' + cont.id() + '","' + cont.name() + '");');
635                 myOPACFetchBBItems( cont.id(), row );
636                 dlink.setAttribute('href', 'javascript:myOPACDeleteBookbag("'+cont.id()+'");');
637
638                 if( cont.pub() ) {
639                         unHideMe($n(row, 'myopac_bb_published_yes'));
640                         var link = $n(row, 'myopac_bb_published_view');
641                         link.setAttribute('href', buildExtrasLink( 'bbags.xml?bb='+cont.id(), false));  
642                         link.setAttribute('target', '_blank' );
643                         unHideMe(link);
644
645                 } else { 
646                         unHideMe($n(row, 'myopac_bb_published_no')); 
647                 }
648
649                 tbody.appendChild(row); 
650         }
651
652         if(!found) unHideMe($('myopac_bookbags_none'));
653         else unHideMe($('myopac_bookbag_table'));       
654 }
655
656 function myOPACDeleteBookbag(id) {
657         if( confirm( $('myopac_delete_bookbag_warn').innerHTML ) ) {
658                 var result = containerDelete(id);
659                 var code = checkILSEvent(result);
660                 if(code) { alertILSEvent(code); return; }
661                 hideMe($('myopac_bookbag_items_table'));
662                 hideMe($('myopac_bookbag_items_name'));
663                 hideMe($('myopac_bookbag_no_items'));
664                 myOPACShowBookbags(true);
665         }
666 }
667
668 function myOPACFetchBBItems( id, row, block ) {
669         if(!block) {
670                 containerFlesh( id, _myOPACSetBBItems, { row: row }  );
671         } else {
672                 var cont = containerFlesh(id);
673                 myOPACSetBBItems( cont, row );
674         }
675 }
676
677 function _myOPACSetBBItems(r) { myOPACSetBBItems( r.getResultObject(), r.args.row ); }
678
679 function myOPACSetBBItems( container, row ) {
680         fleshedContainers[container.id()] = container;
681         var node = $n(row, 'myopac_bookbag_item_count');
682         removeChildren(node);
683         node.appendChild( text(container.items().length) );
684 }
685
686 var BBItemsRow;
687 function myOPACExpandBookbag( id, name ) {
688         
689         var tbody = $('myopac_bookbag_items_tbody');
690         if(!BBItemsRow) BBItemsRow = tbody.removeChild($('myopac_bookbag_items_row'));
691         removeChildren(tbody);
692         removeChildren($('myopac_bookbag_items_name'));
693
694         $('myopac_bookbag_items_name').appendChild(text(name));
695
696         if( fleshedContainers[id] ) {
697                 var len = fleshedContainers[id].items().length;
698
699                 if( len == 0 ) {
700                         unHideMe($('myopac_bookbag_no_items'));
701                         hideMe($('myopac_bookbag_items_table'));
702                         return;
703                 }
704
705                 hideMe($('myopac_bookbag_no_items'));
706                 unHideMe($('myopac_bookbag_items_table'));
707
708                 for( var i = 0; i != len; i++ ) {
709                         var row = BBItemsRow.cloneNode(true);
710                         found = true;
711
712                         var item = fleshedContainers[id].items()[i];
713                         var tlink = $n(row,'myopac_bookbag_items_title');
714                         var alink = $n(row,'myopac_bookbag_items_author');
715
716                         var req = new Request( FETCH_RMODS, item.target_biblio_record_entry() );
717                         req.request.tlink = tlink;
718                         req.request.alink = alink;
719                         req.callback(myOPACShowBBItem);
720                         req.send();
721
722                         var clink = $n(row, 'myopac_bookbag_items_remove');
723                         clink.setAttribute('href', 'javascript:myOPACRemoveBBItem("'+item.id()+'","'+id+'","'+name+'");');
724
725                         tbody.appendChild(row);
726                 }
727         }
728 }
729
730 function myOPACRemoveBBItem( id, containerid, container_name ) {
731         if(!confirm($('myopac_remove_bb_item_confirm').innerHTML)) return;
732         containerRemoveItem( id );
733         myOPACFetchBBItems( containerid, $('myopac_bookbag_row_' + containerid), true);
734         myOPACExpandBookbag( containerid, container_name );
735 }
736
737 function myOPACShowBBItem(r) {
738         var record = r.getResultObject();
739         buildTitleDetailLink(record, r.tlink);
740         buildSearchLink(STYPE_AUTHOR, record.author(), r.alink);
741 }
742
743 function myOPACCreateBookbag() {
744         var name = $('myopac_bookbag_new_name').value;  
745         if(!name) return;
746         var result = containerCreate( name, $('bb_public_yes').checked );
747         var code = checkILSEvent(result);
748         if(code) { alertILSEvent(code); return; }
749         myOPACShowBookbags(true);
750 }
751
752