LP#1350371 detect dupe PO name on edit
authorBill Erickson <berick@esilibrary.com>
Wed, 30 Jul 2014 19:59:02 +0000 (15:59 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 19 Feb 2015 13:38:17 +0000 (08:38 -0500)
When changing the name of an existing PO, if the selected name collides
w/ another PO at or below the ordering agency, a warning is shown to
the user, including a link to the matching PO, and the name change is
aborted.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/acq/po/view.tt2
Open-ILS/web/js/ui/default/acq/po/view_po.js

index ab1ba88..00a8543 100644 (file)
                 </tr>
                 <tr>
                     <th>[% l('Name') %]</th>
-                    <td><a id="acq-po-view-name" href="javascript:void(0);"
-                        onclick="updatePoName()"></a></td>
+                    <td>
+                        <a id="acq-po-view-name" href="javascript:void(0);" onclick="updatePoName()"></a>
+                        <div class="hidden" id="acq-dupe-po-name">
+                            [% l('PO name already in use: ') %]
+                            <a href='javascript:;' id='acq-dupe-po-link'>[% l('View PO') %]</a>
+                        </div>
+                    </td>
                     <th>[% l('Activatable?') %]</th>
                     <td>
                         <span id="acq-po-activate-checking"></span>
index 8a43179..436450a 100644 (file)
@@ -668,6 +668,63 @@ function splitPo() {
 function updatePoName() {
     var value = prompt('Enter new purchase order name:', PO.name()); // TODO i18n
     if(!value || value == PO.name()) return;
+
+    var orgs = fieldmapper.aou.descendantNodeList(PO.ordering_agency(), true);
+    new openils.PermaCrud().search('acqpo', 
+        {
+            id : {'<>' : PO.id()},
+            name : value, 
+            ordering_agency : orgs
+        },
+        {async : true, oncomplete : function(r) {
+            var po = openils.Util.readResponse(r);
+            openils.Util.hide('acq-dupe-po-name');
+
+            if (po && (po = po[0])) {
+                var link = dojo.byId('acq-dupe-po-link');
+                openils.Util.show('acq-dupe-po-name');
+                var dupe_path = '/acq/po/view/' + po.id();
+
+                if (window.xulG) {
+
+                    if (window.IAMBROWSER) {
+                        // TODO: integration
+
+                    } else {
+                        // XUL client
+                        link.onclick = function() {
+
+                            var loc = xulG.url_prefix('XUL_BROWSER?url=') + 
+                                window.encodeURIComponent( 
+                                xulG.url_prefix('EG_WEB_BASE' + dupe_path)
+                            );
+
+                            xulG.new_tab(loc, 
+                                {tab_name: '', browser:false},
+                                {
+                                    no_xulG : false, 
+                                    show_nav_buttons : true, 
+                                    show_print_button : true, 
+                                }
+                            );
+                        }
+                    }
+
+                } else {
+                    link.onclick = function() {
+                        window.open(oilsBasePath + dupe_path, '_blank').focus();
+                    }
+                }
+
+            } else {
+                updatePoName2(value);
+            }
+       }} 
+    );
+}
+
+function updatePoName2(value) {
     PO.name(value);
     pcrud.update(PO, {
         oncomplete : function(r, cudResults) {