context filters for acq user requests UI
authorJason Etheridge <jason@esilibrary.com>
Tue, 26 Jul 2011 13:11:07 +0000 (09:11 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 20 Sep 2011 15:32:14 +0000 (11:32 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/acq/picklist/user_request.tt2
Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/picklist/user_request.js

index 648a791..9d04a16 100644 (file)
@@ -8,20 +8,43 @@
             <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
                 <div>[% ctx.page_title %]</div>
             </div>
-            <div>
-                <span>Context Org Unit</span>
-                <select 
-                    dojoType="openils.widget.OrgUnitFilteringSelect" 
-                    jsId='contextOrgSelector'
-                    searchAttr='shortname' 
-                    labelAttr='shortname'> 
-                </select>
+            <div style="width: 100%">
+                <span>
+                    <span>Context Org Unit</span>
+                    <select 
+                        dojoType="openils.widget.OrgUnitFilteringSelect" 
+                        jsId='contextOrgSelector'
+                        searchAttr='shortname' 
+                        labelAttr='shortname'> 
+                    </select>
+                </span>
+                <span>
+                    <a name="user" href="javascript:changeUserPrompt();">User</a>
+                    <span
+                        name="user"
+                        jsId="contextUsrTextbox"
+                        dojoType="dijit.form.TextBox"
+                        disabled="true">
+                    </span>
+                </span>
+                <span>
+                    <a name="lineitem" href="javascript:changeLIPrompt();">PO Line Item</a>
+                    <span
+                        name="lineitem"
+                        jsId="contextLITextbox"
+                        dojoType="dijit.form.TextBox"
+                        disabled="true">
+                    </span>
+                </span>
+                <button dojoType="dijit.form.Button" onClick="createRequest()">Create Request</button>
             </div>
             <table  jsId="rGrid"
                     dojoType="openils.widget.AutoGrid"
                     query="{id: '*'}"
                     suppressFields='["id", "usr", "pickup_lib", "holdable_formats", "phone_notify", "email_notify", "lineitem", "eg_bib", "max_fee", "cancel_reason"]'
                     fieldOrder='["title", "author", "isxn", "article_title", "article_pages", "request_type", "volume", "pubdate", "publisher", "location", "other_info", "mentioned"]'
+                    editOnEnter='true'
+                    suppressEditFields='["id"]'
                     fmClass='aur'
                     editStyle='pane'
                     autoHeight='true'
index 395f79e..d2b69f4 100644 (file)
@@ -32,6 +32,8 @@
     "LI_CANCEL_CONFIRM" : "Are you SURE you want to cancel this line item?",
     "LID_CANCEL_CONFIRM" : "Are you SURE you want to cancel this copy?",
     "UR_CANCEL_CONFIRM" : "Are you SURE you want to cancel this user request?",
+    "UR_FILTER_USER" : "Enter barcode for user (or leave blank to unset the filter):",
+    "UR_FILTER_LINEITEM" : "Enter id for lineitem (or leave blank to unset the filter):",
     "CANCEL_REASON" : "Cancel reason",
     "CANCEL" : "Cancel",
     "YES" : "Yes",
index d3f4f63..0e67777 100644 (file)
@@ -1,3 +1,4 @@
+dojo.require('openils.CGI');
 dojo.require('openils.Util');
 dojo.require('openils.User');
 dojo.require('openils.widget.AutoGrid');
@@ -7,12 +8,43 @@ dojo.require('openils.widget.EditPane');
 dojo.require("dijit.layout.StackContainer");
 dojo.require('openils.PermaCrud');
 dojo.requireLocalization("openils.acq", "acq");
+dojo.require('openils.acq.Lineitem');
 
 var contextOrg;
+var contextUsr;
+var contextLI;
+var contextEg_bib;
 var aur_obj;
 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
+var cgi = new openils.CGI();
 
 function setup() {
+
+    if (cgi.param('eg_bib')) {
+        changeBib(cgi.param('eg_bib'));
+    }
+
+    if (cgi.param('lineitem')) {
+        changeLI(cgi.param('lineitem'));
+    }
+
+    if (cgi.param('usr')) {
+        var usr_obj = fieldmapper.standardRequest(
+            [
+                'open-ils.actor',
+                'open-ils.actor.user.fleshed.retrieve.authoritative'
+            ],
+            {
+                params: [openils.User.authtoken, cgi.param('usr')]
+            }
+        );
+        if (typeof usr_obj.textcode == 'undefined') {
+            changeUser(usr_obj.id(),usr_obj.card().barcode());
+        } else {
+            alert(usr_obj.textcode + ' : ' + usr_obj.desc);
+        }
+    }
+
     if(reqId) {
         drawRequest();
     } else {
@@ -27,6 +59,15 @@ function drawRequest() {
     // hide the grid and the context selector
     dijit.byId('stackContainer').forward();
 
+    // purge any previous lineitem display
+    // FIXME: I thought it would be cool to have this, but I can't get it 
+    // to look right with our dojo div/contentPanes.  So just testing for
+    // a DOM hook for now.
+    if (dojo.byId('lineitem')) {
+        //openils.Util.hide( 'lineitem_container' );
+        dojo.byId('lineitem').innerHTML = '';
+    }
+
     // toggle the View Picklist/Add to Picklist button label
     if (aur_obj.lineitem()) {
         openils.Util.hide( 'add_to_picklist' );
@@ -47,6 +88,16 @@ function drawRequest() {
     pane.hideActionButtons = true;
     pane.startup();
 
+    // lineitem summary
+    if (dojo.byId('lineitem') && aur_obj.lineitem()) {
+        //openils.Util.show( 'lineitem_container' );
+        openils.acq.Lineitem.fetchAndRender(aur_obj.lineitem(), {},
+            function(li, html) {
+                dojo.byId('lineitem').innerHTML = html;
+            }
+        );
+    }
+
     // including ability to add request to a picklist
     // and to "reject" it (aka apply a cancel reason)
 
@@ -162,18 +213,106 @@ function buildGrid() {
     if(contextOrg == null)
         contextOrg = openils.User.user.ws_ou();
 
+    var query = {
+        cancel_reason : null,
+        '+au' : {
+            home_ou : fieldmapper.aou.descendantNodeList(contextOrg).map(
+            function(item) { return item.id(); })
+        }
+    };
+
+    if (contextUsr) {
+        delete query['+au']['home_ou'];
+        query['+au']['id'] = contextUsr;
+    }
+
+    if (contextEg_bib) {
+        query['eg_bib'] = contextEg_bib;
+    }
+
+    if (contextLI) {
+        query['lineitem'] = contextLI;
+    }
+
+    rGrid.resetStore();
     rGrid.loadAll(
         {   order_by : {aur : 'request_date'},
             join : 'au' 
         },
-        {
-            cancel_reason : null,
-            '+au' : {
-                home_ou : fieldmapper.aou.descendantNodeList(contextOrg).map(
-                    function(item) { return item.id(); })
+        query
+    );
+}
+
+function changeBib(value) {
+    contextEg_bib = value;
+    rGrid.overrideEditWidgets.eg_bib = new dijit.form.TextBox({"disabled": true});
+    rGrid.overrideEditWidgets.eg_bib.shove = { create : contextEg_bib };
+}
+
+function changeLI(value,display_value) {
+    contextLI = value;
+    contextLITextbox.setValue( contextLI );
+    contextLITextbox.setDisplayedValue( display_value || contextLI );
+    rGrid.overrideEditWidgets.lineitem = new dijit.form.TextBox({"disabled": true});
+    rGrid.overrideEditWidgets.lineitem.shove = { create : contextLI };
+}
+
+function changeLIPrompt() {
+    var lineitem = window.prompt(localeStrings.UR_FILTER_LINEITEM);
+    if(lineitem != '' && (lineitem == null || Number(lineitem) == NaN)) {
+        return;
+    }
+    changeLI(lineitem);
+    buildGrid();
+}
+
+function changeUser(value,display_value) {
+    contextUsr = value;
+    contextUsrTextbox.setValue( contextUsr );
+    contextUsrTextbox.setDisplayedValue( display_value || contextUsr );
+    rGrid.overrideEditWidgets.usr = new dijit.form.TextBox({"disabled": true});
+    rGrid.overrideEditWidgets.usr.shove = { create : contextUsr };
+}
+
+function changeUserPrompt() {
+    var barcode = window.prompt(localeStrings.UR_FILTER_USER);
+    if(barcode == null) {
+        return;
+    }
+    if(typeof xulG != 'undefined' && xulG.get_barcode) {
+        // We have a "complete the barcode" function, call it (actor = users only)
+        var new_barcode = xulG.get_barcode(window, 'actor', barcode);
+        // If we got a result (boolean false is "no result") check it
+        if(new_barcode) {
+            // user_false string means they picked "None of the above"
+            // Abort before any other events can fire
+            if(new_barcode == "user_false") return;
+            // No error means we have a (hopefully valid) completed barcode to use.
+            // Otherwise, fall through to other methods of checking
+            if(typeof new_barcode.ilsevent == 'undefined')
+                barcode = new_barcode.barcode;
+        }
+    }
+    if (barcode == '') {
+        changeUser('','');
+    } else {
+        var usr_obj = fieldmapper.standardRequest(
+            [
+                'open-ils.actor',
+                'open-ils.actor.user.fleshed.retrieve_by_barcode.authoritative'
+            ],
+            {
+                params: [openils.User.authtoken, barcode]
             }
+        );
+        if (typeof usr_obj.textcode != 'undefined') {
+            alert(usr_obj.textcode + ' : ' + usr_obj.desc);
+            return;
+        } else {
+            changeUser(usr_obj.id(),usr_obj.card().barcode());
         }
-    );
+    }
+    buildGrid();
 }
 
 openils.Util.addOnLoad(setup);