Retrieve and display item order details, in a primitive fashion.
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 29 Apr 2008 02:37:25 +0000 (02:37 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 29 Apr 2008 02:37:25 +0000 (02:37 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9480 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/acq/Lineitems.js [new file with mode: 0644]
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html

diff --git a/Open-ILS/web/js/dojo/openils/acq/Lineitems.js b/Open-ILS/web/js/dojo/openils/acq/Lineitems.js
new file mode 100644 (file)
index 0000000..cba0bf4
--- /dev/null
@@ -0,0 +1,125 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008  Georgia Public Library Service
+ * David J. Fiander <david@fiander.info>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * ---------------------------------------------------------------------------
+ */
+
+if(!dojo._hasResource['openils.acq.Lineitems']) {
+dojo._hasResource['openils.acq.Lineitems'] = true;
+dojo.provide('openils.acq.Lineitems');
+
+/** Declare the Lineitems class with dojo */
+dojo.declare('openils.acq.Lineitems', null, {
+    /* add instance methods here if necessary */
+});
+
+openils.acq.Lineitems.cache = {};
+
+openils.acq.Lineitems.createStore = function(li_id, onComplete) {
+    // Fetches the details of a lineitem and builds a grid
+
+    function mkStore(r) {
+       var msg;
+       var items = [];
+       while (msg = r.recv()) {
+           var data = msg.content();
+           alert(js2JSON(data));
+           for (i in data.lineitem_details()) {
+               items.push(data.lineitem_details()[i]);
+           }
+       }
+       openils.acq.Lineitems.cache[li_id] = items;
+
+       onComplete(acqlid.toStoreData(items));
+    }
+
+    fieldmapper.standardRequest(
+       ['open-ils.acq', 'open-ils.acq.lineitem.retrieve'],
+       { async: true,
+         params: [openils.User.authtoken, li_id,
+                  {flesh_attrs:1, flesh_li_details:1}],
+         oncomplete: mkStore
+       });
+};
+
+openils.acq.Lineitems.loadGrid = function(domNode, id, layout) {
+    if (!openils.acq.Lineitems.cache[id]) {
+       openils.acq.Lineitems.createStore(id,
+               function(storeData) {
+                   var store = new dojo.data.ItemFileReadStore({data:storeData});
+                   var model = new dojox.grid.data.DojoData(null, store,
+                       {rowsPerPage: 20, clientSort:true, query:{id:'*'}});
+                   openils.acq.Lineitems.cache[id] = model;
+
+                   domNode.setStructure(layout);
+                   domNode.setModel(model);
+                   domNode.update();
+                   alert('ouch! update');
+               });
+    } else {
+       domNode.setModel(openils.acq.Lineitems.cache[id]);
+       domNode.update();
+    }
+}
+
+// openils.acq.Lineitems.initGrid = function(domId, columns) {
+//     var store = new dojo.data.ItemFileWriteStore({data:{identify:'id'}});
+//     var model = new dojox.grid.data.DojoData(null, store,
+//     {rowsPerPage: 20, clientSort: true});
+    
+//     var domNode = dojo.byId(domId);
+//     var columns = layout.cells;
+//     var colWidth = (dojo.coords(domNode.parentNode).w / columns.length) - 30;
+//     for(var i in columns) {
+//         if(columns[i].width == undefined)
+//             columns[i].width = colWidth + 'px';
+//     }
+
+
+//     var grid = new dojox.Grid({structure: layout}, domId);
+
+//     openils.acq.Lineitems.loadGrid = function(domId, li_id) {
+//     var ses = new OpenSRF.ClientSession('open-ils.acq');
+//     var req = ses.request('open-ils.acq.lineitem.retrieve',
+//         openils.User.authtoken, li_id, {flesh_attrs:1,flesh_li_details:1});
+
+//     req.oncomplete = function(r) {
+//         var msg;
+//         grid.setModel(gridRefs.model);
+//         model.query = {id:'*'};
+
+//         while (msg = r.recv()) {
+//             var li = msg.content();
+               
+//             for (i in li.lineitem_details()) {
+//                 lid = li.lineitem_details()[i]
+
+//                 alert(js2JSON(lid));
+
+//                 store.newItem({
+//                     id:lid.id(),
+//                     fund:lid.fund(),
+//                     location:lid.location(),
+//                 });
+//             }
+//         }
+//         grid.update();
+//     };
+
+//     req.send();
+//     };
+
+//     return grid;
+// };
+
+}
index b3cd46c..f755fa2 100644 (file)
             dojoType="dijit.layout.ContentPane" sizeMin="20" sizeShare="20">
            <div jsid='pickListGrid' dojoType='dojox.Grid'
                 id="oils-acq-picklist-grid"> </div>
+           <script type="text/javascript" src="/js/dojo/openils/acq/Lineitems.js"></script>
            <script type="text/javascript">
                 dojo.require("openils.acq.Picklist");
-               dojo.require('dojo.data.ItemFileWriteStore');
-               var layout = [{
+//             dojo.require("openils.acq.Lineitems");
+               dojo.require('dojo.data.ItemFileReadStore');
+
+               var picklistLayout = [{
                    cells: [[
                        {name: "ID", field: 'id'},
                        {name: "Title", width: "50%", get:getJUBTitle},
                    ]]
                }];
 
+               var lineitemLayout = [{ cells: [[
+                   {name:'ID', field:'id'},
+                   {name:'Fund', field:'fund'},
+                   {name:'Location', field:'location'} ]] }];
+
                openils.acq.Picklist.createStore(${c.oils.acq.picklist.value.id()},
                    function(storeData) {
                        var store = new dojo.data.ItemFileReadStore({data:storeData});
                        var model = new dojox.grid.data.DojoData(null, store,
                                         {rowsPerPage:20, clientSort:true,
                                           query:{id:'*'}});
-                       pickListGrid.setStructure(layout);
+                       pickListGrid.setStructure(picklistLayout);
                        pickListGrid.setModel(model);
+
+                       pickListGrid.onRowClick = function(evt) {
+                           openils.acq.Lineitems.loadGrid(lineItemGrid,
+                                                          model.getRow(evt.rowIndex).id,
+                                                          lineitemLayout);
+                       };
+
                        pickListGrid.update();
                     });
            </script>
        </div>
        <div dojoType="dijit.layout.ContentPane" sizeMin="20"
             sizeShare="80">
-           <script type="text/javascript">
-               dojo.require("openils.acq.Lineitems");
-
-               var li_cols = [
-               {name: ('Fund'), field: 'fund'},
-               {name: ('Location'), field: 'location'}
-               ];
-
-               dojo.addOnLoad(function(){openils.acq.Lineitems.initGrid('oils-acq-picklist-details-grid', li_cols);});
-           </script>
-           <div id="oils-acq-picklist-details-grid">
-               <p>Copy order details go here...</p>
+           <div jsid="lineItemGrid" dojoType="dojox.Grid" id="oils-acq-picklist-details-grid">
+               <!-- Copy order details go here -->
            </div>
        </div>
     </div>