From 6911f6ddb6f534e679fdd551d4aff051f6e6702a Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 22 Apr 2008 01:26:47 +0000 Subject: [PATCH] added fund and funding_source retrieval methods git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9421 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/acq/Fund.js | 20 +++++++++++++++++--- Open-ILS/web/js/dojo/openils/acq/FundingSource.js | 14 ++++++++++++++ .../oils/default/acq/financial/view_fund.html | 15 ++++----------- .../default/acq/financial/view_funding_source.html | 18 ++++++------------ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/acq/Fund.js b/Open-ILS/web/js/dojo/openils/acq/Fund.js index fc9a96b5c5..7a0e88246c 100644 --- a/Open-ILS/web/js/dojo/openils/acq/Fund.js +++ b/Open-ILS/web/js/dojo/openils/acq/Fund.js @@ -26,7 +26,7 @@ dojo.declare('openils.acq.Fund', null, { 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 @@ openils.acq.Fund.createStore = function(onComplete) { 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 @@ openils.acq.Fund.create = function(fields, onCreateComplete) { ); }; + +/** + * 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(); diff --git a/Open-ILS/web/js/dojo/openils/acq/FundingSource.js b/Open-ILS/web/js/dojo/openils/acq/FundingSource.js index 624bbfd33c..11790c1f54 100644 --- a/Open-ILS/web/js/dojo/openils/acq/FundingSource.js +++ b/Open-ILS/web/js/dojo/openils/acq/FundingSource.js @@ -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,6 +72,19 @@ openils.acq.FundingSource.create = function(fields, onCreateComplete) { 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) { diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html index 1839b1c8f1..dc9b1bab83 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_fund.html @@ -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 ''+fs.name()+''; } - var name = fsCache[fsId].name(); - return ''+name+''; } function loadFundGrid() { diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html index 9a18d1877c..a6a4804ae6 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html @@ -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 ''+fund.name()+''; } - var name = fundCache[fundId].name(); - return ''+name+''; } /** builds the credits grid ----- */ -- 2.11.0