more holds work
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Jun 2005 21:45:07 +0000 (21:45 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 29 Jun 2005 21:45:07 +0000 (21:45 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@981 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/opac/AbstractRecordResultPage.js
Open-ILS/src/javascript/opac/GlobalInit.js
Open-ILS/src/javascript/opac/HoldsWindow.js
Open-ILS/src/javascript/opac/RecordDetailPage.js
Open-ILS/src/javascript/util/ils_utils.js
Open-ILS/src/javascript/util/webutils.js

index a7693ba..20f40c1 100644 (file)
@@ -288,14 +288,13 @@ AbstractRecordResultPage.prototype.displayRecord =
                if(record.edition())
                        span.appendChild(createAppTextNode(" " + record.edition()));
 
-                       author_cell.appendChild(span);
+               author_cell.appendChild(span);
 
                var marcb = elem( "a",
                        {
                                href:"javascript:void(0)",
                                style: "text-decoration:underline"
-                       },
-                       {}, "View MARC" );
+                       }, {}, "View MARC" );
 
                debug("Setting up view marc callback with record " + record.doc_id());
                var func = buildViewMARCWindow(record);
@@ -310,8 +309,44 @@ AbstractRecordResultPage.prototype.displayRecord =
 
        }
 
+       var holds = elem( "a", 
+       { 
+               href:"javascript:void(0)", 
+               style: "text-decoration:underline" 
+       }, {}, "Place Hold" );
+
+       var user = UserSession.instance();
+
+       /*
+       if(!(user && user.verifySession()))  
+               return;
+               */
+       
+       var type = "M";
+       if(instanceOf(this, RecordResultPage))
+               type = "T";
+
+       var win = new HoldsWindow(record.doc_id(), 
+                       type, user.userObject, user.userObject, user.session_id);
+
+       win.buildWindow(); 
+       holds.onclick = function() { win.toggle(); }
+       var holddiv = elem("div");
+
+       //if(instanceOf(this,RecordResultPage))
+       holddiv.setAttribute("style", "float:right");
+
+       holddiv.appendChild(holds);
+       //var space = elem("span", {style:"padding:5px"},null, " ");
+       //c.appendChild(space)
+       c.appendChild(mktext(" "))
+       c.appendChild(holddiv)
+
+
+
+
        var classname = "result_even";
-       if((page_id%2) != 0) 
+       if((page_id % 2) != 0) 
                classname = "result_odd";
 
        add_css_class(title_row, classname);
index 022127a..aca1dfd 100644 (file)
@@ -193,11 +193,15 @@ function grabCopyStatus() {
                "open-ils.search",
                "open-ils.search.config.copy_status.retrieve.all" );
 
-       if(paramObj.__sub_frame) {
-               /* we have to grab the copy statuses synchronously */
+
+       //if(paramObj.__sub_frame) {
                req.send(true);
-               globalCopyStatus = r.getResultObject();
+               globalCopyStatus = req.getResultObject();
+               if(!globalCopyStatus) {
+                       userMessage("Retrieving copy statuses");
+               }
 
+               /*
        } else {
 
                req.setCompleteCallback(function(r) { 
@@ -206,6 +210,7 @@ function grabCopyStatus() {
        
                req.send();
        }
+       */
 }
 
 
index 8e52890..e7082db 100644 (file)
@@ -1,7 +1,144 @@
-function HoldsWindow(record) {
+var resourceFormats = [ 
+       "text", 
+       "moving image",
+       "sound recording",
+       "software, multimedia",
+       "still images",
+       "cartographic",
+       "mixed material",
+       "notated music",
+       "three dimensional object" ];
+
+
+/* 
+       @param record the id of the target item 
+       @param type is the hold level (M, T, V, C) for metarecord, title,
+               volume, and copy respectively.
+       @param requestor is the user object (fieldmapper) for the requestor
+       @param recipient is the user object (fieldmapper) for the hold recipient
+               role in the holds process 
+       @param requestor_login is the login session of the hold requestor
+       */
+function HoldsWindow(record, type, requestor, recipient, requestor_login) {
+
        this.record = record;
+       this.div = elem("div");
+       this.requestor = requestor;
+       this.recipient  = recipient;
+       this.type = type;
+       this.session = requestor_login;
+
+       add_css_class(this.div, "holds_window");
+       add_css_class(this.div, "hide_me");
+       getDocument().body.appendChild(this.div);
+}
+
+
+HoldsWindow.prototype.process = function() {
+
+       /* collect the checked items */
+       var formats = "";
+       if(this.type == "M") {
+               for(var idx in resourceFormats) {
+                       var form = resourceFormats[idx];
+                       var item = getById( form + "_hold_checkbox");
+                       if(item.checked) {
+                               formats += modsFormatToMARC(form);
+                       }
+               }
+               
+               if(formats.length == 0) {
+                       alert("Please select at least one item format");
+                       this.toggle();
+               }
+       } 
+
+       var sel = getById("holds_org_selector");
+       var orgNode = sel.options[sel.selectedIndex];
+       var org = findOrgUnit(orgNode.value);
+
+       /* for now... */
+       var email = this.recipient.email();
+       var phone = this.recipient.day_phone();
+
+       this.sendHoldsRequest(formats, org, email, phone);
+}
+
+/* formats is a string of format characters, org is the 
+       org unit used for delivery */
+HoldsWindow.prototype.sendHoldsRequest = function(formats, org, email, phone) {
+       var hold = new ahr();
+       hold.pickup_lib(org.id());
+       hold.requestor(this.requestor.id());
+       hold.usr(this.recipient.id());
+       hold.hold_type(this.type);
+       hold.email_notify(email);
+       hold.phone_notify(phone);
+       if(this.type == "M") hold.holdable_formats(formats);
+       hold.target(this.record);
+
+       var req = new RemoteRequest(
+               "open-ils.circ",
+               "open-ils.circ.holds.create",
+               this.session, hold );
+
+       req.send(true);
+       var res = req.getResultObject();
+       if(res == 1) 
+               alert("Hold request was succesfully submitted");
+
+}
+
+HoldsWindow.prototype.buildWindow = function() {
+
+       var d = elem("div");
+       var id = this.record;
+
+       var usr = this.recipient;
+       if(!usr) return;
+       var org = usr.home_ou();
+       d.appendChild(this.buildPickuplibSelector(org));
+
+       if(this.type == "M")
+               d.appendChild(this.buildResourceSelector());
+       d.appendChild(this.buildSubmit());
+
+       this.div.appendChild(d);
+}
+
+HoldsWindow.prototype.toggle = function() {
+       swapClass( this.div, "hide_me", "show_me" );
+
+
+       /* workaround for IE select box widget bleed through, blegh... */
+       if(IE) {
+
+               var sels = getDocument().getElementsByTagName("select");
+               if(sels.length == 0) return;
+
+               if(this.div.className.indexOf("hide_me") != -1)  {
+                       for(var i = 0; i!= sels.length; i++) {
+                               var s = sels[i];
+                               if(s && s.id != "holds_org_selector") {
+                                       remove_css_class(s, "invisible");
+                                       add_css_class(s, "visible");
+                               }
+                       }
+               }
+       
+               if(this.div.className.indexOf("show_me") != -1)  {
+                       for(var i = 0; i!= sels.length; i++) {
+                               var s = sels[i];
+                               if(s && s.id != "holds_org_selector") {
+                                       remove_css_class(s, "visible");
+                                       add_css_class(s, "invisible");
+                               }
+                       }
+               }
+       }
 }
 
+/*
 HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
 
        var hwindow = this;
@@ -20,7 +157,6 @@ HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
                        "location=0,menubar=0,status=0,resizeable,resize," +
                        "outerHeight=500,outerWidth=500,height=500," +
                        "width=500,scrollbars=1," +
-                       /*"screenX=100,screenY=100,top=100,left=100," + */
                        "alwaysraised, chrome" )
        
                hwindow.win.document.write("<html>" + wrapper.innerHTML + "</html>");
@@ -31,20 +167,35 @@ HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
 
        return func;
 }
+*/
 
 HoldsWindow.prototype.buildSubmit = function() {
        var div = elem("div");
-       var bdiv = elem("div")
 
-       bdiv.setAttribute("style", 
-               "border-top: 1px solid lightgrey;" +
-               "border-bottom: 1px solid lightgrey;" +
-               "width:100%;text-align:center;");
+
+       /*
+       var bdiv = elem("div",  
+                       {style: 
+                               "border-top: 1px solid lightgrey;" +
+                               "border-bottom: 1px solid lightgrey;" +
+                               "width:100%;text-align:center;"});
+                               */
+
+       var bdiv = elem("div");  
+       add_css_class(bdiv, "holds_window_buttons");
 
        var button = elem("input", 
-               {type:"submit", value:"Place Hold"});
+               {type:"submit", style:"margin-left: 10px;", value:"Place Hold"});
+
+       var cancel = elem("input", 
+               {type:"submit", style:"margin-right: 10px;",value:"Cancel"});
+       var obj = this;
+
+       cancel.onclick = function() { obj.toggle(); }
+       button.onclick = function() { obj.toggle(); obj.process(); }
 
        div.appendChild(elem("br"));
+       bdiv.appendChild(cancel);
        bdiv.appendChild(button);
        div.appendChild(bdiv);
 
@@ -56,15 +207,14 @@ HoldsWindow.prototype.buildSubmit = function() {
 HoldsWindow.prototype.buildPickuplibSelector = function(selected_id) {
 
        var div = elem("div");
-       var tdiv = elem("div",null, null,
-               "Select the location where the item(s) shall be delivered");
+       var tdiv = elem("div",{style:"margin-left:10px"}, null,
+               "1. Select the location where the item(s) shall be delivered");
 
        var sdiv = elem("div");
-       var selector = elem("select");
+       var selector = elem("select",{id:"holds_org_selector"});
 
        /* this is not copied over... XXX fix me */
        selector.onchange = function() {
-               alert("Change!");
                var idx = selector.selectedIndex;
                var option = selector.options[idx];
                var org = findOrgUnit(option.value);
@@ -73,21 +223,22 @@ HoldsWindow.prototype.buildPickuplibSelector = function(selected_id) {
                if(d) div.removeChild(d);
 
                if(parseInt(findOrgType(org.ou_type()).depth()) < 2) {
-                       alert("A REGION was selected");
                        var err = elem("div",
                                {id:"selector_error_div", style:"color:red"},null, 
                                org.name() + " is a library system, please select a single branch");
                        div.appendChild(err);
                } else {
-                       alert("Depth is " + findOrgType(org.ou_type()).depth());
                }
        }
 
-       sdiv.appendChild(selector);
+       var center = elem("center");
+       center.appendChild(selector);
+       sdiv.appendChild(center);
        _buildOrgList(selector, selected_id, null);
 
        div.appendChild(elem("br"));
        div.appendChild(tdiv);
+       div.appendChild(elem("br"));
        div.appendChild(sdiv);
        return div;
 }
@@ -132,46 +283,37 @@ function _buildOrgList(selector, selected_id, org) {
 HoldsWindow.prototype.buildResourceSelector = function() {
 
        /* useful message */
-       var big_div = elem('div');
+       var big_div = elem('div', {style:"margin-left: 10px;"});
 
        var desc_div = elem("div",null, null, 
-               "Select all acceptible item formats");
-
-       var resources = [ 
-               "text", 
-               "moving image",
-               "sound recording",
-               "software, multimedia",
-               "still images",
-               "cartographic",
-               "mixed material",
-               "notated music",
-               "three dimensional object" ];
+               "2. Select all acceptible item formats");
+
        
        var table = elem("table");      
 
-       for( var idx in resources ) {
+       for( var idx in resourceFormats ) {
                var row = table.insertRow(table.rows.length)
        
                var pic_cell = row.insertCell(0);
                var name_cell = row.insertCell(1);
                var box_cell = row.insertCell(2);
                var box = elem("input", 
-                       {type:"checkbox", id: resources[idx] + "_hold_checkbox"}, null);
+                       {type:"checkbox", id: resourceFormats[idx] + "_hold_checkbox"}, null);
 
                if(idx == 0) { /* select text by default */
                        box.setAttribute("checked","checked");
                        box.checked = true;
                }
                
-               pic_cell.appendChild(mkResourceImage(resources[idx]));
-               name_cell.appendChild(mktext(resources[idx]));
+               pic_cell.appendChild(mkResourceImage(resourceFormats[idx]));
+               name_cell.appendChild(mktext(resourceFormats[idx]));
                box_cell.appendChild(mktext(" "));
                box_cell.appendChild(box);
        }
 
        big_div.appendChild(elem("br"));
        big_div.appendChild(desc_div);
+       big_div.appendChild(elem("br"));
        big_div.appendChild(table);
        return big_div;
 
index 90c33f5..7138b22 100644 (file)
@@ -224,6 +224,7 @@ RecordDetailPage.prototype.setViewMarc = function(record) {
                {}, "View MARC" );
 
        debug(".ou_type()Setting up view marc callback with record " + record.doc_id());
+
        var func = buildViewMARCWindow(record);
        marcb.onclick = func;
        this.viewMarc.appendChild(marcb);
@@ -237,8 +238,14 @@ RecordDetailPage.prototype.setPlaceHold = function(record) {
                }, 
                {}, "Place Hold" );
 
-       var func = new HoldsWindow(record).buildHoldsWindowCallback("M");
-       holds.onclick = func;
+       var user = UserSession.instance();
+       if(!(user && user.verifySession()))  /* needs to pop up a login dialog XXX */
+               return;
+
+       var win = new HoldsWindow(record.doc_id(), 
+                       "T", user.userObject, user.userObject, user.session_id);
+       win.buildWindow(); 
+       holds.onclick = function() { win.toggle(); }
 
        var space = elem("span", {style:"padding:5px"},null, " ");
        this.viewMarc.appendChild(space);
@@ -475,6 +482,8 @@ RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
        
        debug("Displaying copy tree for " + title);
 
+       if(!globalCopyStatus) grabCopyStatus(); /* just to be safe */
+
        var treeDiv =  this.treeDiv;
        removeChildren(treeDiv);
        add_css_class( treeDiv, "copy_tree_div" );
@@ -572,9 +581,12 @@ RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
                                cell4.appendChild(createAppTextNode(loc));
 
                                removeChildren(cell5);
-                               cell5.appendChild(createAppTextNode(
-                                       find_list(globalCopyStatus, 
-                                               function(i) {return (i.id() == copy.status());} ).name() ));
+                               var status = find_list(globalCopyStatus, 
+                                               function(i) { return (i.id() == copy.status());} );
+
+                               var sname = "";
+                               if(status) sname = status.name();
+                               cell5.appendChild(createAppTextNode(sname));
 
                        } else {
 
@@ -594,9 +606,11 @@ RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
                                ce.appendChild(createAppTextNode(copy.barcode()));
                                loc_cell.appendChild(createAppTextNode(loc));
 
-                               status_cell.appendChild(createAppTextNode(
-                                       find_list(globalCopyStatus, 
-                                               function(i) { return (i.id() == copy.status()); } ).name() ));
+                               var status = find_list(globalCopyStatus, 
+                                               function(i) { return (i.id() == copy.status());} );
+                               var sname = "";
+                               if(status) sname = status.name();
+                               status_cell.appendChild(mktext(sname))
                        }
 
                        c++;
index 887faa2..8d55e1e 100644 (file)
@@ -59,7 +59,6 @@ function findOrgUnit(org_id, branch) {
 }
 
 
-
 function getOrgById(id, node) {
        if(node == null) node = globalOrgTree;
        if( node.id() == id) return node;
@@ -119,3 +118,28 @@ function findCopyLocation(id) {
 }
 
 
+function modsFormatToMARC(format) {
+       switch(format) {
+               case "text":
+                       return "at";
+               case "moving image":
+                       return "g";
+               case "sound recording":
+                       return "ij";
+               case "software, multimedia":
+                       return "m";
+               case "still images":
+                       return "k";
+               case "cartographic":
+                       return "ef";
+               case "mixed material":
+                       return "op";
+               case "notated muix":
+                       return "cd";
+               case "three dimensional object":
+                       return "r";
+       }
+       throw new EXLogic("Invalid format provided form modsFormatToMARC: " + format);
+}
+
+
index be2ce5c..512ca15 100644 (file)
@@ -696,3 +696,9 @@ function removeChildren(node) {
                        node.removeChild(node.childNodes[0]);
        }
 }
+
+
+
+function userMessage(msg) {
+       alert("An unknown error occured during the following process: " + msg);
+}