3 MyOPACSPage.prototype = new Page();
4 MyOPACSPage.prototype.constructor = Page;
5 MyOPACSPage.baseClass = Page.constructor;
7 var globalmyopac = null;
10 function MyOPACSPage() {
11 var session_id = location.search.substring(
12 location.search.indexOf("session") + 8 ); /*md5 session key*/
14 this.user = UserSession.instance();
15 this.user.verifySession(session_id);
19 MyOPACSPage.prototype.init = function() {
23 MyOPACSPage.prototype.draw = function(type) {
25 debug("Fleshing User");
27 this.infoPane = getById("my_opac_info_pane");
28 this.infoTable = getById("my_opac_info_table");
30 removeChildren(this.infoPane);
31 removeChildren(this.infoTable);
32 this.infoPane.appendChild(this.infoTable);
36 this.buildNavBox(true);
38 this.checkCell = getById("my_opac_checked");
39 this.holdsCell = getById("my_opac_holds");
40 this.profileCell = getById("my_opac_profile");
41 this.finesCell = getById("my_opac_fines");
43 check = getById("my_opac_checked_link");
44 holds = getById("my_opac_holds_link");
45 profile = getById("my_opac_profile_link");
46 fines = getById("my_opac_fines_link");
49 check.onclick = function() { obj.drawCheckedOut(); };
50 holds.onclick = function() { obj.drawHolds(); };
51 profile.onclick = function() { obj.drawProfile(); };
52 fines.onclick = function() { obj.drawFines(); };
55 case "holds": this.drawHolds(); break;
56 case "profile": this.drawProfile(); break;
57 case "fines": this.drawFines(); break;
59 default:this.drawCheckedOut();
64 MyOPACSPage.prototype.setLink = function(cell) {
65 remove_css_class(this.checkCell, "my_opac_link_cell_active");
66 remove_css_class(this.holdsCell, "my_opac_link_cell_active");
67 remove_css_class(this.profileCell, "my_opac_link_cell_active");
68 remove_css_class(this.finesCell, "my_opac_link_cell_active");
69 add_css_class(cell, "my_opac_link_cell_active");
72 MyOPACSPage.prototype.drawCheckedOut = function() {
73 removeChildren(this.infoTable);
74 removeChildren(this.infoPane);
75 this.infoPane.appendChild(this.infoTable);
76 this.setLink(this.checkCell);
77 this.getCheckedOut(_drawCheckedOut);
80 MyOPACSPage.prototype.drawHolds = function() {
81 removeChildren(this.infoTable);
82 removeChildren(this.infoPane);
83 this.infoPane.appendChild(this.infoTable);
84 this.setLink(this.holdsCell);
88 MyOPACSPage.prototype.drawProfile = function() {
89 removeChildren(this.infoTable);
90 removeChildren(this.infoPane);
91 this.infoPane.appendChild(this.infoTable);
92 this.setLink(this.profileCell);
96 MyOPACSPage.prototype.drawFines = function() {
97 removeChildren(this.infoTable);
98 removeChildren(this.infoPane);
99 this.infoPane.appendChild(this.infoTable);
100 this.setLink(this.finesCell);
103 function _drawCheckedOut(obj, data) {
105 if(data == null) return;
106 //obj.infoPane.appendChild(obj.infoTable);
107 var circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
109 var tcell = circRow.insertCell(circRow.cells.length)
110 tcell.appendChild(mktext("Title"));
111 var dcell = circRow.insertCell(circRow.cells.length);
112 dcell.appendChild(mktext("Due Date"));
113 var drcell = circRow.insertCell(circRow.cells.length);
114 drcell.appendChild(mktext("Duration"));
115 var bcell = circRow.insertCell(circRow.cells.length);
116 bcell.appendChild(mktext("Barcode"));
117 var ccell = circRow.insertCell(circRow.cells.length);
118 ccell.appendChild(mktext("Circulating Library"));
119 var rcell = circRow.insertCell(circRow.cells.length);
120 rcell.appendChild(mktext("Renewals Remaining"));
121 var rbcell = circRow.insertCell(circRow.cells.length);
122 rbcell.appendChild(mktext("Renew?"));
124 add_css_class(tcell, "my_opac_info_table_header");
125 add_css_class(dcell, "my_opac_info_table_header");
126 add_css_class(drcell, "my_opac_info_table_header");
127 add_css_class(bcell, "my_opac_info_table_header");
128 add_css_class(ccell, "my_opac_info_table_header");
129 add_css_class(rcell, "my_opac_info_table_header");
130 add_css_class(rbcell, "my_opac_info_table_header");
133 if(data.length < 1) {
134 debug("No circs exist for this user");
135 circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
136 circRow.insertCell(0).appendChild(
137 mktext("No items currently checked out"));
141 for( var index in data ) {
143 var circ = data[index].circ;
144 var record = data[index].record;
145 var copy = data[index].copy;
146 circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
149 var due = circ.due_date();
150 //due = due.substring(0,10) + "T" + due.substring(12,due.length);
151 due = due.replace(/[0-9][0-9]:.*$/,"");
154 var year = parseInt(due.substring(0,4)) - 1900;
155 var month = parseInt(due.substring(5,7)) - 1;
156 var day = parseInt(due.substring(8,10));
158 //alert(parseInt(due.substring(0,4)) + " " + parseInt(due.substring(5,7)) + " " + parseInt(due.substring(8,10)));
160 //alert(year + " " + month + " " + day);
162 var date = new Date(year, month, day, 0, 0, 0);
163 due = date.toString();
164 //due = due.replace(/[0-9][0-9]:.*$/,"");
175 alert(circ.due_date());
176 alert(new Date(circ.due_date()));
179 var title_href = createAppElement("a");
180 title_href.setAttribute("href","?sub_frame=1&target=record_detail&record=" + record.doc_id() );
181 title_href.setAttribute("target","_top"); /* escape to the outermost frame */
182 title_href.appendChild(mktext(record.title()));
185 var renewbox = elem("input",
186 {type:"checkbox", id:"renew_checkbox_" + record.doc_id()});
189 var renewboxlink = mktext("N/A");
190 if(parseInt(circ.renewal_remaining()) > 0)
191 renewboxlink = buildRenewBoxLink(circ);
193 /* grab circ lib name */
194 var org = obj._getOrgUnit(copy.circ_lib());
197 /* for each circulation, build a row of data */
198 var titleCell = circRow.insertCell(circRow.cells.length);
199 var dueCell = circRow.insertCell(circRow.cells.length);
200 var durationCell = circRow.insertCell(circRow.cells.length);
201 var barcodeCell = circRow.insertCell(circRow.cells.length);
202 var circLibCell = circRow.insertCell(circRow.cells.length);
203 var renewRemainCell = circRow.insertCell(circRow.cells.length);
204 var renewCell = circRow.insertCell(circRow.cells.length);
206 add_css_class(titleCell, "my_opac_profile_cell");
207 add_css_class(dueCell, "my_opac_profile_cell");
208 add_css_class(durationCell, "my_opac_profile_cell");
209 add_css_class(barcodeCell, "my_opac_profile_cell");
210 add_css_class(circLibCell, "my_opac_profile_cell");
211 add_css_class(renewRemainCell, "my_opac_profile_cell");
212 add_css_class(renewCell, "my_opac_profile_cell");
214 titleCell.appendChild(title_href);
215 dueCell.appendChild(mktext(due));
216 durationCell.appendChild(mktext(circ.duration()));
217 barcodeCell.appendChild(mktext(copy.barcode()));
218 circLibCell.appendChild(mktext(org));
219 renewRemainCell.appendChild(mktext(circ.renewal_remaining()));
220 renewCell.appendChild(renewboxlink);
226 function buildRenewBoxLink(circ) {
229 {href:"javascript:void(0);",style:"text-decoration:underline"}, null, "Renew");
230 var but = elem("input",{type:"submit",value:"Renew Circulation"});
231 var can = elem("input",{type:"submit",value:"Cancel"});
233 var box = new PopupBox(a);
234 a.onclick = function(){box.show();}
235 can.onclick = function(){box.hide();}
236 but.onclick = function(){renewCheckout(circ);box.hide();};
237 box.title("Renew Circulation");
238 box.addText("Are you sure you want to renew the circulation?");
239 box.makeGroup([but, can]);
243 function renewCheckout(circ) {
244 var req = new RemoteRequest(
245 "open-ils.circ", "open-ils.circ.renew",
246 globalmyopac.user.session_id, circ );
249 try{var ret = req.getResultObject();}catch(E){return;}
251 //alert(js2JSON(ret));
252 alert("Renewal completed successfully");
253 globalmyopac.draw("checked");
257 MyOPACSPage.prototype.getCheckedOut = function(callback) {
259 /* grab our circs and records */
260 var request = new RemoteRequest(
262 "open-ils.circ.actor.user.checked_out",
263 this.user.getSessionId() );
266 request.setCompleteCallback(
269 callback(obj, req.getResultObject());
277 MyOPACSPage.prototype._drawProfile = function() {
279 this.user.fleshMe(true);
280 var infot = elem("table");
281 this.infoTable.insertRow(0).insertCell(0).appendChild(infot);
282 this.infoTable.insertRow(1).insertCell(0).appendChild(
283 elem("div",{id:"my_opac_update_info"}));
285 var urow = infot.insertRow(infot.rows.length);
286 var prow = infot.insertRow(infot.rows.length);
287 var erow = infot.insertRow(infot.rows.length);
288 var brow = infot.insertRow(infot.rows.length);
289 var arow = infot.insertRow(infot.rows.length);
290 var a2row = infot.insertRow(infot.rows.length);
292 var ucell = urow.insertCell(urow.cells.length);
293 var ucell2 = urow.insertCell(urow.cells.length);
294 var ucell3 = urow.insertCell(urow.cells.length);
296 var pcell = prow.insertCell(prow.cells.length);
297 var pcell2 = prow.insertCell(prow.cells.length);
298 var pcell3 = prow.insertCell(prow.cells.length);
300 var ecell = erow.insertCell(erow.cells.length);
301 var ecell2 = erow.insertCell(erow.cells.length);
302 var ecell3 = erow.insertCell(erow.cells.length);
304 var bcell = brow.insertCell(brow.cells.length);
305 var bcell2 = brow.insertCell(brow.cells.length);
306 var bcell3 = brow.insertCell(brow.cells.length);
308 add_css_class(ucell, "my_opac_info_table_header");
309 add_css_class(pcell, "my_opac_info_table_header");
310 add_css_class(ecell, "my_opac_info_table_header");
311 add_css_class(bcell, "my_opac_info_table_header");
313 add_css_class(ucell2, "my_opac_profile_cell");
314 add_css_class(pcell2, "my_opac_profile_cell");
315 add_css_class(ecell2, "my_opac_profile_cell");
316 add_css_class(bcell2, "my_opac_profile_cell");
318 add_css_class(ucell3, "my_opac_profile_cell");
319 add_css_class(pcell3, "my_opac_profile_cell");
320 add_css_class(ecell3, "my_opac_profile_cell");
321 add_css_class(bcell3, "my_opac_profile_cell");
323 var ubold = elem("b");
324 var pbold = elem("b");
325 var ebold = elem("b");
326 var bbold = elem("b");
327 var abold = elem("b");
329 var uclick = elem("a",
330 {id:"uname_link",href:"javascript:void(0);",
331 style:"text-decoration:underline;"}, null, "Change");
333 var pclick = elem("a",
334 {id:"passwd_link",href:"javascript:void(0);",
335 style:"text-decoration:underline;"}, null, "Change");
337 var eclick = elem("a",
338 {id:"email_link",href:"javascript:void(0);",
339 style:"text-decoration:underline;"}, null, "Change");
342 uclick.onclick = function() { obj.updateUsername(); }
343 pclick.onclick = function() { obj.updatePassword(); }
344 eclick.onclick = function() { obj.updateEmail(); }
346 ucell.appendChild(mktext("Username"));
347 ubold.appendChild(mktext(this.user.userObject.usrname()));
348 ucell2.appendChild(ubold);
349 ucell3.appendChild(uclick);
351 pcell.appendChild(mktext("Password"));
352 pbold.appendChild(mktext("N/A"));
353 pcell2.appendChild(pbold);
354 pcell3.appendChild(pclick);
356 ecell.appendChild(mktext("Email Address"));
357 ebold.appendChild(mktext(this.user.userObject.email()));
358 ecell2.appendChild(ebold);
359 ecell3.appendChild(eclick);
361 bcell.appendChild(mktext("Active Barcode"));
362 bbold.appendChild(mktext(this.user.userObject.card().barcode()));
363 bcell2.appendChild(bbold);
364 bcell3.appendChild(mktext(" "));
367 var addrTable = elem("table");
368 add_css_class(addrTable, "my_opac_addr_table");
370 var row = addrTable.insertRow(0);
371 var mailing = row.insertCell(0);
372 var space = row.insertCell(1);
373 var billing = row.insertCell(2);
377 space.setAttribute("style","width: 30px");
378 space.appendChild(mktext(" "));
380 appendChild(this.mkAddrTable(addrTable, this.userObject.addresses()[a]));
382 var addr = this.user.userObject.mailing_address();
383 mailing.appendChild(this.mkAddrTable("Mailing Address", addr));
385 addr = this.user.userObject.billing_address();
386 billing.appendChild(this.mkAddrTable("Billing Address", addr));
388 this.infoPane.appendChild(elem("br"));
392 this.infoPane.appendChild(elem("hr"));
393 this.infoPane.appendChild(elem("br"));
394 this.infoPane.appendChild(this.mkAddrTable(this.user.userObject.addresses()));
399 MyOPACSPage.prototype.mkAddrTable = function(addresses) {
401 var table = elem("table");
402 add_css_class(table, "my_opac_addr_table");
404 var row = table.insertRow(table.rows.length);
405 var cell = row.insertCell(row.cells.length);
406 add_css_class(cell, "my_opac_info_table_header");
407 cell.appendChild(mktext("Address Type"));
409 cell = row.insertCell(row.cells.length);
410 add_css_class(cell, "my_opac_info_table_header");
411 cell.appendChild(mktext("Street"));
413 cell = row.insertCell(row.cells.length);
414 add_css_class(cell, "my_opac_info_table_header");
415 cell.appendChild(mktext("City"));
417 cell = row.insertCell(row.cells.length);
418 add_css_class(cell, "my_opac_info_table_header");
419 cell.appendChild(mktext("County"));
421 cell = row.insertCell(row.cells.length);
422 add_css_class(cell, "my_opac_info_table_header");
423 cell.appendChild(mktext("State"));
425 cell = row.insertCell(row.cells.length);
426 add_css_class(cell, "my_opac_info_table_header");
427 cell.appendChild(mktext("Zip Code"));
429 cell = row.insertCell(row.cells.length);
430 add_css_class(cell, "my_opac_info_table_header");
431 cell.appendChild(mktext("Valid"));
433 for( var a in addresses ) {
434 var addr = addresses[a];
435 var row = table.insertRow(table.rows.length);
436 var cell = row.insertCell(row.cells.length);
437 add_css_class(cell, "my_opac_profile_cell");
438 cell.appendChild(mktext(addr.address_type()));
440 cell = row.insertCell(row.cells.length);
441 add_css_class(cell, "my_opac_profile_cell");
442 var st = addr.street1();
443 if(addr.street2()) st += ", " + addr.street2();
444 cell.appendChild(mktext(st));
446 cell = row.insertCell(row.cells.length);
447 add_css_class(cell, "my_opac_profile_cell");
448 cell.appendChild(mktext(addr.city()));
450 cell = row.insertCell(row.cells.length);
451 add_css_class(cell, "my_opac_profile_cell");
452 cell.appendChild(mktext(addr.county()));
454 cell = row.insertCell(row.cells.length);
455 add_css_class(cell, "my_opac_profile_cell");
456 cell.appendChild(mktext(addr.state()));
458 cell = row.insertCell(row.cells.length);
459 add_css_class(cell, "my_opac_profile_cell");
460 cell.appendChild(mktext(addr.post_code()));
463 if(addr.valid() != "1") v = "No";
464 cell = row.insertCell(row.cells.length);
465 add_css_class(cell, "my_opac_profile_cell");
466 cell.appendChild(mktext(v));
476 MyOPACSPage.prototype.__mkAddrTable = function(type, addr) {
477 var table = elem("table");
479 var header_row = table.insertRow(table.rows.length);
480 var header_cell = header_row.insertCell(0);
481 add_css_class(header_cell,"my_opac_info_table_header");
482 header_cell.id = "header_cell";
483 header_cell.colSpan = 2;
484 header_cell.setAttribute("colspan", "2");
485 header_cell.appendChild(mktext(type));
487 var s1row = table.insertRow(table.rows.length);
488 var s2row = table.insertRow(table.rows.length);
489 var cityrow = table.insertRow(table.rows.length);
490 var ziprow = table.insertRow(table.rows.length);
491 var staterow = table.insertRow(table.rows.length);
493 var s1cell = s1row.insertCell(0);
494 var s2cell = s2row.insertCell(0);
495 var citycell = cityrow.insertCell(0);
496 var zipcell = ziprow.insertCell(0);
497 var statecell = staterow.insertCell(0);
499 add_css_class(s1cell, "my_opac_info_table_header");
500 add_css_class(s2cell, "my_opac_info_table_header");
501 add_css_class(citycell, "my_opac_info_table_header");
502 add_css_class(zipcell, "my_opac_info_table_header");
503 add_css_class(statecell, "my_opac_info_table_header");
505 s1cell.appendChild(mktext("Address 1"));
506 s2cell.appendChild(mktext("Address 2"));
507 citycell.appendChild(mktext("City"));
508 zipcell.appendChild(mktext("Zip"));
509 statecell.appendChild(mktext("State"));
512 s1cell = s1row.insertCell(1);
513 s2cell = s2row.insertCell(1);
514 citycell = cityrow.insertCell(1);
515 zipcell = ziprow.insertCell(1);
516 statecell = staterow.insertCell(1);
518 add_css_class(s1cell, "my_opac_profile_cell");
519 add_css_class(s2cell, "my_opac_profile_cell");
520 add_css_class(citycell, "my_opac_profile_cell");
521 add_css_class(zipcell, "my_opac_profile_cell");
522 add_css_class(statecell, "my_opac_profile_cell");
525 s1cell.appendChild(mktext(addr.street1()));
526 s2cell.appendChild(mktext(addr.street2()));
527 citycell.appendChild(mktext(addr.city()));
528 zipcell.appendChild(mktext(addr.post_code()));
529 statecell.appendChild(mktext(addr.state()));
535 MyOPACSPage.prototype.updateUsername = function() {
536 var div = getById("my_opac_update_info");
538 /* user clicks to close */
539 if(getById("my_opac_update_usrname")) {
546 var ut = elem("input",{type:"text",id:"new_uname"});
547 var but = elem("input",{type:"submit",value:"Update"});
548 var table = elem("table");
549 table.id = "my_opac_update_usrname";
550 var row = table.insertRow(0);
553 add_css_class(table,"my_opac_update_table");
555 var c0 = row.insertCell(0);
556 var c1 = row.insertCell(1);
557 var c2 = row.insertCell(2);
559 c0.appendChild(mktext("Enter new username: " ));
563 div.appendChild(elem("br"));
564 div.appendChild(table);
566 try{ut.focus();}catch(E){}
568 /* verify looks ok, send the update request */
570 but.onclick = function() {
571 var uname = getById("new_uname").value;
572 if(uname == null || uname == "") {
573 alert("Please enter a username");
576 var resp = obj.user.updateUsername(uname);
577 if(resp) alert("Username updated successfully");
578 else{ alert("Username update failed"); return; }
584 MyOPACSPage.prototype.updatePassword = function() {
585 var div = getById("my_opac_update_info");
587 /* user clicks to close */
588 if(getById("my_opac_update_password")) {
594 var ut = elem("input",{type:"password",size:"15",id:"old_password"});
595 var ut2 = elem("input",{type:"password",size:"15",id:"new_password_1"});
596 var ut3 = elem("input",{type:"password",size:"15",id:"new_password_2"});
597 var but = elem("input",{type:"submit",value:"Update"});
599 var table = elem("table");
600 table.id = "my_opac_update_password";
601 add_css_class(table,"my_opac_update_table");
603 var row = table.insertRow(0);
605 var c0 = row.insertCell(0);
606 var c1 = row.insertCell(1);
607 var c2 = row.insertCell(2);
608 var c3 = row.insertCell(3);
609 var c4 = row.insertCell(4);
610 var c5 = row.insertCell(5);
611 var c6 = row.insertCell(6);
613 c0.appendChild(mktext("Current password: " ));
616 c2.appendChild(mktext("New password: " ));
619 c4.appendChild(mktext("Repeat new password: " ));
623 div.appendChild(elem("br"));
624 div.appendChild(table);
627 try{ut.focus();}catch(E){}
629 /* verify looks ok, send the update request */
631 but.onclick = function() {
633 var old = getById("old_password").value;
634 var p1 = getById("new_password_1").value;
635 var p2 = getById("new_password_2").value;
637 if(!old || !p1 || !p2) {
638 alert("Please fill in all fields");
643 alert("New passwords do not match");
647 var resp = obj.user.updatePassword(old, p1);
648 if(resp) alert("Password updated successfully");
649 else {alert("Password change failed"); return; }
656 MyOPACSPage.prototype.updateEmail = function(){
657 var div = getById("my_opac_update_info");
659 /* user clicks to close */
660 if(getById("my_opac_update_usrname")) {
667 var ut = elem("input",{type:"text",id:"new_email"});
668 var but = elem("input",{type:"submit",value:"Update"});
669 var table = elem("table");
670 table.id = "my_opac_update_usrname";
671 var row = table.insertRow(0);
673 add_css_class(table,"my_opac_update_table");
675 var c0 = row.insertCell(0);
676 var c1 = row.insertCell(1);
677 var c2 = row.insertCell(2);
679 c0.appendChild(mktext("Enter new email address: " ));
683 div.appendChild(elem("br"));
684 div.appendChild(table);
686 try{ut.focus();}catch(E){}
688 /* verify looks ok, send the update request */
690 but.onclick = function() {
691 var uname = getById("new_email").value;
692 if(uname == null || uname == "") {
693 alert("Please enter a valid email address");
696 var resp = obj.user.updateEmail(uname);
697 if(resp) alert("Email updated successfully");
698 else{ alert("Email update failed"); return; }
705 MyOPACSPage.prototype._drawHolds = function() {
707 var table = this.infoTable;
708 var row = table.insertRow(table.rows.length);
710 var cell = row.insertCell(row.cells.length);
711 add_css_class(cell, "my_opac_info_table_header");
712 cell.appendChild(mktext("Title"));
714 cell = row.insertCell(row.cells.length);
715 add_css_class(cell, "my_opac_info_table_header");
716 cell.appendChild(mktext("Author"));
718 cell = row.insertCell(row.cells.length);
719 add_css_class(cell, "my_opac_info_table_header");
720 cell.appendChild(mktext("Format(s)"));
722 cell = row.insertCell(row.cells.length);
723 add_css_class(cell, "my_opac_info_table_header");
724 cell.appendChild(mktext("Pickup Location"));
726 cell = row.insertCell(row.cells.length);
727 add_css_class(cell, "my_opac_info_table_header");
728 cell.appendChild(mktext("Notify Email / Phone"));
730 cell = row.insertCell(row.cells.length);
731 add_css_class(cell, "my_opac_info_table_header");
732 cell.appendChild(mktext("Cancel"));
734 /* ---------------------------------------- */
735 row = table.insertRow(table.rows.length);
736 cell = row.insertCell(row.cells.length);
737 cell.appendChild(mktext("Retrieving holds..."));
738 /* ---------------------------------------- */
740 var holds = this.grabHolds();
741 table.firstChild.removeChild(table.firstChild.childNodes[1]);
743 for( var idx = 0; idx != holds.length; idx++ ) {
744 debug("Displaying hold " + holds[idx].id());
745 _doCallbackDance(table, holds[idx], this.user.session_id, this);
750 function _doCallbackDance(table, hold, session_id, obj) {
751 if(hold == null) return;
752 debug("Setting holds callback with hold " + hold.id() );
753 var func = function(rec) {_drawHoldsRow(table, hold, rec, session_id, obj)};
755 /* grab the record that is held */
756 if(hold.hold_type() == "M")
757 fetchMetaRecord(hold.target(), func);
759 if(hold.hold_type() == "T")
760 fetchRecord(hold.target(), func);
764 function _drawHoldsRow(table, hold, record, session_id, obj) {
766 if(record == null || record.length == 0) return;
767 debug("In holds callback with hold " + hold );
769 var row = table.insertRow(table.rows.length);
770 var cell = row.insertCell(row.cells.length);
772 add_css_class(cell, "my_opac_profile_cell");
773 cell.style.width = "35%";
775 var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
777 {href:prefix + "?sub_frame=1&target=record_detail&record="+encodeURIComponent(record.doc_id())},
778 null, record.title());
779 tl.setAttribute("target","_top");
780 //cell.appendChild(mktext(record.title()));
781 cell.appendChild(tl);
783 cell = row.insertCell(row.cells.length);
785 {href:prefix + "?sub_frame=1&target=mr_result"+
786 "&mr_search_query="+encodeURIComponent(record.author())+
787 "&mr_search_type=author"},
788 null, record.author());
789 al.setAttribute("target","_top");
790 add_css_class(cell, "my_opac_profile_cell");
792 //cell.appendChild(mktext(record.author()));
793 cell.appendChild(al);
795 cell = row.insertCell(row.cells.length);
796 add_css_class(cell, "my_opac_profile_cell");
798 var formats = hold.holdable_formats();
799 if(formats == null || formats == "") /* only metarecord holds have holdable_formats */
800 formats = modsFormatToMARC(record.types_of_resource()[0]);
802 cell.appendChild(_mkFormatList(formats));
803 cell.noWrap = "nowrap";
804 cell.setAttribute("nowrap", "nowrap");
806 cell = row.insertCell(row.cells.length);
807 add_css_class(cell, "my_opac_profile_cell");
808 cell.appendChild(mktext(findOrgUnit(hold.pickup_lib()).name()));
810 cell = row.insertCell(row.cells.length);
811 add_css_class(cell, "my_opac_profile_cell");
812 cell.appendChild(_buildChangeEmailNotify(hold));
813 cell.appendChild(elem("br"));
814 cell.appendChild(_buildChangePhoneNotify(hold));
816 cell = row.insertCell(row.cells.length);
817 var a = elem("a",{href:"javascript:void(0);",
818 style:"text-decoration:underline"},null, "Cancel");
819 a.onclick = function(){_cancelHoldRequest(hold, a, session_id, obj);};
820 add_css_class(cell, "my_opac_profile_cell");
825 function _cancelHoldRequest(hold, node, session_id, obj) {
826 var box = new PopupBox(node);
827 box.title("Cancel Hold");
828 box.addText("Are you sure you wish to cancel the hold?");
829 var but = elem("input",{type:"submit",value:"Cancel Hold"});
830 var can = elem("input",{type:"submit",value:"Do not Cancel Hold"});
831 box.makeGroup([but, can]);
832 but.onclick = function(){
833 _cancelHold(hold, session_id); box.hide(); obj.draw("holds");};
834 can.onclick = function() { box.hide(); };
838 function _cancelHold(hold, session_id) {
839 var req = new RemoteRequest(
840 "open-ils.circ", "open-ils.circ.hold.cancel",
844 if(req.getResultObject())
845 alert("Hold successfully cancelled");
850 function _buildChangeEmailNotify(hold) {
851 var em = hold.email_notify();
852 if(!em || em == "") em = "(no email provided)";
853 var a = elem("a",{href:"javascript:void(0);",
854 style:"text-decoration:underline"},null, em);
855 var ourint = ++globalinteger;
856 var et1 = elem("input",{id:"update_email_1_" + ourint,type:"text",size:"20"});
857 var et2 = elem("input",{id:"update_email_2_" + ourint,type:"text",size:"20"});
858 var box = new PopupBox(a);
859 var but = elem("input",{type:"submit",value:"Submit"});
860 var can = elem("input",{type:"submit",value:"Cancel"});
862 but.onclick = function(){
863 var ret = _submitUpdateNotifyEmail(hold, ourint);
866 globalmyopac.draw("holds");
869 can.onclick = function(){ box.hide(); };
871 box.title("Change Holds Notification Email");
872 box.addText("Enter new notification email");
875 box.addText("Repeat email");
878 box.makeGroup([ but, can ]);
880 a.onclick = function(){box.show(); et1.focus();}
884 /* return true to show success */
885 function _submitUpdateNotifyEmail(hold, ourint) {
887 var e1 = getById("update_email_1_" + ourint).value;
888 var e2 = getById("update_email_2_" + ourint).value;
890 if(!e1 || !e2 || e1 == "" || e2 == "") {
891 alert("Enter and repeate new email address");
895 alert("Email addresses do not match");
899 hold.email_notify(e1);
900 if(_updateHold(hold)) return true;
903 function _submitUpdateNotifyPhone(hold, ourint) {
904 var p = getById("update_phone_" + ourint).value;
906 alert("Enter new phone number in the field provided");
910 hold.phone_notify(p);
911 if(_updateHold(hold)) return true;
915 function _updateHold(hold) {
916 var req = new RemoteRequest(
918 "open-ils.circ.hold.update",
919 globalmyopac.user.session_id, hold);
921 if(req.getResultObject()) return true;
925 function _buildChangePhoneNotify(hold) {
927 var phone = hold.phone_notify();
928 if(!phone || phone == "") phone = "(no phone provided)";
929 var a = elem("a",{href:"javascript:void(0);",
930 style:"text-decoration:underline"},null, phone);
932 var ourint = ++globalinteger;
934 var et1 = elem("input",{id:"update_phone_" + ourint,type:"text",size:"10"});
935 var box = new PopupBox(a);
936 var but = elem("input",{type:"submit",value:"Submit"});
937 var can = elem("input",{type:"submit",value:"Cancel"});
939 but.onclick = function(){
940 var ret = _submitUpdateNotifyPhone(hold, ourint);
943 globalmyopac.draw("holds");
946 can.onclick = function(){ box.hide(); };
948 box.title("Change Holds Notification Phone Number");
949 box.addText("Enter new notification number");
952 box.makeGroup([ but, can ]);
954 a.onclick = function(){box.show(); et1.focus();}
959 function _mkFormatList(formats) {
961 var div = elem("div");
962 var seen = new Object();
963 for( var i = 0; i!= formats.length; i++ ) {
964 var form = MARCFormatToMods(formats.charAt(i));
965 if(seen[form]) continue;
966 div.appendChild(mkResourceImage(form));
975 MyOPACSPage.prototype.grabHolds = function() {
977 var req = new RemoteRequest(
979 "open-ils.circ.holds.retrieve",
980 this.user.session_id,
981 this.user.userObject.id() );
983 return req.getResultObject();
995 /* ----------------------------------------------------------------- ========== ------------ */
999 MyOPACSPage.prototype.drawPersonal = function() {
1000 this.personalBox = new Box();
1001 this.personalBox.init(
1002 "Edit User Information", false, false);
1006 var uname_div = createAppElement("div");
1007 var uname_href = createAppElement("a");
1008 uname_href.onclick = function() {obj.buildUpdateUname();}
1009 uname_href.setAttribute("href", "javascript:void(0)");
1010 uname_href.appendChild(mktext("Change Username"));
1012 uname_div.appendChild(mktext("Username is "));
1013 var bold = createAppElement("b");
1014 bold.appendChild(mktext(this.user.username));
1015 uname_div.appendChild(bold);
1016 uname_div.appendChild(createAppElement("br"));
1017 uname_div.appendChild(uname_href);
1018 this.personalBox.addItem( uname_div,"edit_username");
1020 this.personalBox.addItem( createAppElement("hr"),"break");
1022 var password_href = createAppElement("a");
1023 password_href.setAttribute("href", "javascript:void(0)");
1024 password_href.onclick = function() {obj.buildUpdatePassword();}
1025 password_href.appendChild(mktext("Change Password"));
1026 this.personalBox.addItem( password_href,"edit_password");
1028 this.personalBox.addItem( createAppElement("hr"),"break2");
1030 var email_div = createAppElement("div");
1031 var email_href = createAppElement("a");
1032 email_href.onclick = function() {obj.buildUpdateEmail();}
1033 email_href.setAttribute("href", "javascript:void(0)");
1034 email_href.appendChild(mktext("Change Email Address"));
1036 var em = this.user.userObject.email();
1037 if(!em) em = "[empty]";
1039 email_div.appendChild(mktext("Email address is "));
1040 var bold = createAppElement("b");
1041 bold.appendChild(mktext(em));
1042 email_div.appendChild(bold);
1043 email_div.appendChild(createAppElement("br"));
1044 email_div.appendChild(email_href);
1045 this.personalBox.addItem( email_div,"edit_email");
1048 this.personal.appendChild(this.personalBox.getNode());
1052 MyOPACSPage.prototype.buildUpdateEmail = function() {
1053 var item = this.personalBox.findByKey("edit_email");
1054 var node = item.getNode();
1056 if(node.childNodes.length > 1) {
1057 node.removeChild(node.childNodes[1]);
1061 var newEmail = createAppElement("input");
1062 newEmail.setAttribute("type", "text");
1063 newEmail.id = "new_email";
1065 var newEmail2 = createAppElement("input");
1066 newEmail2.setAttribute("type", "text");
1067 newEmail2.id = "new_email2";
1069 var button = createAppElement("input");
1070 button.setAttribute("type", "submit");
1071 button.setAttribute("value", "Submit");
1074 button.onclick = function() {
1076 var em = getById("new_email").value;
1077 var em2 = getById("new_email2").value;
1079 alert("Email addresses do not match");
1082 var resp = obj.user.updateEmail(em);
1083 if(resp) { alert("Email updated successfully"); obj.draw();}
1086 var node = obj.personalBox.findByKey("edit_email").getNode();
1087 node.removeChild(node.childNodes[1]);
1091 var chunk = createAppElement("div");
1092 chunk.className = "edit_personal_active";
1094 chunk.appendChild(createAppElement("br"));
1095 chunk.appendChild(mktext("Enter New Email:"));
1096 chunk.appendChild(newEmail);
1097 chunk.appendChild(createAppElement("br"));
1098 chunk.appendChild(createAppElement("br"));
1099 chunk.appendChild(mktext("Repeat New Email:"));
1100 chunk.appendChild(createAppElement("br"));
1101 chunk.appendChild(newEmail2);
1102 chunk.appendChild(createAppElement("br"));
1103 chunk.appendChild(createAppElement("br"));
1104 chunk.appendChild(mktext(" "));
1106 var center = createAppElement("center");
1107 center.appendChild(button);
1108 chunk.appendChild(center);
1110 node.appendChild(chunk);
1111 try { newEmail.focus(); } catch(E){}
1115 MyOPACSPage.prototype.buildUpdateUname = function() {
1116 var item = this.personalBox.findByKey("edit_username");
1117 var node = item.getNode();
1119 if(node.childNodes.length > 1) {
1120 node.removeChild(node.childNodes[1]);
1124 var newName = createAppElement("input");
1125 newName.setAttribute("type", "text");
1126 newName.id = "new_uname";
1128 var button = createAppElement("input");
1129 button.setAttribute("type", "submit");
1130 button.setAttribute("value", "Submit");
1133 button.onclick = function() {
1135 var resp = obj.user.updateUsername(getById("new_uname").value);
1136 if(resp) { alert("Username updated successfully"); obj.draw()}
1137 else { alert("Username update failed"); return; }
1139 var node = obj.personalBox.findByKey("edit_username").getNode();
1140 node.removeChild(node.childNodes[1]);
1144 var chunk = createAppElement("div");
1145 chunk.className = "edit_personal_active";
1147 chunk.appendChild(createAppElement("br"));
1148 chunk.appendChild(mktext("Enter New Username:"));
1149 chunk.appendChild(newName);
1150 chunk.appendChild(createAppElement("br"));
1151 chunk.appendChild(createAppElement("br"));
1152 chunk.appendChild(mktext(" "));
1154 var center = createAppElement("center");
1155 center.appendChild(button);
1156 chunk.appendChild(center);
1158 //chunk.appendChild(createAppElement("br"));
1159 //chunk.appendChild(createAppElement("br"));
1160 node.appendChild(chunk);
1161 try { newName.focus(); } catch(E){}
1164 MyOPACSPage.prototype.buildUpdatePassword = function() {
1165 var item = this.personalBox.findByKey("edit_password");
1166 var node = item.getNode();
1167 if(node.childNodes.length > 1) {
1168 node.removeChild(node.childNodes[1]);
1172 var oldPassword = createAppElement("input");
1173 oldPassword.setAttribute("type", "password");
1174 oldPassword.id = "old_password";
1176 var newPassword = createAppElement("input");
1177 newPassword.setAttribute("type", "password");
1178 newPassword.id = "new_password";
1180 var newPassword2 = createAppElement("input");
1181 newPassword2.setAttribute("type", "password");
1182 newPassword2.id = "new_password2";
1185 var button = createAppElement("input");
1186 button.setAttribute("type", "submit");
1187 button.setAttribute("value", "Submit");
1190 button.onclick = function() {
1192 var new1 = getById("new_password").value;
1193 var new2 = getById("new_password2").value;
1194 var old = getById("old_password").value;
1197 alert("Passwords do not match");
1201 var resp = obj.user.updatePassword(old, new1);
1202 if(resp) { alert("Password updated successfully"); }
1205 var node = obj.personalBox.findByKey("edit_password").getNode();
1206 node.removeChild(node.childNodes[1]);
1209 var chunk = createAppElement("div");
1210 chunk.className = "edit_personal_active";
1212 chunk.appendChild(createAppElement("br"));
1213 chunk.appendChild(mktext("Current Password:"));
1214 chunk.appendChild(oldPassword);
1215 chunk.appendChild(createAppElement("br"));
1217 chunk.appendChild(createAppElement("br"));
1218 chunk.appendChild(mktext("Enter New Password:"));
1219 chunk.appendChild(newPassword);
1220 chunk.appendChild(createAppElement("br"));
1222 chunk.appendChild(createAppElement("br"));
1223 chunk.appendChild(mktext("Re-Enter New Password:"));
1224 chunk.appendChild(newPassword2);
1225 chunk.appendChild(createAppElement("br"));
1226 chunk.appendChild(createAppElement("br"));
1228 chunk.appendChild(mktext(" "));
1230 var center = createAppElement("center");
1231 center.appendChild(button);
1232 chunk.appendChild(center);
1234 //chunk.appendChild(createAppElement("br"));
1235 node.appendChild(chunk);
1236 try { newPassword.focus(); } catch(E){}
1242 MyOPACSPage.prototype.getCheckedOut = function() {
1244 this.checkedOutBox = new Box();
1245 this.checkedOutBox.init(
1246 "Items Checked Out", false, false);
1247 this.checkedOutBox.sortByKey();
1250 var request = new RemoteRequest(
1252 "open-ils.circ.actor.user.checked_out",
1253 this.user.getSessionId() );
1256 request.setCompleteCallback(
1258 obj._addCircs(req.getResultObject());
1267 MyOPACSPage.prototype._addCircs = function(data) {
1269 if(data.length < 1) {
1270 debug("No circs exist for this user");
1271 this.checkedOutBox.addItem(
1272 mktext("No items currently checked out") );
1276 for( var index in data ) {
1278 var circ = data[index].circ;
1279 var record = data[index].record;
1280 var copy = data[index].copy;
1283 var due = new Date(parseInt(circ.due_date() + "000")).toLocaleString();
1284 due = due.replace(/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/,"");
1286 var title_href = createAppElement("a");
1287 title_href.setAttribute("href","?sub_frame=1&target=record_detail&record=" + record.doc_id() );
1288 title_href.setAttribute("target","_top"); /* escape to the outermost frame */
1289 title_href.appendChild(mktext(record.title()));
1291 /* grab circ lib name */
1292 var org = this._getOrgUnit(copy.circ_lib());
1295 /* for each circulation, build a small table of data */
1296 var table = createAppElement("table");
1297 this._mkCircRow(table, "Title", title_href);
1298 //this._mkCircRow(table, "Due Date", mktext(due));
1299 this._mkCircRow(table, "Due Date", mktext(due));
1300 this._mkCircRow(table, "Duration", mktext(circ.duration()));
1301 this._mkCircRow(table, "Barcode", mktext(copy.barcode()));
1302 this._mkCircRow(table, "Circulating Library", mktext(org));
1305 this.checkedOutBox.addItem(table);
1307 if(index < data.length - 1)
1308 this.checkedOutBox.addItem(createAppElement("hr"));
1313 MyOPACSPage.prototype._mkCircRow = function(table, title, data) {
1314 var row = table.insertRow(table.rows.length);
1315 var cell = row.insertCell(row.cells.length);
1316 cell.appendChild(mktext(title));
1317 cell = row.insertCell(row.cells.length);
1318 cell.appendChild(data);
1322 MyOPACSPage.prototype._getOrgUnit = function(org_id) {
1323 var request = new RemoteRequest(
1325 "open-ils.actor.org_unit.retrieve",
1326 this.user.getSessionId(),
1329 return request.getResultObject();