Acq: If you go from a catalog record to "View/Place orders", there are now
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 8 Jul 2010 15:11:24 +0000 (15:11 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 8 Jul 2010 15:11:24 +0000 (15:11 +0000)
easy shortcuts for adding a new lineitem to a selection list or a PO if there
aren't already any existing lineitems to work with.

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

Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/js/ui/default/acq/lineitem/related.js
Open-ILS/web/templates/default/acq/lineitem/related.tt2

index c21e0a7..040e0e8 100644 (file)
@@ -1838,41 +1838,7 @@ function AcqLiTable() {
                 break;
 
             case 'create_order':
-
-                if(!this.createPoProviderSelector) {
-                    var widget = new openils.widget.AutoFieldWidget({
-                        fmField : 'provider',
-                        fmClass : 'acqpo',
-                        searchFilter: {"active": "t"},
-                        parentNode : dojo.byId('acq-lit-po-provider'),
-                        dijitArgs : {
-                            "onChange": function() {
-                                if (this.item) {
-                                    self._updateCreatePoPrepayCheckbox(
-                                        this.item.prepayment_required
-                                    );
-                                }
-                            }
-                        }
-                    });
-                    widget.build(
-                        function(w) { self.createPoProviderSelector = w; }
-                    );
-                }
-
-                if(!this.createPoAgencySelector) {
-                    var widget = new openils.widget.AutoFieldWidget({
-                        fmField : 'ordering_agency',
-                        fmClass : 'acqpo',
-                        parentNode : dojo.byId('acq-lit-po-agency'),
-                        orgLimitPerms : ['CREATE_PURCHASE_ORDER'],
-                    });
-                    widget.build(
-                        function(w) { self.createPoAgencySelector = w; }
-                    );
-                }
-
-         
+                this._loadPOSelect();
                 acqLitPoCreateDialog.show();
                 break;
 
@@ -2408,7 +2374,38 @@ function AcqLiTable() {
         );
     }
 
-    this._loadPLSelect = function() {
+    this._loadPOSelect = function() {
+        if (!this.createPoProviderSelector) {
+            var widget = new openils.widget.AutoFieldWidget({
+                "fmField": "provider",
+                "fmClass": "acqpo",
+                "searchFilter": {"active": "t"},
+                "parentNode": dojo.byId("acq-lit-po-provider"),
+                "dijitArgs": {
+                    "onChange": function() {
+                        if (this.item) {
+                            self._updateCreatePoPrepayCheckbox(
+                                this.item.prepayment_required
+                            );
+                        }
+                    }
+                }
+            });
+            widget.build(function(w) { self.createPoProviderSelector = w; });
+        }
+
+        if (!this.createPoAgencySelector) {
+            var widget = new openils.widget.AutoFieldWidget({
+                "fmField": "ordering_agency",
+                "fmClass": "acqpo",
+                "parentNode": dojo.byId("acq-lit-po-agency"),
+                "orgLimitPerms": ["CREATE_PURCHASE_ORDER"],
+            });
+            widget.build(function(w) { self.createPoAgencySelector = w; });
+        }
+    };
+
+    this._loadPLSelect = function(preSel) {
         if(this._plSelectLoaded) return;
         var plList = [];
         function handleResponse(r) {
@@ -2424,7 +2421,8 @@ function AcqLiTable() {
                     self._plSelectLoaded = true;
                     acqLitAddExistingSelect.store = 
                         new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
-                    acqLitAddExistingSelect.setValue();
+
+                    acqLitAddExistingSelect.setValue(preSel);
                 }
             }
         );
index 5e58b9a..9adbc8e 100644 (file)
@@ -35,6 +35,7 @@ function fetchRelated() {
     if(identTarget == 'bib')
         var method = 'open-ils.acq.lineitems_for_bib.by_bib_id';
 
+    var total = 0;
     fieldmapper.standardRequest(
         ["open-ils.acq", method], {
             "async": true,
@@ -46,9 +47,14 @@ function fetchRelated() {
             "onresponse": function(r) {
                 var resp = openils.Util.readResponse(r);
                 if (resp) {
+                    total++;
                     liTable.show("list");
                     liTable.addLineitem(resp);
                 }
+            },
+            "oncomplete": function() {
+                if (!total)
+                    openils.Util.show("li_create_holder");
             }
         }
     );
@@ -69,78 +75,63 @@ function fetchBib() {
     }) 
 }
 
-function addLi(fields) {
-
-    var li = new fieldmapper.jub();
-    li.marc(bibRecord.marc());
-    li.eg_bib_id(bibRecord.id());
-    if(fields.picklist) li.picklist(fields.picklist);
-    if(fields.po) li.po(fields.po);
-    li.selector(openils.User.user.id());
-    li.creator(openils.User.user.id());
-    li.editor(openils.User.user.id());
-
-    fieldmapper.standardRequest(
-        ['open-ils.acq', 'open-ils.acq.lineitem.create'],
-        {   async : true,
-            params : [openils.User.authtoken, li],
-            oncomplete : function(r) {
-                var id = openils.Util.readResponse(r);
-                if(!id) return;
-                if(fields.picklist) 
-                    location.href = oilsBasePath + '/acq/picklist/view/' + fields.picklist;
-                else
-                    location.href = oilsBasePath + '/acq/po/view/' + fields.po;
-            }
-        }
-    );
-}
-
-function loadPl() {
-
-    if(paramPL) {
-
-        fieldmapper.standardRequest(
-            ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
-            {   async: true,
-                params: [openils.User.authtoken, paramPL], 
-                oncomplete : function(r) {
-                    var pl = openils.Util.readResponse(r);
-                    plSelector.store = 
-                        new dojo.data.ItemFileReadStore({data:fieldmapper.acqpl.toStoreData([pl])});
-                    plSelector.attr('value', pl.name());
-                    plSelector.attr('disabled', true);
-                }
-            }
-        );
-
-    } else {
-
+function createLi(oncomplete) {
+    return function() {
+        progressDialog.show();
+        liTable.reset();
         fieldmapper.standardRequest(
-            ['open-ils.acq', 'open-ils.acq.picklist.user.retrieve.atomic'],
-            {   async: true,
-                params: [openils.User.authtoken], 
-                oncomplete : function(r) {
-                    var list = openils.Util.readResponse(r);
-                    plSelector.store = 
-                        new dojo.data.ItemFileReadStore({data:fieldmapper.acqpl.toStoreData(list)});
+            ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
+                "params": [
+                    openils.User.authtoken, [bibRecord.id()], {
+                        "flesh_attrs": true,
+                        "flesh_cancel_reason": true,
+                        "flesh_notes": true
+                    }
+                ],
+                "async": true,
+                "onresponse": function(r) {
+                    var li = openils.Util.readResponse(r);
+                    if (typeof(li) == "object") {
+                        liTable.show("list");
+                        liTable.addLineitem(li);
+                        dojo.query(
+                            "input[name='selectbox']", liTable._findLiRow(li)
+                        )[0].checked = true;
+                    }
+                },
+                "oncomplete": function() {
+                    progressDialog.hide();
+                    openils.Util.hide("li_create_holder");
+                    oncomplete();
                 }
             }
         );
-    }
+    };
 }
 
+function prepareButtons() {
+    addToPlButton.onClick = createLi(
+        function() { /* oncomplete */
+            liTable._loadPLSelect(paramPL);
+            acqLitSavePlDialog.show();
+        }
+    );
+    createPoButton.onClick = createLi(
+        function() { /* oncomplete */
+            liTable._loadPOSelect();
+            acqLitPoCreateDialog.show();
+        }
+    );
+}
 
 function load() {
     var cgi = new openils.CGI();
 
     identTarget = cgi.param('target');
     paramPL = cgi.param('pl');
-    paramPO = cgi.param('po');
-
-    loadPl();
+//    paramPO = cgi.param('po');
 
-    if(identTarget == 'bib') {
+    if (identTarget == 'bib') {
         fetchBib();
     } else {
         fetchLi(); 
@@ -150,6 +141,7 @@ function load() {
     liTable.reset();
     liTable._isRelatedViewer = true;
 
+    prepareButtons();
     fetchRelated();
 }
 
index ec2eaf1..27d00e1 100644 (file)
             <div type='opac/slot-data' query='datafield[tag=260] subfield[code=c]'/>
         </li>
     </ul>
-    <div dojoType="dijit.form.DropDownButton">
-        <span>Create New Lineitem For This Record</span>
-        <div dojoType="dijit.TooltipDialog"  execute="addLi(arguments[0]);">
-            <table>
-                <tbody>
-                    <tr>
-                        <td>Add To Selection List</td>
-                        <td style='padding-left:10px;'><div name='picklist' jsId='plSelector' dojoType='dijit.form.FilteringSelect'/></td>
-                    </tr>
-                    <tr>
-                        <td colspan='2' style='align:center'>
-                            <button dojoType="dijit.form.Button" type="submit">Create</button>
-                        </td>
-                    </tr>
-                </tbody>
-            </table>
-        </div>
+
+    <div id="li_create_holder" class="hidden">
+        <button jsId="addToPlButton" dojoType="dijit.form.Button">
+            Add to New Selection List
+        </button>
+        <button jsId="createPoButton" dojoType="dijit.form.Button">
+            Create a New Purchase Order
+        </button>
     </div>
 
 </div>