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");
31 removeChildren(this.infoPane);
32 removeChildren(this.infoTable);
33 this.infoPane.appendChild(this.infoTable);
37 this.buildNavBox(true);
39 this.checkCell = getById("my_opac_checked");
40 this.holdsCell = getById("my_opac_holds");
41 this.profileCell = getById("my_opac_profile");
42 this.finesCell = getById("my_opac_fines");
44 check = getById("my_opac_checked_link");
45 holds = getById("my_opac_holds_link");
46 profile = getById("my_opac_profile_link");
47 fines = getById("my_opac_fines_link");
50 check.onclick = function() { obj.drawCheckedOut(); };
51 holds.onclick = function() { obj.drawHolds(); };
52 profile.onclick = function() { obj.drawProfile(); };
53 fines.onclick = function() { obj.drawFines(); };
56 case "holds": this.drawHolds(); break;
57 case "profile": this.drawProfile(); break;
58 case "fines": this.drawFines(); break;
60 default:this.drawCheckedOut();
65 MyOPACSPage.prototype.setLink = function(cell) {
66 remove_css_class(this.checkCell, "my_opac_link_cell_active");
67 remove_css_class(this.holdsCell, "my_opac_link_cell_active");
68 remove_css_class(this.profileCell, "my_opac_link_cell_active");
69 remove_css_class(this.finesCell, "my_opac_link_cell_active");
70 add_css_class(cell, "my_opac_link_cell_active");
73 MyOPACSPage.prototype.drawCheckedOut = function() {
74 removeChildren(this.infoTable);
75 removeChildren(this.infoPane);
76 this.infoPane.appendChild(this.infoTable);
77 this.setLink(this.checkCell);
78 this.getCheckedOut(_drawCheckedOut);
81 MyOPACSPage.prototype.drawHolds = function() {
82 removeChildren(this.infoTable);
83 removeChildren(this.infoPane);
84 this.infoPane.appendChild(this.infoTable);
85 this.setLink(this.holdsCell);
89 MyOPACSPage.prototype.drawProfile = function() {
90 removeChildren(this.infoTable);
91 removeChildren(this.infoPane);
92 this.infoPane.appendChild(this.infoTable);
93 this.setLink(this.profileCell);
97 MyOPACSPage.prototype.drawFines = function() {
98 removeChildren(this.infoTable);
99 removeChildren(this.infoPane);
100 this.infoPane.appendChild(this.infoTable);
101 this.setLink(this.finesCell);
105 function _drawCheckedOut(obj, data) {
107 if(data == null) return;
108 var circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
110 var dcell = circRow.insertCell(circRow.cells.length);
111 dcell.appendChild(mktext("Due Date"));
112 var tcell = circRow.insertCell(circRow.cells.length)
113 tcell.appendChild(mktext("Title"));
114 var drcell = circRow.insertCell(circRow.cells.length);
115 drcell.appendChild(mktext("Duration"));
116 var bcell = circRow.insertCell(circRow.cells.length);
117 bcell.appendChild(mktext("Barcode"));
118 var ccell = circRow.insertCell(circRow.cells.length);
119 ccell.appendChild(mktext("Circulating Library"));
120 var rcell = circRow.insertCell(circRow.cells.length);
121 rcell.appendChild(mktext("Renewals Remaining"));
122 var rbcell = circRow.insertCell(circRow.cells.length);
123 rbcell.appendChild(mktext("Renew?"));
125 add_css_class(tcell, "my_opac_info_table_header");
126 add_css_class(dcell, "my_opac_info_table_header");
127 add_css_class(drcell, "my_opac_info_table_header");
128 add_css_class(bcell, "my_opac_info_table_header");
129 add_css_class(ccell, "my_opac_info_table_header");
130 add_css_class(rcell, "my_opac_info_table_header");
131 add_css_class(rbcell, "my_opac_info_table_header");
134 if(data.length < 1) {
135 debug("No circs exist for this user");
136 circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
137 circRow.insertCell(0).appendChild(
138 mktext("No items currently checked out"));
142 for( var index in data ) {
144 var circ = data[index].circ;
145 var record = data[index].record;
146 var copy = data[index].copy;
147 circRow = obj.infoTable.insertRow(obj.infoTable.rows.length);
150 var due = circ.due_date();
151 due = due.replace(/[0-9][0-9]:.*$/,"");
153 var title_href = createAppElement("a");
154 var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
155 title_href.setAttribute("href", prefix + "?sub_frame=1&target=record_detail&record=" + record.doc_id() );
156 title_href.setAttribute("target","_top"); /* escape to the outermost frame */
157 title_href.appendChild(mktext(record.title()));
159 var renewboxlink = mktext("N/A");
160 if(parseInt(circ.renewal_remaining()) > 0)
161 renewboxlink = buildRenewBoxLink(circ);
163 /* grab circ lib name */
164 var org = obj._getOrgUnit(copy.circ_lib());
167 /* for each circulation, build a row of data */
168 var dueCell = circRow.insertCell(circRow.cells.length);
169 var titleCell = circRow.insertCell(circRow.cells.length);
170 var durationCell = circRow.insertCell(circRow.cells.length);
171 var barcodeCell = circRow.insertCell(circRow.cells.length);
172 var circLibCell = circRow.insertCell(circRow.cells.length);
173 var renewRemainCell = circRow.insertCell(circRow.cells.length);
174 var renewCell = circRow.insertCell(circRow.cells.length);
176 add_css_class(titleCell, "my_opac_profile_cell");
177 add_css_class(dueCell, "my_opac_profile_cell");
178 add_css_class(durationCell, "my_opac_profile_cell");
179 add_css_class(barcodeCell, "my_opac_profile_cell");
180 add_css_class(circLibCell, "my_opac_profile_cell");
181 add_css_class(renewRemainCell, "my_opac_profile_cell");
182 add_css_class(renewCell, "my_opac_profile_cell");
184 titleCell.appendChild(title_href);
185 dueCell.appendChild(mktext(due));
186 durationCell.appendChild(mktext(circ.duration()));
187 barcodeCell.appendChild(mktext(copy.barcode()));
188 circLibCell.appendChild(mktext(org));
189 renewRemainCell.appendChild(mktext(circ.renewal_remaining()));
190 renewCell.appendChild(renewboxlink);
196 function buildRenewBoxLink(circ) {
199 {href:"javascript:void(0);",style:"text-decoration:underline"}, null, "Renew");
200 var but = elem("input",{type:"submit",value:"Renew Circulation"});
201 var can = elem("input",{type:"submit",value:"Cancel"});
203 var box = new PopupBox(a);
204 a.onclick = function(){box.show();}
205 can.onclick = function(){box.hide();}
206 but.onclick = function(){renewCheckout(circ);box.hide();};
207 box.title("Renew Circulation");
208 box.addText("Are you sure you want to renew the circulation?");
209 box.makeGroup([but, can]);
213 function renewCheckout(circ) {
214 var req = new RemoteRequest(
215 "open-ils.circ", "open-ils.circ.renew",
216 globalmyopac.user.session_id, circ );
219 try{req.getResultObject();}catch(E){return;}
220 alert("Renewal completed successfully");
221 globalmyopac.draw("checked");
225 MyOPACSPage.prototype.getCheckedOut = function(callback) {
227 /* grab our circs and records */
228 var request = new RemoteRequest(
230 "open-ils.circ.actor.user.checked_out",
231 this.user.getSessionId() );
234 request.setCompleteCallback(
237 callback(obj, req.getResultObject());
245 MyOPACSPage.prototype._drawProfile = function() {
247 this.user.fleshMe(true);
248 var infot = elem("table");
249 this.infoTable.insertRow(0).insertCell(0).appendChild(infot);
250 this.infoTable.insertRow(1).insertCell(0).appendChild(
251 elem("div",{id:"my_opac_update_info"}));
253 var urow = infot.insertRow(infot.rows.length);
254 var prow = infot.insertRow(infot.rows.length);
255 var erow = infot.insertRow(infot.rows.length);
256 var brow = infot.insertRow(infot.rows.length);
257 var arow = infot.insertRow(infot.rows.length);
258 var a2row = infot.insertRow(infot.rows.length);
260 var ucell = urow.insertCell(urow.cells.length);
261 var ucell2 = urow.insertCell(urow.cells.length);
262 var ucell3 = urow.insertCell(urow.cells.length);
264 var pcell = prow.insertCell(prow.cells.length);
265 var pcell2 = prow.insertCell(prow.cells.length);
266 var pcell3 = prow.insertCell(prow.cells.length);
268 var ecell = erow.insertCell(erow.cells.length);
269 var ecell2 = erow.insertCell(erow.cells.length);
270 var ecell3 = erow.insertCell(erow.cells.length);
272 var bcell = brow.insertCell(brow.cells.length);
273 var bcell2 = brow.insertCell(brow.cells.length);
274 var bcell3 = brow.insertCell(brow.cells.length);
276 add_css_class(ucell, "my_opac_info_table_header");
277 add_css_class(pcell, "my_opac_info_table_header");
278 add_css_class(ecell, "my_opac_info_table_header");
279 add_css_class(bcell, "my_opac_info_table_header");
281 add_css_class(ucell2, "my_opac_profile_cell");
282 add_css_class(pcell2, "my_opac_profile_cell");
283 add_css_class(ecell2, "my_opac_profile_cell");
284 add_css_class(bcell2, "my_opac_profile_cell");
286 add_css_class(ucell3, "my_opac_profile_cell");
287 add_css_class(pcell3, "my_opac_profile_cell");
288 add_css_class(ecell3, "my_opac_profile_cell");
289 add_css_class(bcell3, "my_opac_profile_cell");
291 var ubold = elem("b");
292 var pbold = elem("b");
293 var ebold = elem("b");
294 var bbold = elem("b");
295 var abold = elem("b");
297 var uclick = elem("a",
298 {id:"uname_link",href:"javascript:void(0);",
299 style:"text-decoration:underline;"}, null, "Change");
301 var pclick = elem("a",
302 {id:"passwd_link",href:"javascript:void(0);",
303 style:"text-decoration:underline;"}, null, "Change");
305 var eclick = elem("a",
306 {id:"email_link",href:"javascript:void(0);",
307 style:"text-decoration:underline;"}, null, "Change");
310 uclick.onclick = function() { obj.updateUsername(); }
311 pclick.onclick = function() { obj.updatePassword(); }
312 eclick.onclick = function() { obj.updateEmail(); }
314 ucell.appendChild(mktext("Username"));
315 ubold.appendChild(mktext(this.user.userObject.usrname()));
316 ucell2.appendChild(ubold);
317 ucell3.appendChild(uclick);
319 pcell.appendChild(mktext("Password"));
320 pbold.appendChild(mktext("N/A"));
321 pcell2.appendChild(pbold);
322 pcell3.appendChild(pclick);
324 ecell.appendChild(mktext("Email Address"));
325 ebold.appendChild(mktext(this.user.userObject.email()));
326 ecell2.appendChild(ebold);
327 ecell3.appendChild(eclick);
329 bcell.appendChild(mktext("Active Barcode"));
330 bbold.appendChild(mktext(this.user.userObject.card().barcode()));
331 bcell2.appendChild(bbold);
332 bcell3.appendChild(mktext(" "));
335 var addrTable = elem("table");
336 add_css_class(addrTable, "my_opac_addr_table");
338 var row = addrTable.insertRow(0);
339 var mailing = row.insertCell(0);
340 var space = row.insertCell(1);
341 var billing = row.insertCell(2);
345 space.setAttribute("style","width: 30px");
346 space.appendChild(mktext(" "));
348 appendChild(this.mkAddrTable(addrTable, this.userObject.addresses()[a]));
350 var addr = this.user.userObject.mailing_address();
351 mailing.appendChild(this.mkAddrTable("Mailing Address", addr));
353 addr = this.user.userObject.billing_address();
354 billing.appendChild(this.mkAddrTable("Billing Address", addr));
356 this.infoPane.appendChild(elem("br"));
360 this.infoPane.appendChild(elem("hr"));
361 this.infoPane.appendChild(elem("br"));
362 this.infoPane.appendChild(this.mkAddrTable(this.user.userObject.addresses()));
367 MyOPACSPage.prototype.mkAddrTable = function(addresses) {
369 var table = elem("table");
370 add_css_class(table, "my_opac_addr_table");
372 var row = table.insertRow(table.rows.length);
373 var cell = row.insertCell(row.cells.length);
374 add_css_class(cell, "my_opac_info_table_header");
375 cell.appendChild(mktext("Address Type"));
377 cell = row.insertCell(row.cells.length);
378 add_css_class(cell, "my_opac_info_table_header");
379 cell.appendChild(mktext("Street"));
381 cell = row.insertCell(row.cells.length);
382 add_css_class(cell, "my_opac_info_table_header");
383 cell.appendChild(mktext("City"));
385 cell = row.insertCell(row.cells.length);
386 add_css_class(cell, "my_opac_info_table_header");
387 cell.appendChild(mktext("County"));
389 cell = row.insertCell(row.cells.length);
390 add_css_class(cell, "my_opac_info_table_header");
391 cell.appendChild(mktext("State"));
393 cell = row.insertCell(row.cells.length);
394 add_css_class(cell, "my_opac_info_table_header");
395 cell.appendChild(mktext("Zip Code"));
397 cell = row.insertCell(row.cells.length);
398 add_css_class(cell, "my_opac_info_table_header");
399 cell.appendChild(mktext("Valid"));
401 for( var a in addresses ) {
402 var addr = addresses[a];
403 var row = table.insertRow(table.rows.length);
404 var cell = row.insertCell(row.cells.length);
405 add_css_class(cell, "my_opac_profile_cell");
406 cell.appendChild(mktext(addr.address_type()));
408 cell = row.insertCell(row.cells.length);
409 add_css_class(cell, "my_opac_profile_cell");
410 var st = addr.street1();
411 if(addr.street2()) st += ", " + addr.street2();
412 cell.appendChild(mktext(st));
414 cell = row.insertCell(row.cells.length);
415 add_css_class(cell, "my_opac_profile_cell");
416 cell.appendChild(mktext(addr.city()));
418 cell = row.insertCell(row.cells.length);
419 add_css_class(cell, "my_opac_profile_cell");
420 cell.appendChild(mktext(addr.county()));
422 cell = row.insertCell(row.cells.length);
423 add_css_class(cell, "my_opac_profile_cell");
424 cell.appendChild(mktext(addr.state()));
426 cell = row.insertCell(row.cells.length);
427 add_css_class(cell, "my_opac_profile_cell");
428 cell.appendChild(mktext(addr.post_code()));
431 if(addr.valid() != "1") v = "No";
432 cell = row.insertCell(row.cells.length);
433 add_css_class(cell, "my_opac_profile_cell");
434 cell.appendChild(mktext(v));
444 MyOPACSPage.prototype.__mkAddrTable = function(type, addr) {
445 var table = elem("table");
447 var header_row = table.insertRow(table.rows.length);
448 var header_cell = header_row.insertCell(0);
449 add_css_class(header_cell,"my_opac_info_table_header");
450 header_cell.id = "header_cell";
451 header_cell.colSpan = 2;
452 header_cell.setAttribute("colspan", "2");
453 header_cell.appendChild(mktext(type));
455 var s1row = table.insertRow(table.rows.length);
456 var s2row = table.insertRow(table.rows.length);
457 var cityrow = table.insertRow(table.rows.length);
458 var ziprow = table.insertRow(table.rows.length);
459 var staterow = table.insertRow(table.rows.length);
461 var s1cell = s1row.insertCell(0);
462 var s2cell = s2row.insertCell(0);
463 var citycell = cityrow.insertCell(0);
464 var zipcell = ziprow.insertCell(0);
465 var statecell = staterow.insertCell(0);
467 add_css_class(s1cell, "my_opac_info_table_header");
468 add_css_class(s2cell, "my_opac_info_table_header");
469 add_css_class(citycell, "my_opac_info_table_header");
470 add_css_class(zipcell, "my_opac_info_table_header");
471 add_css_class(statecell, "my_opac_info_table_header");
473 s1cell.appendChild(mktext("Address 1"));
474 s2cell.appendChild(mktext("Address 2"));
475 citycell.appendChild(mktext("City"));
476 zipcell.appendChild(mktext("Zip"));
477 statecell.appendChild(mktext("State"));
480 s1cell = s1row.insertCell(1);
481 s2cell = s2row.insertCell(1);
482 citycell = cityrow.insertCell(1);
483 zipcell = ziprow.insertCell(1);
484 statecell = staterow.insertCell(1);
486 add_css_class(s1cell, "my_opac_profile_cell");
487 add_css_class(s2cell, "my_opac_profile_cell");
488 add_css_class(citycell, "my_opac_profile_cell");
489 add_css_class(zipcell, "my_opac_profile_cell");
490 add_css_class(statecell, "my_opac_profile_cell");
493 s1cell.appendChild(mktext(addr.street1()));
494 s2cell.appendChild(mktext(addr.street2()));
495 citycell.appendChild(mktext(addr.city()));
496 zipcell.appendChild(mktext(addr.post_code()));
497 statecell.appendChild(mktext(addr.state()));
503 MyOPACSPage.prototype.updateUsername = function() {
504 var div = getById("my_opac_update_info");
506 /* user clicks to close */
507 if(getById("my_opac_update_usrname")) {
514 var ut = elem("input",{type:"text",id:"new_uname"});
515 var but = elem("input",{type:"submit",value:"Update"});
516 var table = elem("table");
517 table.id = "my_opac_update_usrname";
518 var row = table.insertRow(0);
521 add_css_class(table,"my_opac_update_table");
523 var c0 = row.insertCell(0);
524 var c1 = row.insertCell(1);
525 var c2 = row.insertCell(2);
527 c0.appendChild(mktext("Enter new username: " ));
531 div.appendChild(elem("br"));
532 div.appendChild(table);
534 try{ut.focus();}catch(E){}
536 /* verify looks ok, send the update request */
538 but.onclick = function() {
539 var uname = getById("new_uname").value;
540 if(uname == null || uname == "") {
541 alert("Please enter a username");
544 var resp = obj.user.updateUsername(uname);
545 if(resp) alert("Username updated successfully");
546 else{ alert("Username update failed"); return; }
552 MyOPACSPage.prototype.updatePassword = function() {
553 var div = getById("my_opac_update_info");
555 /* user clicks to close */
556 if(getById("my_opac_update_password")) {
562 var ut = elem("input",{type:"password",size:"15",id:"old_password"});
563 var ut2 = elem("input",{type:"password",size:"15",id:"new_password_1"});
564 var ut3 = elem("input",{type:"password",size:"15",id:"new_password_2"});
565 var but = elem("input",{type:"submit",value:"Update"});
567 var table = elem("table");
568 table.id = "my_opac_update_password";
569 add_css_class(table,"my_opac_update_table");
571 var row = table.insertRow(0);
573 var c0 = row.insertCell(0);
574 var c1 = row.insertCell(1);
575 var c2 = row.insertCell(2);
576 var c3 = row.insertCell(3);
577 var c4 = row.insertCell(4);
578 var c5 = row.insertCell(5);
579 var c6 = row.insertCell(6);
581 c0.appendChild(mktext("Current password: " ));
584 c2.appendChild(mktext("New password: " ));
587 c4.appendChild(mktext("Repeat new password: " ));
591 div.appendChild(elem("br"));
592 div.appendChild(table);
595 try{ut.focus();}catch(E){}
597 /* verify looks ok, send the update request */
599 but.onclick = function() {
601 var old = getById("old_password").value;
602 var p1 = getById("new_password_1").value;
603 var p2 = getById("new_password_2").value;
605 if(!old || !p1 || !p2) {
606 alert("Please fill in all fields");
611 alert("New passwords do not match");
615 var resp = obj.user.updatePassword(old, p1);
616 if(resp) alert("Password updated successfully");
617 else {alert("Password change failed"); return; }
624 MyOPACSPage.prototype.updateEmail = function(){
625 var div = getById("my_opac_update_info");
627 /* user clicks to close */
628 if(getById("my_opac_update_usrname")) {
635 var ut = elem("input",{type:"text",id:"new_email"});
636 var but = elem("input",{type:"submit",value:"Update"});
637 var table = elem("table");
638 table.id = "my_opac_update_usrname";
639 var row = table.insertRow(0);
641 add_css_class(table,"my_opac_update_table");
643 var c0 = row.insertCell(0);
644 var c1 = row.insertCell(1);
645 var c2 = row.insertCell(2);
647 c0.appendChild(mktext("Enter new email address: " ));
651 div.appendChild(elem("br"));
652 div.appendChild(table);
654 try{ut.focus();}catch(E){}
656 /* verify looks ok, send the update request */
658 but.onclick = function() {
659 var uname = getById("new_email").value;
660 if(uname == null || uname == "") {
661 alert("Please enter a valid email address");
664 var resp = obj.user.updateEmail(uname);
665 if(resp) alert("Email updated successfully");
666 else{ alert("Email update failed"); return; }
673 MyOPACSPage.prototype._drawHolds = function() {
675 var table = this.infoTable;
676 var row = table.insertRow(table.rows.length);
678 var cell = row.insertCell(row.cells.length);
679 add_css_class(cell, "my_opac_info_table_header");
680 cell.appendChild(mktext("Request Date"));
682 cell = row.insertCell(row.cells.length);
683 add_css_class(cell, "my_opac_info_table_header");
684 cell.appendChild(mktext("Title"));
686 cell = row.insertCell(row.cells.length);
687 add_css_class(cell, "my_opac_info_table_header");
688 cell.appendChild(mktext("Author"));
690 cell = row.insertCell(row.cells.length);
691 add_css_class(cell, "my_opac_info_table_header");
692 cell.appendChild(mktext("Format(s)"));
695 cell = row.insertCell(row.cells.length);
696 add_css_class(cell, "my_opac_info_table_header");
697 cell.appendChild(mktext("Notify Email / Phone"));
699 cell = row.insertCell(row.cells.length);
700 add_css_class(cell, "my_opac_info_table_header");
701 cell.appendChild(mktext("Status"));
703 cell = row.insertCell(row.cells.length);
704 add_css_class(cell, "my_opac_info_table_header");
705 cell.appendChild(mktext("Pickup Location"));
707 cell = row.insertCell(row.cells.length);
708 add_css_class(cell, "my_opac_info_table_header");
709 cell.appendChild(mktext("Cancel"));
711 /* ---------------------------------------- */
712 row = table.insertRow(table.rows.length);
713 row.id = "holds_waiting";
714 cell = row.insertCell(row.cells.length);
715 cell.appendChild(mktext("Retrieving holds..."));
716 /* ---------------------------------------- */
718 var holds = this.grabHolds();
720 for( var idx = 0; idx != holds.length; idx++ ) {
721 var hold = holds[idx];
722 var r = table.insertRow(table.rows.length);
723 r.id = "hold_display_row_" + hold.id();
724 debug("Displaying hold " + hold.id());
725 _doCallbackDance(table, hold, this.user.session_id, this);
728 if(!holds || holds.length == 0) {
729 var z = getById("holds_waiting");
730 z.firstChild.innerHTML = "No holds currently placed";
736 function _doCallbackDance(table, hold, session_id, obj) {
737 if(hold == null) return;
738 debug("Setting holds callback with hold " + hold.id() );
739 var func = function(rec) {_drawHoldsRow(table, hold, rec, session_id, obj)};
741 /* grab the record that is held */
742 if(hold.hold_type() == "M")
743 fetchMetaRecord(hold.target(), func);
745 if(hold.hold_type() == "T")
746 fetchRecord(hold.target(), func);
750 function _drawHoldsRow(table, hold, record, session_id, obj) {
752 if(record == null || record.length == 0) return;
753 debug("In holds callback with hold " + hold );
755 //var row = table.insertRow(table.rows.length);
756 var row = getById("hold_display_row_" + hold.id());
758 var cell = row.insertCell(row.cells.length);
759 add_css_class(cell, "my_opac_profile_cell");
760 var t = hold.request_time().replace(/[0-9][0-9]:.*$/,"");
761 cell.appendChild(mktext(t));
764 cell = row.insertCell(row.cells.length);
765 add_css_class(cell, "my_opac_profile_cell");
766 cell.style.width = "35%";
768 var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
770 {href:prefix + "?sub_frame=1&target=record_detail&record="+encodeURIComponent(record.doc_id())},
771 null, record.title());
772 tl.setAttribute("target","_top");
773 cell.appendChild(tl);
775 cell = row.insertCell(row.cells.length);
777 {href:prefix + "?sub_frame=1&target=mr_result"+
778 "&mr_search_query="+encodeURIComponent(record.author())+
779 "&mr_search_type=author"},
780 null, record.author());
781 al.setAttribute("target","_top");
782 add_css_class(cell, "my_opac_profile_cell");
784 cell.appendChild(al);
786 cell = row.insertCell(row.cells.length);
787 add_css_class(cell, "my_opac_profile_cell");
789 var formats = hold.holdable_formats();
790 if(formats == null || formats == "") /* only metarecord holds have holdable_formats */
791 formats = modsFormatToMARC(record.types_of_resource()[0]);
793 cell.appendChild(_mkFormatList(formats));
794 cell.noWrap = "nowrap";
795 cell.setAttribute("nowrap", "nowrap");
798 cell = row.insertCell(row.cells.length);
799 add_css_class(cell, "my_opac_profile_cell");
800 cell.appendChild(_buildChangeEmailNotify(hold));
801 cell.appendChild(elem("br"));
802 cell.appendChild(_buildChangePhoneNotify(hold));
804 cell = row.insertCell(row.cells.length);
805 add_css_class(cell, "my_opac_profile_cell");
806 var stat = _fetchHoldStatus(hold);
807 cell.appendChild(mktext(stat));
809 cell = row.insertCell(row.cells.length);
810 add_css_class(cell, "my_opac_profile_cell");
811 cell.appendChild(mktext(findOrgUnit(hold.pickup_lib()).name()));
813 cell = row.insertCell(row.cells.length);
814 var a = elem("a",{href:"javascript:void(0);",
815 style:"text-decoration:underline"},null, "Cancel");
816 a.onclick = function(){_cancelHoldRequest(hold, a, session_id, obj);};
817 add_css_class(cell, "my_opac_profile_cell");
820 var z = getById("holds_waiting");
821 if(z) table.firstChild.removeChild(z);
824 function _fetchHoldStatus(hold) {
825 var req = new RemoteRequest(
827 "open-ils.circ.hold.status.retrieve",
828 globalmyopac.user.session_id, hold.id());
830 var stat = req.getResultObject();
831 if(stat == "1") stat = "Waiting for available copy";
832 if(stat == "2") stat = "Copy found, waiting for capture";
833 if(stat == "3") stat = "In Transit";
834 if(stat == "4") stat = "Available";
839 function _cancelHoldRequest(hold, node, session_id, obj) {
840 var box = new PopupBox(node);
841 box.title("Cancel Hold");
842 box.addText("Are you sure you wish to cancel the hold?");
843 var but = elem("input",{type:"submit",value:"Cancel Hold"});
844 var can = elem("input",{type:"submit",value:"Do not Cancel Hold"});
845 box.makeGroup([but, can]);
846 but.onclick = function(){
847 _cancelHold(hold, session_id); box.hide(); obj.draw("holds");};
848 can.onclick = function() { box.hide(); };
852 function _cancelHold(hold, session_id) {
853 var req = new RemoteRequest(
854 "open-ils.circ", "open-ils.circ.hold.cancel",
858 if(req.getResultObject())
859 alert("Hold successfully cancelled");
864 function _buildChangeEmailNotify(hold) {
865 var em = hold.email_notify();
866 if(!em || em == "") em = "(no email provided)";
867 var a = elem("a",{href:"javascript:void(0);",
868 style:"text-decoration:underline"},null, em);
869 var ourint = ++globalinteger;
870 var et1 = elem("input",{id:"update_email_1_" + ourint,type:"text",size:"20"});
871 var et2 = elem("input",{id:"update_email_2_" + ourint,type:"text",size:"20"});
872 var box = new PopupBox(a);
873 var but = elem("input",{type:"submit",value:"Submit"});
874 var can = elem("input",{type:"submit",value:"Cancel"});
876 but.onclick = function(){
877 var ret = _submitUpdateNotifyEmail(hold, ourint);
880 globalmyopac.draw("holds");
883 can.onclick = function(){ box.hide(); };
885 box.title("Change Holds Notification Email");
886 box.addText("Enter new notification email");
889 box.addText("Repeat email");
892 box.makeGroup([ but, can ]);
894 a.onclick = function(){box.show(); et1.focus();}
898 /* return true to show success */
899 function _submitUpdateNotifyEmail(hold, ourint) {
901 var e1 = getById("update_email_1_" + ourint).value;
902 var e2 = getById("update_email_2_" + ourint).value;
904 if(!e1 || !e2 || e1 == "" || e2 == "") {
905 alert("Enter and repeate new email address");
909 alert("Email addresses do not match");
913 hold.email_notify(e1);
914 if(_updateHold(hold)) return true;
917 function _submitUpdateNotifyPhone(hold, ourint) {
918 var p = getById("update_phone_" + ourint).value;
920 alert("Enter new phone number in the field provided");
924 hold.phone_notify(p);
925 if(_updateHold(hold)) return true;
929 function _updateHold(hold) {
930 var req = new RemoteRequest(
932 "open-ils.circ.hold.update",
933 globalmyopac.user.session_id, hold);
935 if(req.getResultObject()) return true;
939 function _buildChangePhoneNotify(hold) {
941 var phone = hold.phone_notify();
942 if(!phone || phone == "") phone = "(no phone provided)";
943 var a = elem("a",{href:"javascript:void(0);",
944 style:"text-decoration:underline"},null, phone);
946 var ourint = ++globalinteger;
948 var et1 = elem("input",{id:"update_phone_" + ourint,type:"text",size:"10"});
949 var box = new PopupBox(a);
950 var but = elem("input",{type:"submit",value:"Submit"});
951 var can = elem("input",{type:"submit",value:"Cancel"});
953 but.onclick = function(){
954 var ret = _submitUpdateNotifyPhone(hold, ourint);
957 globalmyopac.draw("holds");
960 can.onclick = function(){ box.hide(); };
962 box.title("Change Holds Notification Phone Number");
963 box.addText("Enter new notification number");
966 box.makeGroup([ but, can ]);
968 a.onclick = function(){box.show(); et1.focus();}
973 function _mkFormatList(formats) {
975 var div = elem("div");
976 var seen = new Object();
977 for( var i = 0; i!= formats.length; i++ ) {
978 var form = MARCFormatToMods(formats.charAt(i));
979 if(seen[form]) continue;
980 div.appendChild(mkResourceImage(form));
989 MyOPACSPage.prototype.grabHolds = function() {
991 var req = new RemoteRequest(
993 "open-ils.circ.holds.retrieve",
994 this.user.session_id,
995 this.user.userObject.id() );
997 return req.getResultObject();
1009 /* ----------------------------------------------------------------- ========== ------------ */
1013 MyOPACSPage.prototype.drawPersonal = function() {
1014 this.personalBox = new Box();
1015 this.personalBox.init(
1016 "Edit User Information", false, false);
1020 var uname_div = createAppElement("div");
1021 var uname_href = createAppElement("a");
1022 uname_href.onclick = function() {obj.buildUpdateUname();}
1023 uname_href.setAttribute("href", "javascript:void(0)");
1024 uname_href.appendChild(mktext("Change Username"));
1026 uname_div.appendChild(mktext("Username is "));
1027 var bold = createAppElement("b");
1028 bold.appendChild(mktext(this.user.username));
1029 uname_div.appendChild(bold);
1030 uname_div.appendChild(createAppElement("br"));
1031 uname_div.appendChild(uname_href);
1032 this.personalBox.addItem( uname_div,"edit_username");
1034 this.personalBox.addItem( createAppElement("hr"),"break");
1036 var password_href = createAppElement("a");
1037 password_href.setAttribute("href", "javascript:void(0)");
1038 password_href.onclick = function() {obj.buildUpdatePassword();}
1039 password_href.appendChild(mktext("Change Password"));
1040 this.personalBox.addItem( password_href,"edit_password");
1042 this.personalBox.addItem( createAppElement("hr"),"break2");
1044 var email_div = createAppElement("div");
1045 var email_href = createAppElement("a");
1046 email_href.onclick = function() {obj.buildUpdateEmail();}
1047 email_href.setAttribute("href", "javascript:void(0)");
1048 email_href.appendChild(mktext("Change Email Address"));
1050 var em = this.user.userObject.email();
1051 if(!em) em = "[empty]";
1053 email_div.appendChild(mktext("Email address is "));
1054 var bold = createAppElement("b");
1055 bold.appendChild(mktext(em));
1056 email_div.appendChild(bold);
1057 email_div.appendChild(createAppElement("br"));
1058 email_div.appendChild(email_href);
1059 this.personalBox.addItem( email_div,"edit_email");
1062 this.personal.appendChild(this.personalBox.getNode());
1066 MyOPACSPage.prototype.buildUpdateEmail = function() {
1067 var item = this.personalBox.findByKey("edit_email");
1068 var node = item.getNode();
1070 if(node.childNodes.length > 1) {
1071 node.removeChild(node.childNodes[1]);
1075 var newEmail = createAppElement("input");
1076 newEmail.setAttribute("type", "text");
1077 newEmail.id = "new_email";
1079 var newEmail2 = createAppElement("input");
1080 newEmail2.setAttribute("type", "text");
1081 newEmail2.id = "new_email2";
1083 var button = createAppElement("input");
1084 button.setAttribute("type", "submit");
1085 button.setAttribute("value", "Submit");
1088 button.onclick = function() {
1090 var em = getById("new_email").value;
1091 var em2 = getById("new_email2").value;
1093 alert("Email addresses do not match");
1096 var resp = obj.user.updateEmail(em);
1097 if(resp) { alert("Email updated successfully"); obj.draw();}
1100 var node = obj.personalBox.findByKey("edit_email").getNode();
1101 node.removeChild(node.childNodes[1]);
1105 var chunk = createAppElement("div");
1106 chunk.className = "edit_personal_active";
1108 chunk.appendChild(createAppElement("br"));
1109 chunk.appendChild(mktext("Enter New Email:"));
1110 chunk.appendChild(newEmail);
1111 chunk.appendChild(createAppElement("br"));
1112 chunk.appendChild(createAppElement("br"));
1113 chunk.appendChild(mktext("Repeat New Email:"));
1114 chunk.appendChild(createAppElement("br"));
1115 chunk.appendChild(newEmail2);
1116 chunk.appendChild(createAppElement("br"));
1117 chunk.appendChild(createAppElement("br"));
1118 chunk.appendChild(mktext(" "));
1120 var center = createAppElement("center");
1121 center.appendChild(button);
1122 chunk.appendChild(center);
1124 node.appendChild(chunk);
1125 try { newEmail.focus(); } catch(E){}
1129 MyOPACSPage.prototype.buildUpdateUname = function() {
1130 var item = this.personalBox.findByKey("edit_username");
1131 var node = item.getNode();
1133 if(node.childNodes.length > 1) {
1134 node.removeChild(node.childNodes[1]);
1138 var newName = createAppElement("input");
1139 newName.setAttribute("type", "text");
1140 newName.id = "new_uname";
1142 var button = createAppElement("input");
1143 button.setAttribute("type", "submit");
1144 button.setAttribute("value", "Submit");
1147 button.onclick = function() {
1149 var resp = obj.user.updateUsername(getById("new_uname").value);
1150 if(resp) { alert("Username updated successfully"); obj.draw()}
1151 else { alert("Username update failed"); return; }
1153 var node = obj.personalBox.findByKey("edit_username").getNode();
1154 node.removeChild(node.childNodes[1]);
1158 var chunk = createAppElement("div");
1159 chunk.className = "edit_personal_active";
1161 chunk.appendChild(createAppElement("br"));
1162 chunk.appendChild(mktext("Enter New Username:"));
1163 chunk.appendChild(newName);
1164 chunk.appendChild(createAppElement("br"));
1165 chunk.appendChild(createAppElement("br"));
1166 chunk.appendChild(mktext(" "));
1168 var center = createAppElement("center");
1169 center.appendChild(button);
1170 chunk.appendChild(center);
1172 //chunk.appendChild(createAppElement("br"));
1173 //chunk.appendChild(createAppElement("br"));
1174 node.appendChild(chunk);
1175 try { newName.focus(); } catch(E){}
1178 MyOPACSPage.prototype.buildUpdatePassword = function() {
1179 var item = this.personalBox.findByKey("edit_password");
1180 var node = item.getNode();
1181 if(node.childNodes.length > 1) {
1182 node.removeChild(node.childNodes[1]);
1186 var oldPassword = createAppElement("input");
1187 oldPassword.setAttribute("type", "password");
1188 oldPassword.id = "old_password";
1190 var newPassword = createAppElement("input");
1191 newPassword.setAttribute("type", "password");
1192 newPassword.id = "new_password";
1194 var newPassword2 = createAppElement("input");
1195 newPassword2.setAttribute("type", "password");
1196 newPassword2.id = "new_password2";
1199 var button = createAppElement("input");
1200 button.setAttribute("type", "submit");
1201 button.setAttribute("value", "Submit");
1204 button.onclick = function() {
1206 var new1 = getById("new_password").value;
1207 var new2 = getById("new_password2").value;
1208 var old = getById("old_password").value;
1211 alert("Passwords do not match");
1215 var resp = obj.user.updatePassword(old, new1);
1216 if(resp) { alert("Password updated successfully"); }
1219 var node = obj.personalBox.findByKey("edit_password").getNode();
1220 node.removeChild(node.childNodes[1]);
1223 var chunk = createAppElement("div");
1224 chunk.className = "edit_personal_active";
1226 chunk.appendChild(createAppElement("br"));
1227 chunk.appendChild(mktext("Current Password:"));
1228 chunk.appendChild(oldPassword);
1229 chunk.appendChild(createAppElement("br"));
1231 chunk.appendChild(createAppElement("br"));
1232 chunk.appendChild(mktext("Enter New Password:"));
1233 chunk.appendChild(newPassword);
1234 chunk.appendChild(createAppElement("br"));
1236 chunk.appendChild(createAppElement("br"));
1237 chunk.appendChild(mktext("Re-Enter New Password:"));
1238 chunk.appendChild(newPassword2);
1239 chunk.appendChild(createAppElement("br"));
1240 chunk.appendChild(createAppElement("br"));
1242 chunk.appendChild(mktext(" "));
1244 var center = createAppElement("center");
1245 center.appendChild(button);
1246 chunk.appendChild(center);
1248 //chunk.appendChild(createAppElement("br"));
1249 node.appendChild(chunk);
1250 try { newPassword.focus(); } catch(E){}
1256 MyOPACSPage.prototype.getCheckedOut = function() {
1258 this.checkedOutBox = new Box();
1259 this.checkedOutBox.init(
1260 "Items Checked Out", false, false);
1261 this.checkedOutBox.sortByKey();
1264 var request = new RemoteRequest(
1266 "open-ils.circ.actor.user.checked_out",
1267 this.user.getSessionId() );
1270 request.setCompleteCallback(
1272 obj._addCircs(req.getResultObject());
1281 MyOPACSPage.prototype._addCircs = function(data) {
1283 if(data.length < 1) {
1284 debug("No circs exist for this user");
1285 this.checkedOutBox.addItem(
1286 mktext("No items currently checked out") );
1290 for( var index in data ) {
1292 var circ = data[index].circ;
1293 var record = data[index].record;
1294 var copy = data[index].copy;
1297 var due = new Date(parseInt(circ.due_date() + "000")).toLocaleString();
1298 due = due.replace(/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/,"");
1300 var title_href = createAppElement("a");
1301 var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
1302 title_href.setAttribute("href",prefix + "?sub_frame=1&target=record_detail&record=" + record.doc_id() );
1303 title_href.setAttribute("target","_top"); /* escape to the outermost frame */
1304 title_href.appendChild(mktext(record.title()));
1306 /* grab circ lib name */
1307 var org = this._getOrgUnit(copy.circ_lib());
1310 /* for each circulation, build a small table of data */
1311 var table = createAppElement("table");
1312 this._mkCircRow(table, "Due Date", mktext(due));
1313 this._mkCircRow(table, "Title", title_href);
1314 this._mkCircRow(table, "Duration", mktext(circ.duration()));
1315 this._mkCircRow(table, "Barcode", mktext(copy.barcode()));
1316 this._mkCircRow(table, "Circulating Library", mktext(org));
1319 this.checkedOutBox.addItem(table);
1321 if(index < data.length - 1)
1322 this.checkedOutBox.addItem(createAppElement("hr"));
1327 MyOPACSPage.prototype._mkCircRow = function(table, title, data) {
1328 var row = table.insertRow(table.rows.length);
1329 var cell = row.insertCell(row.cells.length);
1330 cell.appendChild(mktext(title));
1331 cell = row.insertCell(row.cells.length);
1332 cell.appendChild(data);
1336 MyOPACSPage.prototype._getOrgUnit = function(org_id) {
1337 var request = new RemoteRequest(
1339 "open-ils.actor.org_unit.retrieve",
1340 this.user.getSessionId(),
1343 return request.getResultObject();
1347 var showTransactions = false;
1348 MyOPACSPage.prototype._drawFines = function() {
1349 this.drawFinesSummary();
1350 this.infoPane.appendChild(elem("hr"));
1351 this.infoPane.appendChild(elem("br"));
1352 if(showTransactions) this.drawTransactions();
1356 MyOPACSPage.prototype.drawFinesSummary = function() {
1358 var bigt = this.infoTable;
1359 var table = elem("table");
1360 bigt.insertRow(0).insertCell(0).appendChild(table);
1362 var title = table.insertRow(table.rows.length);
1363 var tcell = title.insertCell(0);
1364 tcell.setAttribute("style", "font-weight: bolder");
1365 tcell.appendChild(mktext("Fines Summary"));
1367 var torow = table.insertRow(table.rows.length);
1368 var tprow = table.insertRow(table.rows.length);
1369 var borow = table.insertRow(table.rows.length);
1371 var to = torow.insertCell(torow.cells.length);
1372 var tp = tprow.insertCell(tprow.cells.length);
1373 var bo = borow.insertCell(borow.cells.length);
1375 add_css_class(to, "my_opac_info_table_header");
1376 add_css_class(tp, "my_opac_info_table_header");
1377 add_css_class(bo, "my_opac_info_table_header");
1379 to.appendChild(mktext("Total Amount Owed"));
1380 tp.appendChild(mktext("Total Amoun Paid"));
1381 bo.appendChild(mktext("* Balance Owed"));
1383 to = torow.insertCell(torow.cells.length);
1384 tp = tprow.insertCell(tprow.cells.length);
1385 bo = borow.insertCell(borow.cells.length);
1387 add_css_class(to, "my_opac_profile_cell");
1388 add_css_class(tp, "my_opac_profile_cell");
1389 add_css_class(bo, "my_opac_profile_cell");
1391 var summary = grabUserFinesSummary(
1392 globalmyopac.user.session_id, globalmyopac.user.userObject.id());
1398 if(instanceOf(summary, mus)) {
1399 showTransactions = true;
1400 owed = _finesFormatNumber(summary.total_owed());
1401 paid = _finesFormatNumber(summary.total_paid());
1402 bowed = _finesFormatNumber(summary.balance_owed());
1405 showTransactions = false;
1406 owed = _finesFormatNumber("0.00");
1407 paid = _finesFormatNumber("0.00");
1408 bowed = _finesFormatNumber("0.00");
1411 to.appendChild(mktext(owed));
1412 tp.appendChild(mktext(paid));
1413 bo.appendChild(mktext(bowed));
1417 function _finesFormatNumber(num) {
1418 if(num.length == "1" || !num.match(/\./)) num += ".00";
1424 MyOPACSPage.prototype.drawTransactions = function() {
1425 var table = elem("table");
1426 var d = elem("div", {style:"font-weight: bolder"}, null, "Summary of Charges");
1427 this.infoPane.appendChild(d);
1428 this.infoPane.appendChild(table);
1430 var row = table.insertRow(table.rows.length);
1432 var cella = row.insertCell(row.cells.length);
1433 var cellb = row.insertCell(row.cells.length);
1434 var cellc = row.insertCell(row.cells.length);
1435 var celld = row.insertCell(row.cells.length);
1436 var celle = row.insertCell(row.cells.length);
1437 var cellf = row.insertCell(row.cells.length);
1438 var cellg = row.insertCell(row.cells.length);
1439 var cellh = row.insertCell(row.cells.length);
1441 add_css_class(cella, "my_opac_info_table_header");
1442 add_css_class(cellb, "my_opac_info_table_header");
1443 add_css_class(cellc, "my_opac_info_table_header");
1444 add_css_class(celld, "my_opac_info_table_header");
1445 add_css_class(celle, "my_opac_info_table_header");
1446 add_css_class(cellf, "my_opac_info_table_header");
1447 add_css_class(cellg, "my_opac_info_table_header");
1448 add_css_class(cellh, "my_opac_info_table_header");
1450 cella.appendChild(mktext("Transaction Start Time"));
1451 cellb.appendChild(mktext("Last Billing Time"));
1452 cellc.appendChild(mktext("Last Payment Time"));
1453 celld.appendChild(mktext("Initial Amount Owed"));
1454 celle.appendChild(mktext("Total Amount Paid"));
1455 cellf.appendChild(mktext("* Balance Owed"));
1456 cellg.appendChild(mktext("Type"));
1457 cellh.appendChild(mktext("Extra Info"));
1459 var transactions = grabUserTransactions(
1460 globalmyopac.user.session_id, globalmyopac.user.userObject.id());
1462 for( var t in transactions ) _addTransactionRow(table, transactions[t]);
1467 function _addTransactionRow(table, transaction) {
1469 var trans = transaction.transaction;
1470 var circ = transaction.circ;
1471 var record = transaction.record;
1473 var row = table.insertRow(table.rows.length);
1474 var cella = row.insertCell(row.cells.length);
1475 var cellb = row.insertCell(row.cells.length);
1476 var cellc = row.insertCell(row.cells.length);
1477 var celld = row.insertCell(row.cells.length);
1478 var celle = row.insertCell(row.cells.length);
1479 var cellf = row.insertCell(row.cells.length);
1480 var cellg = row.insertCell(row.cells.length);
1481 var cellh = row.insertCell(row.cells.length);
1483 add_css_class(cella, "my_opac_profile_cell");
1484 add_css_class(cellb, "my_opac_profile_cell");
1485 add_css_class(cellc, "my_opac_profile_cell");
1486 add_css_class(celld, "my_opac_profile_cell");
1487 add_css_class(celle, "my_opac_profile_cell");
1488 add_css_class(cellf, "my_opac_profile_cell");
1489 add_css_class(cellg, "my_opac_profile_cell");
1490 add_css_class(cellh, "my_opac_profile_cell");
1492 var owed = _finesFormatNumber(trans.total_owed());
1493 var paid = _finesFormatNumber(trans.total_paid());
1494 var bowed = _finesFormatNumber(trans.balance_owed());
1496 var stime = _trimSeconds(trans.xact_start());
1497 var last_bill = _trimSeconds(trans.last_billing_ts());
1498 var last_payment = _trimSeconds(trans.last_payment_ts());
1500 cella.appendChild(mktext(stime));
1501 cellb.appendChild(mktext(last_bill));
1502 cellc.appendChild(mktext(last_payment));
1503 celld.appendChild(mktext(owed));
1504 celle.appendChild(mktext(paid));
1505 cellf.appendChild(mktext(bowed));
1506 cellg.appendChild(mktext(trans.xact_type()));
1507 var extrainfo = "N/A";
1508 if(trans.xact_type() == "circulation")
1509 extrainfo = "Title: " + _grabTitleFromCircTransaction(trans);
1510 cellh.appendChild(mktext(extrainfo));
1515 function _grabTitleFromCircTransaction(trans) {
1516 var req = new RemoteRequest(
1518 "open-ils.circ.circ_transaction.find_title",
1519 globalmyopac.user.session_id, trans.id() );
1521 return req.getResultObject().title();
1526 function _trimSeconds(time) { if(!time) return ""; return time.replace(/\..*/,""); }
1528 function grabUserTransactions(session, usrid) {
1529 var req = new RemoteRequest(
1531 "open-ils.actor.user.transactions.have_charge.fleshed",
1534 return req.getResultObject();
1538 function grabUserFinesSummary(session, usrid) {
1539 var req = new RemoteRequest(
1541 "open-ils.actor.user.fines.summary",
1544 return req.getResultObject();