Eliminate duplicate call to get list of Funds
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 20 May 2008 19:09:16 +0000 (19:09 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 20 May 2008 19:09:16 +0000 (19:09 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9644 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/acq/Fund.js
Open-ILS/web/js/dojo/openils/widget/FundSelector.js

index 28dcd94..4273e23 100644 (file)
@@ -26,9 +26,10 @@ dojo.declare('openils.acq.Fund', null, {
 });
 
 openils.acq.Fund.cache = {};
+openils.acq.Fund._cachecomplete = false;
 
 openils.acq.Fund.createStore = function(onComplete, limitPerm) {
-    /** Fetches the list of funding_sources and builds a grid from them */
+    /** Fetches the list of funds and builds a grid from them */
 
     function mkStore(r) {
         var msg;
@@ -38,6 +39,7 @@ openils.acq.Fund.createStore = function(onComplete, limitPerm) {
             openils.acq.Fund.cache[src.id()] = src;
             items.push(src);
         }
+       openils.acq.Fund._cachecomplete = true;
         onComplete(acqf.toStoreData(items));
     }
 
@@ -140,5 +142,22 @@ openils.acq.Fund._deleteList = function(list, idx, onComplete) {
         }
     );
 };
-}
 
+openils.acq.Fund.nameMapping = function(oncomplete) {
+    var ids = [];
+    var names = [];
+    var buildMap = function() {
+       for (var i in openils.acq.Fund.cache) {
+           ids.push(i.id());
+           names.push(i.name());
+           oncomplete(ids, names);
+       }
+    };
+
+    if (openils.acq.Fund._cachecomplete) {
+       buildMap(oncomplete);
+    } else {
+       openils.acq.Fund.createStore(buildMap);
+    }
+};
+}
index 1713346..9ffeea9 100644 (file)
@@ -4,6 +4,7 @@ if(!dojo._hasResource["openils.widget.FundSelector"]){
 
     dojo.require("dojox.grid.editors");
 
+    dojo.require('openils.acq.Fund');
     dojo.require('fieldmapper.Fieldmapper');
     dojo.require('fieldmapper.dojoData');
 
@@ -25,21 +26,10 @@ if(!dojo._hasResource["openils.widget.FundSelector"]){
 
     dojo.addOnLoad(
        function() {
-           fieldmapper.standardRequest(
-               ['open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
-               {
-                   async: true,
-                   params: [openils.User.authtoken, null, {flesh_summary:1}],
-                   oncomplete: function (r) {
-                       var msg;
-                       
-                       while (msg = r.recv()) {
-                           var f = msg.content();
-                           console.dir(f)
-                           openils.widget.FundSelector.fundNames.push(f.name());
-                           openils.widget.FundSelector.fundCodes.push(f.id());
-                       }
-                   }
+           openils.acq.Fund.nameMapping(
+               function(ids, names) {
+                   openils.widget.FundSelector.fundCodes = ids;
+                   openils.widget.FundSelector.fundNames = names;
                });
        });
 }