KMAIN 266 Note batch dropdown
authorBill Erickson <berickxx@gmail.com>
Thu, 29 Oct 2015 14:17:37 +0000 (10:17 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Add batch note/alert field to purchase order line item batch apply.
Add loop which adds notes/alerts to lineitems.
Add notice to user that an alert code is required.

modified:   KCLS/openils/var/templates_kcls/acq/common/li_table.tt2
modified:   Open-ILS/web/js/ui/kcls/acq/common/li_table.js

Signed-off-by: Michael Glass (mglass@catalystitservices.com)
berick: did some minor formatting cleanup.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/acq/common/li_table.tt2
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 91a14bc..eafd398 100644 (file)
                 <th>
                     <label for="acq-bu-distribution_formula">[% l("Distribution Formula") %]</label>
                 </th>
+                <th></th>
+                <th>
+                    <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
+                </th>
+                <th>
+                    <label for="acq-batch-create-note-text" class='batch-note'>[% l('Note') %]&nbsp;&nbsp;</label>
+                </th>
+                <th>
+                    <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
+                </th>
+                <th>
+                    <label for="acq-batch-lit-alert-alert-text" class='batch-alert'>[% l('Choose alert code ') %]&nbsp;&nbsp;</label>
+                </th>
             </tr>
             <tr>
                 <td>
                     <span id="acq-bu-circ_modifier"></span> OR
                 </td>
                 <td>
-                    <span id="acq-bu-distribution_formula"></span>
+                     <span id="acq-bu-distribution_formula"></span>
+                </td>
+                <td>&nbsp;</td>
+                <td>&nbsp;</td>
+               <td>
+                    <div id='batch-note-div' class='batch-note' ">
+                        <div id = "acg-batch-create-note-text" jsId="acqBatchCreateNoteText" dojoType="dijit.form.Textarea" style="height: 10px; width:15em;" name="note"></div><br>
+                        <label for="acq-batch-create-note-vendor-public">[% l('Note is vendor-public') %]</label>
+                        <div dojoType="dijit.form.CheckBox" jsId="acqBatchCreateNoteVendorPublic" name="vendor_public" id="acq-batch-create-note-vendor-public"></div>
+                    </div>
+                </td>
+                <td>
+                    <span>&nbsp;</span>
+                </td>
+                <td>
+                    <div id='batch-alert-div' class='batch-alert'">
+                       <input id="acq-batch-lit-alert-alert-text" jsId="acqBatchLitAlertAlertText" dojoType="dijit.form.FilteringSelect" labelAttr="code" searchAttr="code" required="true" />
+                       <br>
+                       <label for="acq-batch-lit-alert-value">[% l('Alert Additional comments') %]</label>    <br>
+                       <div jsId="acqBatchLitAlertNoteValue" id="acq-batch-lit-alert-value" dojoType="dijit.form.Textarea" style="height: 10px; width:15em;" name="value"></div>
+                    <div>
+                </td>
+                <td>&nbsp;</td>
+                <td>&nbsp;</td>
+                <td>
                     <span dojoType="dijit.form.Button" jsId="acqBatchUpdateApply">[% l("Apply to Selected") %]</span>
                 </td>
             </tr>
index 5ff4144..fa68955 100644 (file)
@@ -1,4 +1,5 @@
 dojo.require('dojo.date.locale');
+dojo.require('dojox.validate.check');
 dojo.require('dojo.date.stamp');
 dojo.require('dijit.form.Button');
 dojo.require('dijit.form.TextBox');
@@ -303,6 +304,53 @@ function AcqLiTable() {
                 alert(localeStrings.NO_LI_TO_UPDATE);
                 return;
             }
+            //Get all li elements on the page
+            var liItems = self.getSelected(true, null, false);
+
+            //Add batch of notes to all list elements
+            dojo.forEach(liItems, function(li) {
+                if(li_id_list.indexOf(JSON.stringify(li.id())) == -1){return;}
+                var value = acqBatchCreateNoteText.attr('value');
+                if(!value) return;
+                var note = new fieldmapper.acqlin();
+                note.isnew(true);
+                note.vendor_public(
+                    Boolean(acqBatchCreateNoteVendorPublic.attr('checked'))
+                );
+                note.value(value);
+                note.lineitem(li.id());
+                self.updateLiNotes(li, note, true);
+            });
+            acqBatchCreateNoteVendorPublic.attr("checked", false);
+            acqBatchCreateNoteText.attr("value", "");
+            var alertCodeCheck = true;
+            //Add alerts to all list elements
+            dojo.forEach(liItems, function(li) {
+                if(li_id_list.indexOf(JSON.stringify(li.id())) == -1){return;}
+                if (!acqBatchLitAlertAlertText.item) {
+                    if(acqBatchLitAlertNoteValue.attr("value") && alertCodeCheck) {
+                        alertCodeCheck = false;
+                        alert(localeStrings.ALERT_UNSELECTED);
+                    }
+                    return;
+                } 
+                var alert_text = new fieldmapper.acqliat().fromStoreItem(
+                    acqBatchLitAlertAlertText.item
+                );
+
+                var value = acqBatchLitAlertNoteValue.attr("value") || "";
+
+                var note = new fieldmapper.acqlin();
+                note.isnew(true);
+                note.lineitem(li.id());
+                note.value(value);
+                note.alert_text(alert_text);
+
+                self.updateLiNotes(li, note, true);
+            });
+            acqBatchLitAlertNoteValue.attr("value", "");
+            acqBatchLitAlertAlertText.attr("value", "");
+
 
             progressDialog.show(true);
             progressDialog.attr("title", localeStrings.LI_BATCH_UPDATE);
@@ -339,11 +387,15 @@ function AcqLiTable() {
                     }
                 }
             );
+            location.reload(true);
         };
     };
 
     this.batchUpdateChanges = function() {
         var o = {};
+        
+        // This will iterate over the batch apply properties, and will create 
+        // an array containing values of the form (batchProp:batchValue). 
 
         dojo.forEach(
             openils.Util.objectProperties(this.batchUpdateWidgets),
@@ -470,6 +522,7 @@ function AcqLiTable() {
                 openils.Util.show('acq-lit-table-div');
                 this.focusLi();
                 this.refreshInlineCopies();
+                this._setBatchAlertStore();
                 break;
             case 'info':
                 openils.Util.show('acq-lit-info-div');
@@ -1371,6 +1424,24 @@ function AcqLiTable() {
         openils.Util.show(state_cell);
     };
 
+    this._setBatchAlertStore = function() {
+        acqBatchLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
+            {
+                "data": acqliat.toStoreData(
+                    this.pcrud.search(
+                        "acqliat", {
+                            "owning_lib": aou.orgNodeTrail(
+                                aou.findOrgUnit(openils.User.user.ws_ou())
+                            ).map(function(o) { return o.id(); })
+                        }
+                    )
+                )
+            }
+        );
+        acqBatchLitAlertAlertText.setValue(); /* make the store "live" */
+        acqBatchLitAlertAlertText._store_ready = true;
+    };
+
 
     this._setAlertStore = function() {
         acqLitAlertAlertText.store = new dojo.data.ItemFileReadStore(
@@ -1501,7 +1572,8 @@ function AcqLiTable() {
     /**
      * Updates any new/changed/deleted notes on the server
      */
-    this.updateLiNotes = function(li, newNote) {
+    this.updateLiNotes = function(li, newNote, isBatch) {
+        isBatch = isBatch || false;
 
         var notes;
         if(newNote) {
@@ -1520,7 +1592,7 @@ function AcqLiTable() {
 
         fieldmapper.standardRequest(
             ['open-ils.acq', 'open-ils.acq.lineitem_note.cud.batch'],
-            {   async : true,
+            {   async : !isBatch,
                 params : [this.authtoken, notes],
                 onresponse : function(r) {
                     var resp = openils.Util.readResponse(r);