From 8b29ad37260b5a068bcb37b257611d4dbbcdeec6 Mon Sep 17 00:00:00 2001
From: senator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Thu, 17 Jun 2010 18:45:16 +0000
Subject: [PATCH] Acq: Remove the "Selection Lists" entry from the staff
 client's menu

The unified search interface now does everything that the Selection Lists
interface could.

Also, merging selection lists now updates the edit_time field on the lead
list.



git-svn-id: svn://svn.open-ils.org/ILS/trunk@16746 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 .../src/perlmods/OpenILS/Application/Acq/Order.pm  |  13 +-
 Open-ILS/web/js/ui/default/acq/search/invoice.js   |  52 ++++++
 Open-ILS/web/js/ui/default/acq/search/picklist.js  | 188 +++++++++++++++++++++
 .../web/js/ui/default/acq/search/purchase_order.js |   7 +
 Open-ILS/web/js/ui/default/acq/search/unified.js   |  11 ++
 .../web/templates/default/acq/search/unified.tt2   | 171 ++++++++-----------
 .../chrome/content/main/menu_frame_menus.xul       |   4 +-
 7 files changed, 342 insertions(+), 104 deletions(-)
 create mode 100644 Open-ILS/web/js/ui/default/acq/search/invoice.js
 create mode 100644 Open-ILS/web/js/ui/default/acq/search/picklist.js
 create mode 100644 Open-ILS/web/js/ui/default/acq/search/purchase_order.js

diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
index f47d44dbfd..02b6283adf 100644
--- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
+++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
@@ -831,9 +831,13 @@ sub update_picklist {
     $picklist = $mgr->editor->retrieve_acq_picklist($picklist) unless ref $picklist;
     $picklist->edit_time('now');
     $picklist->editor($mgr->editor->requestor->id);
-    $mgr->picklist($picklist);
-    return $picklist if $mgr->editor->update_acq_picklist($picklist);
-    return undef;
+    if ($mgr->editor->update_acq_picklist($picklist)) {
+        $picklist = $mgr->editor->retrieve_acq_picklist($mgr->editor->data);
+        $mgr->picklist($picklist);
+        return $picklist;
+    } else {
+        return undef;
+    }
 }
 
 sub delete_picklist {
@@ -2085,6 +2089,7 @@ sub merge_picklist_api {
 
     # XXX perms on each picklist modified
 
+    $lead_pl = $e->retrieve_acq_picklist($lead_pl) or return $e->die_event;
     # point all of the lineitems at the lead picklist
     my $li_ids = $e->search_acq_lineitem({picklist => $pl_list}, {idlist => 1});
 
@@ -2101,6 +2106,8 @@ sub merge_picklist_api {
         $e->delete_acq_picklist($pl) or return $e->die_event;
     }
 
+    update_picklist($mgr, $lead_pl) or return $e->die_event;
+
     $e->commit;
     return $mgr->respond_complete;
 }
diff --git a/Open-ILS/web/js/ui/default/acq/search/invoice.js b/Open-ILS/web/js/ui/default/acq/search/invoice.js
new file mode 100644
index 0000000000..02adfb28b2
--- /dev/null
+++ b/Open-ILS/web/js/ui/default/acq/search/invoice.js
@@ -0,0 +1,52 @@
+function getInvIdent(rowIndex, item) {
+    if (item) {
+        return {
+            "inv_ident": this.grid.store.getValue(item, "inv_ident") ||
+                this.grid.store.getValue(item, "id"),
+            "id": this.grid.store.getValue(item, "id")
+        };
+    }
+}
+
+function formatInvIdent(inv) {
+    if (inv) {
+        return "<a href='" + oilsBasePath + "/acq/invoice/view/" +
+            inv.id + "'>" + inv.inv_ident + "</a>";
+    }
+}
+
+function printInvoiceVouchers() {
+    var inv_ids = dijit.byId("acq-unified-inv-grid").
+        getSelectedItems().map(function(o) {return o.id[0];});
+
+    /* XXX this business about opening a window and populating its
+     * body should be wrapped up in a simple dijit or something.
+     * consolidate with claim_voucher.js maybe. */
+    if (inv_ids.length) {
+        var win = null;
+        fieldmapper.standardRequest(
+            ["open-ils.acq", "open-ils.acq.invoice.print.html"], {
+                "params": [openils.User.authtoken, inv_ids],
+                "async": true,
+                "onresponse": function(r) {
+                    if (r = openils.Util.readResponse(r)) {
+                        if (!win) {
+                            win = window.open(
+                                "", "", "resizable,width=800," +
+                                "height=600,scrollbars=1"
+                            );
+                            win.document.title = localeStrings.INVOICES;
+                            win.document.body.innerHTML =
+                                "<style type='text/css'>.acq-invoice-" +
+                                "voucher {page-break-after:always;}" +
+                                "</style>\n";
+                        }
+                        win.document.body.innerHTML +=
+                            r.template_output().data();
+                    }
+                },
+                "oncomplete": function() { win.print(); }
+            }
+        );
+    }
+}
diff --git a/Open-ILS/web/js/ui/default/acq/search/picklist.js b/Open-ILS/web/js/ui/default/acq/search/picklist.js
new file mode 100644
index 0000000000..b21bc37cb8
--- /dev/null
+++ b/Open-ILS/web/js/ui/default/acq/search/picklist.js
@@ -0,0 +1,188 @@
+dojo.require("dojo.data.ItemFileWriteStore");
+dojo.require("dijit.Dialog");
+dojo.require("dijit.form.Button");
+dojo.require("dijit.form.TextBox");
+dojo.require("dijit.form.FilteringSelect");
+dojo.require("dijit.form.Button");
+dojo.require("dojox.grid.cells.dijit");
+dojo.require("openils.acq.Picklist");
+dojo.require("openils.widget.ProgressDialog");
+
+function getPlOwnerName(rowIndex, item) {
+    try {
+        return resultManager.plCache[this.grid.store.getValue(item, "id")].
+            owner().usrname();
+    } catch (E) {
+        return "";
+    }
+}
+
+function formatPlName(pl) {
+    if (pl) {
+        return "<a href='" + oilsBasePath + "/acq/picklist/view/" +
+            pl.id + "'>" + pl.name + "</a>";
+    }
+}
+
+function deleteSelectedPl() {
+    var grid = resultManager.result_types.picklist.interface;
+
+    progressDialog.show(true);
+
+    openils.acq.Picklist.deleteList(
+        grid.getSelectedItems().map(
+            function(item) {
+                var id = grid.store.getValue(item, "id");
+                grid.store.deleteItem(item);
+                return id;
+            }
+        ), function() { progressDialog.hide(); }
+    );
+}
+
+function cloneSelectedPl(fields) {
+    var grid = resultManager.result_types.picklist.interface;
+
+    var item = grid.getSelectedItems()[0];
+    if (!item) return;
+
+    var plId = grid.store.getValue(item, "id");
+    var entryCount = Number(grid.store.getValue(item, "entry_count"));
+
+    progressDialog.show();
+    progressDialog.update({"maximum": entryCount, "progress": 0});
+
+    fieldmapper.standardRequest(
+        ["open-ils.acq", "open-ils.acq.picklist.clone"], {
+            "async": true,
+            "params": [openils.User.authtoken, plId, fields.name],
+            "onresponse": function(r) {
+                var resp = openils.Util.readResponse(r);
+                if (resp) {
+                    progressDialog.update({"progress": resp.li});
+
+                    if (resp.complete) {
+                        progressDialog.hide();
+                        var pl = resp.picklist;
+                        pl.owner(openils.User.user);
+                        pl.entry_count(entryCount);
+                        resultManager.plCache[pl.id()] = pl;
+                        grid.store.newItem(fieldmapper.acqpl.toStoreItem(pl));
+                    }
+                }
+            }
+        }
+    );
+}
+
+function loadLeadPlSelector() {
+    var grid = resultManager.result_types.picklist.interface;
+    var data = acqpl.initStoreData();
+    var store = new dojo.data.ItemFileWriteStore({"data": data});
+
+    grid.getSelectedItems().forEach(
+        function(item) {
+            store.newItem(
+                fieldmapper.acqpl.toStoreItem(
+                    resultManager.plCache[grid.store.getValue(item, "id")]
+                )
+            );
+        }
+    );
+
+    plMergeLeadSelector.store = store;
+    plMergeLeadSelector.startup();
+}
+
+function mergeSelectedPl(fields) {
+    var grid = resultManager.result_types.picklist.interface;
+
+    if (!fields.lead) return;
+
+    var ids = [];
+    var totalLi = 0;
+    var leadPl = resultManager.plCache[fields.lead];
+    var leadPlItem;
+
+    grid.getSelectedItems().forEach(
+        function(item) {
+            var id = grid.store.getValue(item, "id");
+            if (id == fields.lead) {
+                leadPlItem = item;
+                return;
+            }
+            totalLi +=  new Number(grid.store.getValue(item, "entry_count"));
+            ids.push(id);
+        }
+    );
+
+    progressDialog.show();
+    progressDialog.update({"maximum": totalLi, "progress": 0});
+
+    fieldmapper.standardRequest(
+        ["open-ils.acq", "open-ils.acq.picklist.merge"], {
+            "async": true,
+            "params": [openils.User.authtoken, fields.lead, ids],
+            "onresponse": function(r) {
+                var resp = openils.Util.readResponse(r);
+                if (resp) {
+                    if (resp.li)
+                        progressDialog.update({"progress": resp.li});
+
+                    if (resp.complete) {
+                        progressDialog.hide();
+                        leadPl.entry_count(leadPl.entry_count() + totalLi);
+
+                        grid.store.setValue(
+                            leadPlItem, "entry_count", leadPl.entry_count()
+                        );
+                        if (resp.picklist) {
+                            grid.store.setValue(
+                                leadPlItem, "edit_time",
+                                resp.picklist.edit_time()
+                            );
+                        }
+
+                        // remove the deleted lists from the grid
+                        grid.getSelectedItems().filter(
+                            function(o) {
+                                return grid.store.getValue(o, "id") !=
+                                    fields.lead;
+                            }
+                        ).forEach(function(o) { grid.store.deleteItem(o); });
+                    }
+                }
+            }
+        }
+    );
+}
+
+function createPl(fields) {
+    if (fields.name == '') return;
+
+    var grid = resultManager.result_types.picklist.interface;
+
+    openils.acq.Picklist.create(fields,
+        function(plId) {
+            fieldmapper.standardRequest(
+                ["open-ils.acq", "open-ils.acq.picklist.retrieve"], {
+                    "async": true,
+                    "params": [
+                        openils.User.authtoken, plId,
+                        {"flesh_lineitem_count": 1, "flesh_owner": 1}
+                    ],
+                    "oncomplete": function(r) {
+                        var pl = openils.Util.readResponse(r);
+                        if (pl) {
+                            resultManager.plCache[pl.id()] = pl;
+                            grid.store.newItem(
+                                acqpl.toStoreData([pl]).items[0]
+                            );
+                        }
+                    }
+                }
+            );
+        }
+    );
+}
+
diff --git a/Open-ILS/web/js/ui/default/acq/search/purchase_order.js b/Open-ILS/web/js/ui/default/acq/search/purchase_order.js
new file mode 100644
index 0000000000..d33b6c5d1a
--- /dev/null
+++ b/Open-ILS/web/js/ui/default/acq/search/purchase_order.js
@@ -0,0 +1,7 @@
+    function formatPoName(po) {
+        if (po) {
+            return "<a href='" + oilsBasePath + "/acq/po/view/" + po.id +
+                "'>" + po.name + "</a>";
+        }
+    }
+
diff --git a/Open-ILS/web/js/ui/default/acq/search/unified.js b/Open-ILS/web/js/ui/default/acq/search/unified.js
index b0d92085bc..87563399c2 100644
--- a/Open-ILS/web/js/ui/default/acq/search/unified.js
+++ b/Open-ILS/web/js/ui/default/acq/search/unified.js
@@ -27,6 +27,17 @@ HTMLSelectElement.prototype.setValue = function(s) {
     }
 }
 
+/* minor formatting function used by autogrids in unified.tt2 */
+function getName(rowIndex, item) {
+    if (item) {
+        return {
+            "name": this.grid.store.getValue(item, "name") ||
+                localeStrings.UNNAMED,
+            "id": this.grid.store.getValue(item, "id")
+        };
+    }
+}
+
 /* quickly find elements by the value of a "name" attribute */
 function nodeByName(name, root) {
     return dojo.query("[name='" + name + "']", root)[0];
diff --git a/Open-ILS/web/templates/default/acq/search/unified.tt2 b/Open-ILS/web/templates/default/acq/search/unified.tt2
index 08ca0f3503..97f09cf6b7 100644
--- a/Open-ILS/web/templates/default/acq/search/unified.tt2
+++ b/Open-ILS/web/templates/default/acq/search/unified.tt2
@@ -1,103 +1,10 @@
 [% WRAPPER "default/base.tt2" %]
 [% ctx.page_title = "Acquisitions Search" %]
-<script src="[% ctx.media_prefix %]/js/ui/default/acq/common/base64.js">
-</script>
-<script src="[% ctx.media_prefix %]/js/ui/default/acq/search/unified.js">
-</script>
-<script type="text/javascript">
-    /* The functions in this <script> element are for formatting/getting
-        fields for autogrids, and doing misc operations on specific
-        result types. General unified search code is in unified.js. */
-    function getName(rowIndex, item) {
-        if (item) {
-            return {
-                "name": this.grid.store.getValue(item, "name") ||
-                    localeStrings.UNNAMED,
-                "id": this.grid.store.getValue(item, "id")
-            };
-        }
-    }
-
-    function getInvIdent(rowIndex, item) {
-        if (item) {
-            return {
-                "inv_ident": this.grid.store.getValue(item, "inv_ident") ||
-                    this.grid.store.getValue(item, "id"),
-                "id": this.grid.store.getValue(item, "id")
-            };
-        }
-    }
-
-    function getPlOwnerName(rowIndex, item) {
-        try {
-            return resultManager.plCache[this.grid.store.getValue(item, "id")].
-                owner().usrname();
-        } catch (E) {
-            return "";
-        }
-    }
-
-    function formatPoName(po) {
-        if (po) {
-            return "<a href='" + oilsBasePath + "/acq/po/view/" + po.id +
-                "'>" + po.name + "</a>";
-        }
-    }
-
-    function formatPlName(pl) {
-        if (pl) {
-            return "<a href='" + oilsBasePath + "/acq/picklist/view/" +
-                pl.id + "'>" + pl.name + "</a>";
-        }
-    }
-
-    function formatInvIdent(inv) {
-        if (inv) {
-            return "<a href='" + oilsBasePath + "/acq/invoice/view/" +
-                inv.id + "'>" + inv.inv_ident + "</a>";
-        }
-    }
-
-    /* XXX consider separate per-result-type .js files to separate functions
-     * like these into */
-    function printInvoiceVouchers() {
-        var inv_ids = dijit.byId("acq-unified-inv-grid").
-            getSelectedItems().map(function(o) {return o.id[0];});
-
-        /* XXX this business about opening a window and populating its
-         * body should be wrapped up in a simple dijit or something.
-         * consolidate with claim_voucher.js maybe. */
-        if (inv_ids.length) {
-            var win = null;
-            fieldmapper.standardRequest(
-                ["open-ils.acq", "open-ils.acq.invoice.print.html"], {
-                    "params": [openils.User.authtoken, inv_ids],
-                    "async": true,
-                    "onresponse": function(r) {
-                        if (r = openils.Util.readResponse(r)) {
-                            if (!win) {
-                                win = window.open(
-                                    "", "", "resizable,width=800," +
-                                    "height=600,scrollbars=1"
-                                );
-                                win.document.title = localeStrings.INVOICES;
-                                win.document.body.innerHTML =
-                                    "<style type='text/css'>.acq-invoice-" +
-                                    "voucher {page-break-after:always;}" +
-                                    "</style>\n";
-                            }
-                            win.document.body.innerHTML +=
-                                r.template_output().data();
-                        }
-                    },
-                    "oncomplete": function() { win.print(); }
-                }
-            );
-        }
-    }
-
-</script>
-<!-- later: "[% ctx.page_args.0 %]" -->
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/common/base64.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/search/unified.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/search/invoice.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/search/picklist.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/acq/search/purchase_order.js"></script>
 <div id="acq-unified-body" class="hidden">
     <div id="acq-unified-heading">
         <span id="acq-unified-heading-actual">Acquisitions Search</span>
@@ -203,6 +110,73 @@
         </table>
     </div>
     <div id="acq-unified-results-picklist" class="hidden">
+        <div class="acq-unified-result-specific-controls">
+            <div dojoType="dijit.form.DropDownButton">
+                <span>New Selection List</span>
+                <div dojoType="dijit.TooltipDialog"
+                    execute="createPl(arguments[0]);">
+                    <table class="dijitTooltipTable">
+                        <tr>
+                            <td><label for="name">Name:</label></td>
+                            <td><input dojoType="dijit.form.TextBox"
+                                name="name"/></td>
+                        </tr>
+                        <tr>
+                            <td colspan="2" align="center">
+                                <button dojoType="dijit.form.Button"
+                                    type="submit">Create</button>
+                            </td>
+                        </tr>
+                    </table>
+                </div>
+            </div>
+            <div dojoType="dijit.form.DropDownButton">
+                <span>Clone Selected</span>
+                <div dojoType="dijit.TooltipDialog"
+                    execute="cloneSelectedPl(arguments[0]);">
+                    <table class="dijitTooltipTable">
+                        <tr>
+                            <td><label for="name">New Name:</label></td>
+                            <td><input dojoType="dijit.form.TextBox"
+                                name="name"/></td>
+                        </tr>
+                        <tr>
+                            <td colspan="2" align="center">
+                                <button dojoType="dijit.form.Button"
+                                    type="submit">Clone</button>
+                            </td>
+                        </tr>
+                    </table>
+                </div>
+            </div>
+            <div dojoType="dijit.form.DropDownButton">
+                <span>Merge Selected</span>
+                <div dojoType="dijit.TooltipDialog"
+                    execute="mergeSelectedPl(arguments[0]);"
+                    jsId="plMergeDialog">
+                    <script type="dojo/connect" event="onOpen">
+                        loadLeadPlSelector();
+                    </script>
+                    <table class="dijitTooltipTable">
+                        <tr>
+                            <td><label for="name">Choose the Lead
+                                 Selection List:</label></td>
+                             <td><input jsId="plMergeLeadSelector"
+                                 dojoType="dijit.form.FilteringSelect"
+                                 name="lead" /></td>
+                        </tr>
+                        <tr>
+                            <td colspan="2" align="center">
+                                <button dojoType="dijit.form.Button"
+                                    type="submit">Merge</button>
+                            </td>
+                        </tr>
+                    </table>
+                </div>
+            </div>
+            <button dojoType="dijit.form.Button"
+                onclick="deleteSelectedPl();">Delete Selected</button>
+        </div>
         <table
             id="acq-unified-pl-grid"
             autoHeight="true"
@@ -256,5 +230,4 @@
         [% INCLUDE "default/acq/common/li_table.tt2" %]
     </div>
 </div>
-
 [% END %]
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 1bd6cb87a3..0569db577b 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
@@ -78,7 +78,7 @@
     <command id="cmd_open_vandelay" />
     
     <command id="cmd_acq_create_invoice" />
-    <command id="cmd_acq_view_picklist" />
+    <!-- <command id="cmd_acq_view_picklist" /> -->
     <command id="cmd_acq_upload" />
     <command id="cmd_acq_view_po" />
     <!-- <command id="cmd_acq_view_po_events" /> -->
@@ -272,7 +272,7 @@
         <menuitem label="&staff.main.menu.acq.bib_search.label;" accesskey="&staff.main.menu.acq.bib_search.accesskey;" command="cmd_acq_bib_search"/>
         <menuitem label="&staff.main.menu.acq.from_bib.label;" accesskey="&staff.main.menu.acq.from_bib.accesskey;" command="cmd_acq_from_bib"/>
         <!-- <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.picklist.label;" accesskey="&staff.main.menu.acq.picklist.accesskey;" command="cmd_acq_view_picklist"/>
+        <!-- <menuitem label="&staff.main.menu.acq.picklist.label;" accesskey="&staff.main.menu.acq.picklist.accesskey;" command="cmd_acq_view_picklist"/> -->
         <menuseparator />
         <menuitem label="&staff.main.menu.acq.create_invoice.label;" accesskey="&staff.main.menu.acq.create_invoice.accesskey;" command="cmd_acq_create_invoice"/>
         <menuitem label="&staff.main.menu.acq.upload.label;" accesskey="&staff.main.menu.acq.upload.accesskey;" command="cmd_acq_upload"/>
-- 
2.11.0