[open-ils-commits] r10118 - in branches/acq-experiment/Open-ILS/web: js/dojo/openils/acq oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common oilsweb/oilsweb/templates/oils/default/acq/picklist

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jul 24 13:40:49 EDT 2008


Author: erickson
Date: 2008-07-24 13:40:41 -0400 (Thu, 24 Jul 2008)
New Revision: 10118

Modified:
   branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html
Log:


Put a modified version of Picklist.onJUBSet into jubgrid.js.  This way, code that uses jubgrid 
outside of the Picklist context can still take advantage of the jub update handling code

onJUBSet is automatically applied to lineitems at jubgrid create time

I commented out the version in Picklist and picklist view code, pending review




Modified: branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js	2008-07-24 17:38:18 UTC (rev 10117)
+++ branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Picklist.js	2008-07-24 17:40:41 UTC (rev 10118)
@@ -95,6 +95,8 @@
 	}
 	return '';
     },
+
+    /* MOVED INTO jubgrid.js  .. safe to delete?
     onJUBSet: function (griditem, attr, oldVal,newVal) {
 	var item;
 	var updateDone = function(r) {
@@ -107,7 +109,6 @@
 	    }
 	};
 
-    var self = this;
     // after an attribute has been updated
     var attrUpdateDone = function(r, attr) {
 	    var res = r.recv().content();
@@ -162,6 +163,7 @@
 	     oncomplete: updateDone
 	    });
     },
+    */
 });
 
 /** Creates a new picklist. fields.name is required */ 

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js	2008-07-24 17:38:18 UTC (rev 10117)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js	2008-07-24 17:40:41 UTC (rev 10118)
@@ -117,7 +117,8 @@
 
                     JUBGrid.jubDetailGrid.lineitemID = jub.id;
 
-                    if (jub.state == "approved") {
+                    //if (jub.state == "approved") {
+                    if (false) { // need finer grained control here
                         grid = JUBGrid.jubDetailGridLayoutReadOnly;
                     } else {
                         grid = JUBGrid.jubDetailGridLayout;
@@ -128,6 +129,8 @@
                 }
             );
         }
+        // capture changes to lineitems
+        dojo.connect(model.store, "onSet", JUBGrid.onJUBSet);
         gridWidget.update();
     },
 
@@ -154,7 +157,8 @@
 			// Reload lineitem details, read-only
 			openils.acq.Lineitem.loadLIDGrid(
 			    JUBGrid.jubDetailGrid, li.id(),
-			    JUBGrid.jubDetailGridLayoutReadOnly);
+			    JUBGrid.jubDetailGridLayout);
+			    //JUBGrid.jubDetailGridLayoutReadOnly);
 		    };
 
 		    JUBGrid.jubGrid.model.store.fetch({query:{id:jub.id},
@@ -248,14 +252,83 @@
     },
 
     createLID: function(fields) {
-	fields['lineitem'] = JUBGrid.jubDetailGrid.lineitemID;
-	var addToStore = function () {
-	    JUBGrid.jubDetailGrid.model.store.newItem(fields);
-	    JUBGrid.jubDetailGrid.refresh();
-	    JUBGrid.jubGrid.update();
-	    JUBGrid.jubGrid.refresh();
-	}
-	openils.acq.Lineitem.createLID(fields, addToStore);
+        fields['lineitem'] = JUBGrid.jubDetailGrid.lineitemID;
+        var addToStore = function () {
+            JUBGrid.jubDetailGrid.model.store.newItem(fields);
+            JUBGrid.jubDetailGrid.refresh();
+            JUBGrid.jubGrid.update();
+            JUBGrid.jubGrid.refresh();
+        }
+        openils.acq.Lineitem.createLID(fields, addToStore);
     },
+
+    // called when a lineitem is edited
+    onJUBSet: function (griditem, attr, oldVal,newVal) {
+        var item;
+
+        var updateDone = function(r) {
+            var stat = r.recv().content();
+            if(e = openils.Event.parse(stat)) 
+                console.dir(e);
+        };
+
+        // after an attribute has been updated
+        var attrUpdateDone = function(r, attr) {
+            var res = r.recv().content();
+            if(e = openils.Event.parse(res))
+                return alert(e);
+
+            var oldVal = new openils.acq.Lineitem(
+                {lineitem:item}).findAttr(attr, 'lineitem_local_attr_definition');
+
+            if(oldVal) {
+                // if this attr already exists on the object, just update the value
+                for(var i = 0; i < item.attributes().length; i++) {
+                    var attrobj = item.attributes()[i];
+                    if(attrobj.attr_type() == 'lineitem_local_attr_definition' && attrobj.attr_name() == attr) {
+                        attrobj.attr_value(newVal);
+                    }
+                }
+            } else {
+                // if this is a new attribute, create a new object to match reality
+                liad = new acqlia();
+                liad.attr_type('lineitem_local_attr_definition');
+                liad.attr_value(newVal);
+                liad.attr_name(attr);
+                liad.id(res);
+                item.attributes().push(liad);
+            }
+        }
+
+        if (oldVal == newVal) {
+            return;
+        }
+
+        item = JUBGrid.lineitems[griditem.id];
+        if (attr == "provider") {
+            if(newVal == '') 
+                newVal = null;
+            item.provider(newVal);
+
+        } else if(attr == 'estimated_price' || attr == 'actual_price') {
+            fieldmapper.standardRequest(
+                ['open-ils.acq', 'open-ils.acq.lineitem_local_attr.set'],
+                {   async: true,
+                    params: [openils.User.authtoken, item.id(), attr, newVal],
+                    oncomplete: function(r) {attrUpdateDone(r, attr); }
+                }
+            );
+        } else {
+            //alert("Unexpected attr in Picklist.onSet: '"+attr+"'");
+            return;
+        }
+
+        fieldmapper.standardRequest(
+            ["open-ils.acq", "open-ils.acq.lineitem.update"],
+            {params: [openils.User.authtoken, item],
+             oncomplete: updateDone
+            }
+        );
+    },
 };
 

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-07-24 17:38:18 UTC (rev 10117)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html	2008-07-24 17:40:41 UTC (rev 10118)
@@ -40,6 +40,7 @@
 				    JUBGrid.populate(pickListGrid,
 						     model,
 						     plist._items);
+                    /*
 				    dojo.connect(model.store,
 						 "onSet",
 						 function(griditem,
@@ -51,6 +52,7 @@
 								    oldVal,
 								    newVal);
 						 }); 
+                    */
 				});
             }
 	    dojo.addOnLoad(loadPL);



More information about the open-ils-commits mailing list