From: erickson Date: Thu, 24 Jul 2008 17:40:41 +0000 (+0000) Subject: Put a modified version of Picklist.onJUBSet into jubgrid.js. This way, code that... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2b2b3db66012ade063838cf4ca67f5329e24133b;p=Evergreen.git 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 git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@10118 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/acq/Picklist.js b/Open-ILS/web/js/dojo/openils/acq/Picklist.js index 3d814e9417..202d31ca54 100644 --- a/Open-ILS/web/js/dojo/openils/acq/Picklist.js +++ b/Open-ILS/web/js/dojo/openils/acq/Picklist.js @@ -95,6 +95,8 @@ dojo.declare('openils.acq.Picklist', null, { } return ''; }, + + /* MOVED INTO jubgrid.js .. safe to delete? onJUBSet: function (griditem, attr, oldVal,newVal) { var item; var updateDone = function(r) { @@ -107,7 +109,6 @@ dojo.declare('openils.acq.Picklist', null, { } }; - var self = this; // after an attribute has been updated var attrUpdateDone = function(r, attr) { var res = r.recv().content(); @@ -162,6 +163,7 @@ dojo.declare('openils.acq.Picklist', null, { oncomplete: updateDone }); }, + */ }); /** Creates a new picklist. fields.name is required */ diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js index 6681ca6b70..6928a937fa 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js @@ -117,7 +117,8 @@ var JUBGrid = { 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 @@ var JUBGrid = { } ); } + // capture changes to lineitems + dojo.connect(model.store, "onSet", JUBGrid.onJUBSet); gridWidget.update(); }, @@ -154,7 +157,8 @@ var JUBGrid = { // 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 @@ var JUBGrid = { }, 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 + } + ); }, }; diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html index 5290a0a333..c38784ff39 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/view.html @@ -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);