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

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 21 22:05:48 EDT 2008


Author: erickson
Date: 2008-04-21 21:26:47 -0400 (Mon, 21 Apr 2008)
New Revision: 9421

Modified:
   branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Fund.js
   branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/FundingSource.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html
Log:
added fund and funding_source retrieval methods

Modified: branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Fund.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Fund.js	2008-04-22 00:58:31 UTC (rev 9420)
+++ branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/Fund.js	2008-04-22 01:26:47 UTC (rev 9421)
@@ -26,7 +26,7 @@
 
 openils.acq.Fund.cache = {};
 
-openils.acq.Fund.createStore = function(onComplete) {
+openils.acq.Fund.createStore = function(onComplete, limitPerm) {
     /** Fetches the list of funding_sources and builds a grid from them */
 
     function mkStore(r) {
@@ -38,14 +38,13 @@
             items.push(src);
             console.log('loaded fund: ' + src.name());
         }
-        console.log(js2JSON(acqf.toStoreData(items)));
         onComplete(acqf.toStoreData(items));
     }
 
     fieldmapper.standardRequest(
         ['open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
         {   async: true,
-            params: [openils.User.authtoken, null, {flesh_summary:1}],
+            params: [openils.User.authtoken, null, {flesh_summary:1, limit_perm:limitPerm}],
             oncomplete: mkStore
         }
     );
@@ -75,6 +74,21 @@
     );
 };
 
+
+/**
+ * Synchronous fund retrievel method 
+ */
+openils.acq.Fund.retrieve = function(id) {
+    if(openils.acq.Fund.cache[id])
+        return openils.acq.Fund.cache[id];
+    openils.acq.Fund.cache[id] = fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
+        [openils.User.authtoken, id]
+    );
+    return openils.acq.Fund.cache[id];
+};
+
+
 openils.acq.Fund.deleteFromGrid = function(grid, onComplete) {
     var list = []
     var selected = grid.selection.getSelected();

Modified: branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/FundingSource.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/FundingSource.js	2008-04-22 00:58:31 UTC (rev 9420)
+++ branches/acq-experiment/Open-ILS/web/js/dojo/openils/acq/FundingSource.js	2008-04-22 01:26:47 UTC (rev 9421)
@@ -17,6 +17,7 @@
 if(!dojo._hasResource['openils.acq.FundingSource']) {
 dojo._hasResource['openils.acq.FundingSource'] = true;
 dojo.provide('openils.acq.FundingSource');
+dojo.require('fieldmapper.Fieldmapper');
 
 /** Declare the FundingSource class with dojo */
 dojo.declare('openils.acq.FundingSource', null, {
@@ -71,7 +72,20 @@
     req.send();
 };
 
+/**
+ * Synchronous funding_source retrievel method 
+ */
+openils.acq.FundingSource.retrieve = function(id) {
+    if(openils.acq.FundingSource.cache[id])
+        return openils.acq.FundingSource.cache[id];
+    openils.acq.FundingSource.cache[id] = fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.funding_source.retrieve'],
+        [openils.User.authtoken, id]
+    );
+    return openils.acq.FundingSource.cache[id];
+};
 
+
 openils.acq.FundingSource.createCredit = function(fields, onCreateComplete) {
 
     var fsc = new acqfscred()

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html	2008-04-22 00:58:31 UTC (rev 9420)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html	2008-04-22 01:26:47 UTC (rev 9421)
@@ -8,8 +8,8 @@
     dojo.require('dijit.layout.TabContainer');
     dojo.require('dijit.layout.ContentPane');
     dojo.require('openils.acq.Fund');
+    dojo.require('openils.acq.FundingSource');
     dojo.require('openils.Event');
-    dojo.require('fieldmapper.Fieldmapper');
     dojo.require('openils.User');
 
     var fundID = ${c.oils.acq.fund_id};
@@ -32,19 +32,12 @@
         return fieldmapper.aou.findOrgUnit(data.org).shortname();
     }
 
-    var fsCache = {};
     function getFundingSource(rowIndex) {
         data = fundAllocationGrid.model.getRow(rowIndex);
-        if(!data) return;
-        var fsId = data.funding_source;
-        if(!fsCache[fsId]) {
-            fsCache[fsId] = fieldmapper.standardRequest(
-                ['open-ils.acq', 'open-ils.acq.funding_source.retrieve'],
-                [openils.User.authtoken, fsId]
-            );
+        if(data) {
+            var fs = openils.acq.FundingSource.retrieve(data.funding_source);
+            return '<a href="${c.oils.acq.prefix.value}/funding_source/view/'+fs.id()+'">'+fs.name()+'</a>';
         }
-        var name = fsCache[fsId].name();
-        return '<a href="${c.oils.acq.prefix.value}/funding_source/view/'+fsId+'">'+name+'</a>';
     }
 
     function loadFundGrid() {

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html	2008-04-22 00:58:31 UTC (rev 9420)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html	2008-04-22 01:26:47 UTC (rev 9421)
@@ -12,12 +12,12 @@
     dojo.require("dijit.form.Textarea");
     dojo.require("dijit.form.CurrencyTextBox");
     dojo.require('openils.acq.FundingSource');
+    dojo.require('openils.acq.Fund');
     dojo.require('openils.Event');
     
     var ses = new OpenSRF.ClientSession('open-ils.acq');
     var fundingSourceID = ${c.oils.acq.funding_source_id};
     var fundingSource = null;
-    var fundCache = {};
 
     /** creates a new funding_source_credit from the dialog ----- */
     function applyFSCredit(fields) {
@@ -33,7 +33,8 @@
     /** fetch the fleshed funding source ----- */
     function loadFS() {
         var req = ses.request(
-            'open-ils.acq.funding_source.retrieve', openils.User.authtoken, fundingSourceID, 
+            'open-ils.acq.funding_source.retrieve', 
+            openils.User.authtoken, fundingSourceID, 
             {flesh_summary:1, flesh_credits:1,flesh_allocations:1}
         );
 
@@ -66,18 +67,11 @@
     }
     
     function getFund(rowIndex) {
-        /** synchronous version ... XXX need to refactor this to be async */
         data = fsAllocationGrid.model.getRow(rowIndex);
-        if(!data) return;
-        var fundId = data.fund;
-        if(!fundCache[fundId]) {
-            req = ses.request('open-ils.acq.fund.retrieve', openils.User.authtoken, fundId);
-            req.timeout = 10;
-            req.send();
-            fundCache[fundId] = req.recv().content();
+        if(data) {
+            var fund = openils.acq.Fund.retrieve(data.fund);
+            return '<a href="${c.oils.acq.prefix.value}/fund/view/'+fund.id()+'">'+fund.name()+'</a>';
         }
-        var name = fundCache[fundId].name();
-        return '<a href="${c.oils.acq.prefix.value}/fund/view/'+fundId+'">'+name+'</a>';
     }
 
     /** builds the credits grid ----- */



More information about the open-ils-commits mailing list