From: djfiander Date: Tue, 20 May 2008 19:09:16 +0000 (+0000) Subject: Eliminate duplicate call to get list of Funds X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d0b490537c493f9866293b18a9364abb1f55f74a;p=Evergreen.git Eliminate duplicate call to get list of Funds git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9644 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/js/dojo/openils/acq/Fund.js b/Open-ILS/web/js/dojo/openils/acq/Fund.js index 28dcd9404e..4273e23997 100644 --- a/Open-ILS/web/js/dojo/openils/acq/Fund.js +++ b/Open-ILS/web/js/dojo/openils/acq/Fund.js @@ -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); + } +}; +} diff --git a/Open-ILS/web/js/dojo/openils/widget/FundSelector.js b/Open-ILS/web/js/dojo/openils/widget/FundSelector.js index 1713346d4c..9ffeea99d7 100644 --- a/Open-ILS/web/js/dojo/openils/widget/FundSelector.js +++ b/Open-ILS/web/js/dojo/openils/widget/FundSelector.js @@ -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; }); }); }