[open-ils-commits] r19095 - in branches/rel_2_0/Open-ILS: src/perlmods/OpenILS/Application/Acq web/js/dojo/openils/acq/nls web/js/ui/default/acq/common web/templates/default/acq/common (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jan 4 09:51:23 EST 2011


Author: senator
Date: 2011-01-04 09:51:21 -0500 (Tue, 04 Jan 2011)
New Revision: 19095

Modified:
   branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Claims.pm
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
   branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/claim_dialog.js
   branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/li_table.js
   branches/rel_2_0/Open-ILS/web/templates/default/acq/common/claim_dialog.tt2
Log:
Acq: backport r19040 and r19094 from trunk

[19040] Acq: support manual claiming as always intended, which to some users
means claiming with no predefined policy

[19094] Acq: Make manual lineitem claiming work better. When a claiming policy
has not been applied, users can now choose claim actions manually (this is what
a claiming policy would have specified).



Modified: branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Claims.pm
===================================================================
--- branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Claims.pm	2011-01-04 14:40:23 UTC (rev 19094)
+++ branches/rel_2_0/Open-ILS/src/perlmods/OpenILS/Application/Acq/Claims.pm	2011-01-04 14:51:21 UTC (rev 19095)
@@ -123,6 +123,13 @@
                 /, 
                 type => 'array'
             },
+            {   desc => q/
+                    Optional: Claim Event Types.  If present, we bypass any policy configuration
+                    and use the specified event types.  This is useful for manual claiming against
+                    items that have no claim policy.
+                /,
+                type => 'array'
+            }
         ],
         return => {
             desc => "The claim voucher events on success, Event on error",
@@ -140,8 +147,10 @@
     my $claim_type_id = shift;
     my $note = shift;
     my $policy_actions = shift;
-#   my $only_eligible = shift; # so far unused
 
+    # if this claim occurs outside of a policy, allow the caller to specificy the event type
+    my $claim_event_types = shift; 
+
     my $e = new_editor(xact => 1, authtoken=>$auth);
     return $e->die_event unless $e->checkauth;
 
@@ -169,32 +178,28 @@
         return OpenILS::Event->new('BAD_PARAMS');
     }
 
+
+    my $lids;
     if($self->api_name =~ /claim.lineitem_detail/) {
-        my $lids = $e->search_acq_lineitem_detail([
+
+        $lids = $e->search_acq_lineitem_detail([
             {"id" => $object_id, "cancel_reason" => undef},
             $lid_flesh
         ]) or return $e->die_event;
-        foreach my $lid (@$lids) {
-            return $evt if
-                $evt = claim_lineitem_detail(
-                    $e, $lid, $claim, $claim_type, $policy_actions,
-                    $note, $claim_events
-                );
-        }
 
     } elsif($self->api_name =~ /claim.lineitem/) {
-        my $lids = $e->search_acq_lineitem_detail([
+        $lids = $e->search_acq_lineitem_detail([
             {"lineitem" => $object_id, "cancel_reason" => undef},
             $lid_flesh
         ]) or return $e->die_event;
+    }
 
-        foreach my $lid (@$lids) {
-            return $evt if
-                $evt = claim_lineitem_detail(
-                    $e, $lid, $claim, $claim_type, $policy_actions,
-                    $note, $claim_events
-                );
-        }
+    foreach my $lid (@$lids) {
+        return $evt if
+            $evt = claim_lineitem_detail(
+                $e, $lid, $claim, $claim_type, $policy_actions,
+                $note, $claim_events, $claim_event_types
+            );
     }
 
     $e->commit;
@@ -210,7 +215,7 @@
 }
 
 sub claim_lineitem_detail {
-    my($e, $lid, $claim, $claim_type, $policy_actions, $note, $claim_events) = @_;
+    my($e, $lid, $claim, $claim_type, $policy_actions, $note, $claim_events, $claim_event_types) = @_;
 
     # Create the claim object
     unless($claim) {
@@ -220,23 +225,35 @@
         $e->create_acq_claim($claim) or return $e->die_event;
     }
 
-    # find all eligible policy actions if none are provided
-    unless($policy_actions) {
-        my $list = $e->json_query({
-            select => {acrlid => ['claim_policy_action']},
-            from => 'acrlid',
-            where => {lineitem_detail => $lid->id}
-        });
+    unless($claim_event_types) {
+        # user did not specify explicit event types
 
-        $policy_actions = [map { $_->{claim_policy_action} } @$list];
+        unless($policy_actions) {
+            # user did not specifcy policy actions.  find all eligible.
+
+            my $list = $e->json_query({
+                select => {acrlid => ['claim_policy_action']},
+                from => 'acrlid',
+                where => {lineitem_detail => $lid->id}
+            });
+    
+            $policy_actions = [map { $_->{claim_policy_action} } @$list];
+        }
+
+        # from the set of policy_action's, locate the related event types
+        # IOW, the policy action's action
+        $claim_event_types = [];
+        for my $act_id (@$policy_actions) {
+            my $action = $e->retrieve_acq_claim_policy_action($act_id) or return $e->die_event;
+            push(@$claim_event_types, $action->action);
+        }
     }
 
     # for each eligible (or chosen) policy actions, create a claim_event
-    for my $act_id (@$policy_actions) {
-        my $action = $e->retrieve_acq_claim_policy_action($act_id) or return $e->die_event;
+    for my $event_type (@$claim_event_types) {
         my $event = Fieldmapper::acq::claim_event->new;
         $event->claim($claim->id);
-        $event->type($action->action);
+        $event->type($event_type);
         $event->creator($e->requestor->id);
         $event->note($note);
         $e->create_acq_claim_event($event) or return $e->die_event;

Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2011-01-04 14:40:23 UTC (rev 19094)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2011-01-04 14:51:21 UTC (rev 19095)
@@ -76,5 +76,6 @@
     "INVOICES" : "Invoices",
     "NUM_CLAIMS_EXISTING" : "Claims (${0} existing)",
     "LOAD_TERMS_FIRST" : "You can't retrieve records until you've loaded a CSV file\nwith bibliographic IDs in the first column.",
-    "SELECT_SEARCH_FIELD": "Select Search Field"
+    "SELECT_SEARCH_FIELD": "Select Search Field",
+    "LIBRARY_INITIATED": "Library Initiated"
 }

Modified: branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/claim_dialog.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/claim_dialog.js	2011-01-04 14:40:23 UTC (rev 19094)
+++ branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/claim_dialog.js	2011-01-04 14:51:21 UTC (rev 19095)
@@ -26,6 +26,11 @@
         nodeByName("lid_to_claim", this.eligibleList)
     );
 
+    var acqclet_template_parent = dojo.byId("acqclet-tbody");
+    this.eventTypeTemplate = acqclet_template_parent.removeChild(
+        nodeByName("acqclet-template", acqclet_template_parent)
+    );
+
     dojo.byId("acq-lit-li-claim-dia-claim").onclick = function() {
         var lid_ids = self.getSelectedEligible();
         if (lid_ids.length) {
@@ -55,7 +60,9 @@
 
         openils.Util.hide("acq-lit-li-claim-dia-initiate");
         openils.Util.hide("acq-lit-li-claim-dia-show");
+        openils.Util.hide("acqclet-display");
 
+        dojo.empty("acqclet-tbody");
         dojo.empty(this.showingList);
         dojo.empty(this.eligibleList);
     };
@@ -87,8 +94,64 @@
                 }
             }
         );
+
+        if (!li.claim_policy())
+            this.showClaimEventTypes();
     };
 
+    this.showClaimEventTypes = function() {
+        if (!this._cached_event_types) {
+            this._cached_event_types = new openils.PermaCrud({
+                "authtoken": openils.User.authtoken
+            }).retrieveAll(
+                "acqclet", {"order_by": {"acqclet": "code"}}
+            );
+        }
+
+        if (this._cached_event_types && this._cached_event_types.length) {
+            openils.Util.show("acqclet-display");
+            dojo.empty("acqclet-tbody");
+            this._cached_event_types.forEach(
+                function(clet) { self._render_event_type_row(clet); }
+            );
+        }
+    };
+
+    this.selectedEventTypes = function() {
+        var selected = dojo.query("[id^='acqclet-checkbox-']").filter(
+            function(node) {
+                return dojo.attr(node, "checked");
+            }
+        ).map(
+            function(node) {
+                return dojo.attr(node, "id").match(/-(\d+)$/)[1];
+            }
+        );
+
+        return selected.length ? selected : null;
+    };
+
+    this._render_event_type_row = function(clet) {
+        var row = dojo.clone(this.eventTypeTemplate);
+
+        var checkbox = nodeByName("acqclet-checkbox", row);
+        var label = nodeByName("acqclet-label", row);
+
+        var checkbox_id = "acqclet-checkbox-" + clet.id();
+        dojo.attr(checkbox, "id", checkbox_id);
+        dojo.attr(label, "for", checkbox_id);
+
+        label.innerHTML = dojo.string.substitute(label.innerHTML, {
+            "description": clet.description(),
+            "code": clet.code(),
+            "library_initiated": clet.library_initiated() ?
+                localeStrings.LIBRARY_INITIATED : "",
+            "ou": aou.findOrgUnit(clet.org_unit()).shortname()
+        });
+
+        dojo.place(row, "acqclet-tbody");
+    };
+
     this._reprReceived = function(lid) {
         if (lid.cancel_reason())
             return localeStrings.CANCELED + ": " + lid.cancel_reason().label();
@@ -172,32 +235,30 @@
 
     this.claim = function(lid_ids) {
         progressDialog.show(true);
-        var win = null;
 
         fieldmapper.standardRequest(
-            ["open-ils.acq", "open-ils.acq.claim.lineitem_detail"], {
+            ["open-ils.acq", "open-ils.acq.claim.lineitem_detail.atomic"], {
                 "params": [
                     openils.User.authtoken, lid_ids, null,
                     this.claimType.attr("value"),
-                    dijit.byId("acq-eligible-claim-note").attr("value")
+                    dijit.byId("acq-eligible-claim-note").attr("value"),
+                    null,
+                    this.selectedEventTypes()
                 ],
                 "async": true,
                 "onresponse": function(r) {
                     if (r = openils.Util.readResponse(r)) {
-                        if (!win)
-                            win = openClaimVoucherWindow();
-                        dojo.byId("main", win.document).innerHTML +=
-                            (r.template_output().data() + "<hr />");
+                        if (r.length) {
+                            openils.Util.printHtmlString(
+                                r.map(
+                                    function(o) {
+                                        return o.template_output().data();
+                                    }
+                                ).join("<hr />")
+                            );
+                        }
                     }
-                    else {
-                        progressDialog.hide();
-                    }
-                },
-                "oncomplete": function() {
                     progressDialog.hide();
-                    dojo.byId("print", win.document).innerHTML =
-                        localeStrings.PRINT;
-                    dojo.byId("print", win.document).disabled = false;
                     self.claimCallback(self.workingLi);
                 }
             }

Modified: branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/li_table.js	2011-01-04 14:40:23 UTC (rev 19094)
+++ branches/rel_2_0/Open-ILS/web/js/ui/default/acq/common/li_table.js	2011-01-04 14:51:21 UTC (rev 19095)
@@ -228,6 +228,7 @@
                         [li], self.claimPolicyPicker.attr("value"),
                         function() {
                             self.setClaimPolicyControl(li, row);
+                            self.reconsiderClaimControl(li, row);
                             liClaimPolicyDialog.hide();
                         }
                     );
@@ -291,12 +292,15 @@
         dojo.query('[name=noteslink]', row)[0].onclick = function() {self.drawLiNotes(li)};
 
         if (!this.skipInitialEligibilityCheck)
-            this.fetchClaimInfo(li.id(), false, null, row);
+            this.fetchClaimInfo(
+                li.id(),
+                false,
+                function(full) { self.setClaimPolicyControl(full, row) },
+                row
+            );
 
         this.updateLiNotesCount(li, row);
 
-        this.setClaimPolicyControl(li, row);
-
         // show which PO this lineitem is a member of
         if(li.purchase_order() && !this.isPO) {
             var po = 
@@ -376,10 +380,10 @@
     };
 
     this.reconsiderClaimControl = function(li, row) {
+        if (!row) row = this._findLiRow(li);
         var option = nodeByName("action_manage_claims", row);
         var eligible = this.claimEligibleLidByLi[li.id()].length;
         var count = this._liCountClaims(li);
-        if (!row) row = this._findLiRow(li);
 
         option.disabled = !(count || eligible);
         option.innerHTML =
@@ -409,7 +413,20 @@
     };
 
     this.checkClaimEligibility = function(li, callback, row) {
+        /* Assume always eligible, i.e. from this interface we don't care about
+         * claim eligibility any more. this is where the user would force a
+         * claime. */
         this.clearEligibility(li);
+        this.claimEligibleLidByLi[li.id()] = li.lineitem_details().map(
+            function(lid) { return lid.id(); }
+        );
+        li.lineitem_details().forEach(
+            function(lid) { self.claimEligibleLid[lid.id()] = true; }
+        );
+        this.reconsiderClaimControl(li, row);
+        if (callback) callback(li);
+        /*
+        this.clearEligibility(li);
         fieldmapper.standardRequest(
             ["open-ils.acq", "open-ils.acq.claim.eligible.lineitem_detail"], {
                 "params": [openils.User.authtoken, {"lineitem": li.id()}],
@@ -429,6 +446,7 @@
                 }
             }
         );
+        */
     };
 
     this.updateLiNotesCount = function(li, row) {
@@ -1912,7 +1930,10 @@
                         self.claimPolicyPicker.attr("value"),
                         function() {
                             li_list.forEach(
-                                function(li) { self.setClaimPolicyControl(li); }
+                                function(li) {
+                                    self.setClaimPolicyControl(li);
+                                    self.reconsiderClaimControl(li);
+                                }
                             );
                             liClaimPolicyDialog.hide();
                         }

Modified: branches/rel_2_0/Open-ILS/web/templates/default/acq/common/claim_dialog.tt2
===================================================================
--- branches/rel_2_0/Open-ILS/web/templates/default/acq/common/claim_dialog.tt2	2011-01-04 14:40:23 UTC (rev 19094)
+++ branches/rel_2_0/Open-ILS/web/templates/default/acq/common/claim_dialog.tt2	2011-01-04 14:51:21 UTC (rev 19095)
@@ -21,9 +21,9 @@
                 </ul>
             </li>
         </ul>
+        <hr />
     </div>
     <div id="acq-lit-li-claim-dia-initiate" class="hidden">
-        <hr />
         <div><big>Initiate New Claims</big></div>
         <div id="acq-lit-li-claim-dia-lid-list-init">
             <div name="lid_to_claim">
@@ -34,6 +34,27 @@
                 </label>
             </div>
         </div>
+        <hr />
+        <div id="acqclet-display" class="hidden">
+            <div><big>Select Claim Action</big></div>
+            <table>
+                <tbody id="acqclet-tbody">
+                    <tr name="acqclet-template">
+                        <td>
+                            <input type="checkbox" name="acqclet-checkbox" />
+                        </td>
+                        <td style="padding-left: 1em;">
+                            <label name="acqclet-label">
+                                (${ou}) ${code} <em>${description}</em>
+                                <span style="color: #069;">
+                                    ${library_initiated}</span>
+                            </label>
+                        </td>
+                    </tr>
+                </tbody>
+            </table>
+            <hr />
+        </div>
         <button id="acq-lit-li-claim-dia-claim">Claim selected</button>
     </div>
 </div>



More information about the open-ils-commits mailing list