[open-ils-commits] r9480 - in branches/acq-experiment/Open-ILS/web: js/dojo/openils/acq oilsweb/oilsweb/templates/oils/default/acq/picklist

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 28 23:17:26 EDT 2008


Author: djfiander
Date: 2008-04-28 22:37:25 -0400 (Mon, 28 Apr 2008)
New Revision: 9480

Added:
   branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Lineitems.js
Modified:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
Log:
Retrieve and display item order details, in a primitive fashion.

Added: branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Lineitems.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Lineitems.js	                        (rev 0)
+++ branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Lineitems.js	2008-04-29 02:37:25 UTC (rev 9480)
@@ -0,0 +1,125 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008  Georgia Public Library Service
+ * David J. Fiander <david at 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;
+// };
+
+}

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html	2008-04-28 18:19:37 UTC (rev 9479)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html	2008-04-29 02:37:25 UTC (rev 9480)
@@ -40,10 +40,13 @@
 	     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},
@@ -53,32 +56,34 @@
 		    ]]
 		}];
 
+		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>



More information about the open-ils-commits mailing list