1 dojo.require("dijit.Dialog");
2 dojo.require('dijit.layout.TabContainer');
3 dojo.require('dijit.layout.ContentPane');
4 dojo.require("dijit.form.FilteringSelect");
5 dojo.require("dijit.form.Textarea");
6 dojo.require("dijit.form.CurrencyTextBox");
7 dojo.require('dojox.grid.DataGrid');
8 dojo.require('dojo.data.ItemFileReadStore');
9 dojo.require("fieldmapper.OrgUtils");
10 dojo.require('openils.acq.FundingSource');
11 dojo.require('openils.acq.Fund');
12 dojo.require('openils.Event');
13 dojo.require('openils.Util');
14 dojo.require('openils.widget.AutoGrid');
16 var ses = new OpenSRF.ClientSession('open-ils.acq');
17 var fundingSource = null;
19 function resetPage(also_load_grid) {
21 fsCreditGrid.isLoaded = false;
22 fsAllocationGrid.isLoaded = false;
23 loadFS(also_load_grid);
26 function getFund(rowIndex, item) {
28 //return '<a href="[% ctx.base_path %]/acq/fund/view/'+fund.id()+'">'+fund.code()+'</a>';
32 /** creates a new funding_source_credit from the dialog ----- */
33 function applyFSCredit(fields) {
34 fields.funding_source = fundingSourceID;
35 openils.acq.FundingSource.createCredit(
36 fields, function() { resetPage(loadCreditGrid); }
40 function applyFSAllocation(fields) {
41 fields.funding_source = fundingSourceID;
42 if(isNaN(fields.amount)) fields.amount = null;
43 openils.acq.Fund.createAllocation(
44 fields, function() { resetPage(loadAllocationGrid); }
48 /** fetch the fleshed funding source ----- */
49 function loadFS(also_load_grid) {
50 var req = ses.request(
51 'open-ils.acq.funding_source.retrieve',
52 openils.User.authtoken, fundingSourceID,
53 {flesh_summary:1, flesh_credits:1,flesh_allocations:1}
56 req.oncomplete = function(r) {
58 fundingSource = msg.content();
59 var evt = openils.Event.parse(fundingSource);
65 if (typeof(also_load_grid) == "function")
66 also_load_grid(true /* reset_first */);
71 /** Some grid rendering accessor functions ----- */
72 function getOrgInfo(rowIndex, item) {
74 var owner = this.grid.store.getValue(item, 'owner');
75 return fieldmapper.aou.findOrgUnit(owner).shortname();
79 function getSummaryInfo(rowIndex) {
80 return new String(fundingSource.summary()[this.field]);
83 function getFund(rowIndex, item) {
85 var fId = this.grid.store.getValue(item, 'fund');
86 return openils.acq.Fund.retrieve(fId);
90 function formatFund(fund) {
92 return '<a href="' + oilsBasePath + '/acq/fund/view/'+fund.id()+'">'+fund.code()+'</a>';
96 /** builds the summary grid ----- */
97 function loadFSGrid() {
98 if(!fundingSource) return;
99 var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
100 fundingSourceGrid.setStore(store);
101 fundingSourceGrid.render();
105 /** builds the credits grid ----- */
106 function loadCreditGrid(reset_first) {
107 if (fsCreditGrid.isLoaded) return;
108 if (reset_first) fsCreditGrid.resetStore();
109 fsCreditGrid.loadAll(
110 {"order_by": {"acqfscred": "effective_date DESC"}},
111 {"funding_source": fundingSource.id()}
113 fsCreditGrid.isLoaded = true;
116 function loadAllocationGrid(reset_first) {
117 if (fsAllocationGrid.isLoaded) return;
118 if (reset_first) fsCreditGrid.resetStore();
119 fsAllocationGrid.loadAll(
120 {"order_by": {"acqfa": "create_time DESC"}},
121 {"funding_source": fundingSource.id()}
123 fsAllocationGrid.isLoaded = true;
126 openils.Util.addOnLoad(loadFS);