From: phasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Wed, 24 Mar 2010 19:43:49 +0000 (+0000)
Subject: Cancel with Reason for User Requests (tweaked the ML to support that), and wired... 
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=08ee3931a3204c08e00784404c7c733368102706;p=evergreen%2Fmasslnc.git

Cancel with Reason for User Requests (tweaked the ML to support that), and wired the interface into the staff client menu

Apologies for any bazaar merge metadata noise with this commit.


git-svn-id: svn://svn.open-ils.org/ILS/trunk@15959 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
index d61f720d2d..660fc63cd1 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
@@ -2558,6 +2558,13 @@ __PACKAGE__->register_method (
     method      => 'update_user_request',
     api_name    => 'open-ils.acq.user_request.cancel.batch',
     stream      => 1,
+    signature => q/
+        If given a cancel reason, will update the request with that reason, otherwise, this will delete the request altogether.  The intention 
+        is for staff interfaces or processes to provide cancel reasons, and for patron interfaces to just delete the requests.
+        @param authtoken Login session key
+        @param ids Id or array of id's for the user requests to cancel.
+        @param cancel_reason Optional Cancel Reason Id.
+    /
 );
 __PACKAGE__->register_method (
     method      => 'update_user_request',
@@ -2566,7 +2573,7 @@ __PACKAGE__->register_method (
 );
 
 sub update_user_request {
-    my($self, $conn, $auth, $aur_ids) = @_;
+    my($self, $conn, $auth, $aur_ids, $cancel_reason) = @_;
     my $e = new_editor(xact => 1, authtoken => $auth);
     return $e->die_event unless $e->checkauth;
     my $rid = $e->requestor->id;
@@ -2602,7 +2609,12 @@ sub update_user_request {
         }
 
         if($self->api_name =~ /cancel/) {
-            $e->delete_acq_user_request($aur_obj);
+            if ( $cancel_reason ) {
+                $aur_obj->cancel_reason( $cancel_reason );
+                $e->update_acq_user_request($aur_obj) or return $e->die_event;
+            } else {
+                $e->delete_acq_user_request($aur_obj);
+            }
         }
 
         $conn->respond({maximum => scalar(@$aur_ids), progress => $x++});
diff --git a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
index 8f43d7fa78..15576db920 100644
--- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
+++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
@@ -31,6 +31,7 @@
     'PO_CANCEL_CONFIRM': "Are you SURE you want to cancel this purchase order?",
     '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?",
     'CANCEL_REASON': "Cancel reason",
     'CANCEL': "Cancel",
     'YES': "Yes",
diff --git a/Open-ILS/web/js/ui/default/acq/picklist/user_request.js b/Open-ILS/web/js/ui/default/acq/picklist/user_request.js
index 6e5a6be06f..b995d37e81 100644
--- a/Open-ILS/web/js/ui/default/acq/picklist/user_request.js
+++ b/Open-ILS/web/js/ui/default/acq/picklist/user_request.js
@@ -6,18 +6,17 @@ dojo.require('openils.widget.OrgUnitFilteringSelect');
 dojo.require('openils.widget.EditPane');
 dojo.require("dijit.layout.StackContainer");
 dojo.require('openils.PermaCrud');
+dojo.requireLocalization("openils.acq", "acq");
 
 var contextOrg;
 var aur_obj;
+var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
 
 function setup() {
-
     if(reqId) {
         drawRequest();
     } else {
         drawList();
-        rGrid.cancelSelected = function() { doSelected('open-ils.acq.user_request.cancel.batch') };
-        rGrid.setNoHoldSelected = function() { doSelected('open-ils.acq.user_request.set_no_hold.batch') };
     }
 }
 
@@ -30,11 +29,11 @@ function drawRequest() {
 
     // toggle the View Picklist/Add to Picklist button label
     if (aur_obj.lineitem()) {
-        openils.Util.addCSSClass( document.getElementById('add_to_picklist'), 'hidden' );
-        openils.Util.removeCSSClass( document.getElementById('view_picklist'), 'hidden' );
+        openils.Util.show( 'add_to_picklist' );
+        openils.Util.hide( 'view_picklist' );
     } else {
-        openils.Util.addCSSClass( document.getElementById('view_picklist'), 'hidden' );
-        openils.Util.removeCSSClass( document.getElementById('add_to_picklist'), 'hidden' );
+        openils.Util.show( 'view_picklist' );
+        openils.Util.hide( 'add_to_picklist' );
     }
 
     // draw a detail page for a particular request
@@ -50,6 +49,53 @@ function drawRequest() {
 
     // including ability to add request to a picklist
     // and to "reject" it (aka apply a cancel reason)
+
+    dojo.byId("acq-ur-cancel-reason").innerHTML = '';
+    var widget = new openils.widget.AutoFieldWidget({
+        "fmField": "cancel_reason",
+        "fmClass": "aur",
+        "parentNode": dojo.byId("acq-ur-cancel-reason"),
+        "orgLimitPerms": ["CREATE_PURCHASE_REQUEST"],
+        "forceSync": true
+    });
+
+    widget.build(
+        function(w, ww) {
+            acqUrCancelReasonSubmit.onClick = function() {
+                if (w.attr("value")) {
+                    if (confirm( localeStrings.UR_CANCEL_CONFIRM )) {
+                        fieldmapper.standardRequest(
+                            [ 'open-ils.acq', 'open-ils.acq.user_request.cancel.batch' ],
+                            {   async: true,
+                                params: [openils.User.authtoken, [reqId], w.attr("value")],
+                                oncomplete: function(r) {
+                                    location.href = location.href; // kludge to reload the interface
+                                }
+                            }
+                        );
+                    }
+                }
+            };
+        }
+    );
+}
+
+function fooPicklist() {
+    if (aur_obj.lineitem()) {
+        viewPicklist();
+    } else {
+        addToPicklist();
+    }
+}
+
+function viewPicklist() {
+    var lineitem = fieldmapper.standardRequest(
+        [ 'open-ils.acq', 'open-ils.acq.lineitem.retrieve' ],
+        {
+            params: [openils.User.authtoken, aur_obj.lineitem()]
+        }
+    );
+    location.href = oilsBasePath + "/acq/picklist/view/" + lineitem.picklist();
 }
 
 function fooPicklist() {
@@ -94,19 +140,6 @@ function setNoHold() {
     );
 }
 
-function cancelRequest() {
-    // reqId, from detail view
-    fieldmapper.standardRequest(
-        [ 'open-ils.acq', 'open-ils.acq.user_request.cancel.batch' ],
-        {   async: true,
-            params: [openils.User.authtoken, [reqId]],
-            oncomplete: function(r) {
-                drawRequest();
-            }
-        }
-    );
-}
-
 // format the title data as id:title
 function getTitle(idx, item) {
     if(item) {
@@ -161,55 +194,6 @@ function buildGrid() {
     );
 }
 
-function doSelected(method) {
-    try {
-        var ids = [];
-        dojo.forEach(
-            rGrid.getSelectedItems(),
-            function(item) {
-                ids.push( rGrid.store.getValue(item,'id') );
-            }
-        );
-        fieldmapper.standardRequest(
-            [ 'open-ils.acq', method ],
-            {   async: true,
-                params: [openils.User.authtoken, ids],
-                onresponse: function(r) {
-                    try {
-                        var result = openils.Util.readResponse(r);
-                        if (typeof result.ilsevent != 'undefined') { throw(result); }
-                    } catch(E) {
-                        //dump('Error in acq/events.js, doSelected(), onresponse(): ' + E);
-                        throw(E);
-                    }
-                },
-                onerror: function(r) {
-                    try {
-                        var result = openils.Util.readResponse(r);
-                        throw(result);
-                    } catch(E) {
-                        //dump('Error in acq/events.js, doSelected(), onerror(): ' + E);
-                        throw(E);
-                    }
-                },
-                oncomplete: function(r) {
-                    try {
-                        var result = openils.Util.readResponse(r);
-                        rGrid.resetStore();
-                        buildGrid();
-                    } catch(E) {
-                        //dump('Error in acq/events.js, doSelected(), oncomplete(): ' + E);
-                        throw(E);
-                    }
-                }
-            }
-        );
-    } catch(E) {
-        //dump('Error in acq/events.js, doSelected(): ' + E);
-        throw(E);
-    }
-}
-
 openils.Util.addOnLoad(setup);
 
 
diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd
index 0d8c04b11c..2ccf8b47aa 100644
--- a/Open-ILS/web/opac/locale/en-US/lang.dtd
+++ b/Open-ILS/web/opac/locale/en-US/lang.dtd
@@ -793,6 +793,8 @@
 <!ENTITY staff.main.menu.acq.po.accesskey "P">
 <!ENTITY staff.main.menu.acq.po_events.label "Purchase Order Events">
 <!ENTITY staff.main.menu.acq.po_events.accesskey "E">
+<!ENTITY staff.main.menu.acq.user_requests.label "User Requests">
+<!ENTITY staff.main.menu.acq.user_requests.accesskey "R">
 <!ENTITY staff.main.menu.acq.fund.label "Funds">
 <!ENTITY staff.main.menu.acq.fund.accesskey "F">
 <!ENTITY staff.main.menu.acq.funding_source.label "Funding Sources">
diff --git a/Open-ILS/web/templates/default/acq/picklist/user_request.tt2 b/Open-ILS/web/templates/default/acq/picklist/user_request.tt2
index 4173297463..3a20c95b33 100644
--- a/Open-ILS/web/templates/default/acq/picklist/user_request.tt2
+++ b/Open-ILS/web/templates/default/acq/picklist/user_request.tt2
@@ -8,10 +8,6 @@
         <div dojoType="dijit.layout.ContentPane">
             <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
                 <div>[% ctx.page_title %]</div>
-                <div>
-                    <button dojoType="dijit.form.Button" onClick="rGrid.setNoHoldSelected()">Set No Hold on Selected</button>
-                    <button dojoType="dijit.form.Button" onClick="rGrid.cancelSelected()">Cancel Selected</button>
-                </div>
             </div>
             <div>
                 <span>Context Org Unit</span>
@@ -50,7 +46,18 @@
                     <button dojoType="dijit.form.Button" onClick="location.href=oilsBasePath+'/acq/picklist/user_request'">[% ctx.page_title %]</button>
                     <button dojoType="dijit.form.Button" onClick="fooPicklist()"><span id="add_to_picklist">Add to Picklist</span><span id="view_picklist">View Picklist</span></button>
                     <button dojoType="dijit.form.Button" onClick="setNoHold()">Set No Hold</button>
-                    <button dojoType="dijit.form.Button" onClick="cancelRequest()">Cancel Request with Reason</button>
+                    <span dojoType="dijit.form.DropDownButton">
+                        <span>Cancel Request</span>
+                        <span dojoType="dijit.TooltipDialog">
+                            <label for="acq-ur-cancel-reason">
+                                Reason:
+                            </label>
+                            <span id="acq-ur-cancel-reason"></span>
+                            <button jsId="acqUrCancelReasonSubmit"
+                                dojoType="dijit.form.Button"
+                                type="submit">Cancel Request</button>
+                        </span>
+                    </span>
                 </div>
             </div>
             <div id="detail_content_pane" />
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js
index 68188b27c9..8a615bb82f 100644
--- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js
+++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js
@@ -675,6 +675,10 @@ main.menu.prototype = {
                 ['oncommand'],
                 function() { open_eg_web_page('acq/po/events', 'menu.cmd_acq_view_po_events.tab'); }
             ],
+            'cmd_acq_user_requests' : [
+                ['oncommand'],
+                function() { open_eg_web_page('acq/picklist/user_request', 'menu.cmd_acq_user_requests.tab'); }
+            ],
             'cmd_acq_upload' : [
                 ['oncommand'],
                 function() { open_eg_web_page('acq/picklist/upload', 'menu.cmd_acq_upload.tab'); }
diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul
index 1fc8f1b5a7..263e26d3e4 100644
--- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul
+++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul
@@ -80,6 +80,7 @@
     <command id="cmd_acq_upload" />
     <command id="cmd_acq_view_po" />
     <command id="cmd_acq_view_po_events" />
+    <command id="cmd_acq_user_requests" />
     <command id="cmd_acq_bib_search" />
     <command id="cmd_acq_li_search" />
     <command id="cmd_acq_new_brief_record" />
@@ -259,6 +260,7 @@
         <menuseparator />
         <menuitem label="&staff.main.menu.acq.po.label;" accesskey="&staff.main.menu.acq.po.accesskey;" command="cmd_acq_view_po" />
         <menuitem label="&staff.main.menu.acq.po_events.label;" accesskey="&staff.main.menu.acq.po_events.accesskey;" command="cmd_acq_view_po_events" />
+        <menuitem label="&staff.main.menu.acq.user_requests.label;" accesskey="&staff.main.menu.acq.user_requests.accesskey;" command="cmd_acq_user_requests" />
         <menuseparator />
         <menuitem label="&staff.main.menu.acq.fund.label;" accesskey="&staff.main.menu.acq.fund.accesskey;" command="cmd_acq_view_fund" />
         <menuitem label="&staff.main.menu.acq.funding_source.label;" accesskey="&staff.main.menu.acq.funding_source.accesskey;" command="cmd_acq_view_funding_source" />
diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties
index ceddeb9620..2c41c0a81d 100644
--- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties
+++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties
@@ -227,6 +227,7 @@ menu.cmd_acq_upload.tab=Load Order Record
 menu.cmd_acq_new_brief_record.tab=New Brief Record
 menu.cmd_acq_view_po.tab=Purchase Orders
 menu.cmd_acq_view_po_events.tab=Purchase Order Events
+menu.cmd_acq_user_requests.tab=User Requests
 menu.cmd_acq_view_fund.tab=Funds
 menu.cmd_acq_view_funding_source.tab=Funding Sources
 menu.cmd_acq_view_provider.tab=Providers