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');
15 var ses = new OpenSRF.ClientSession('open-ils.acq');
16 var fundingSource = null;
18 function resetPage() {
20 fsCreditGrid.isLoaded = false;
21 fsAllocationGrid.isLoaded = false;
25 /** creates a new funding_source_credit from the dialog ----- */
26 function applyFSCredit(fields) {
27 fields.funding_source = fundingSourceID;
28 openils.acq.FundingSource.createCredit(fields, resetPage);
31 function applyFSAllocation(fields) {
32 fields.funding_source = fundingSourceID;
33 if(isNaN(fields.percent)) fields.percent = null;
34 if(isNaN(fields.amount)) fields.amount = null;
35 openils.acq.Fund.createAllocation(fields, resetPage);
38 /** fetch the fleshed funding source ----- */
40 var req = ses.request(
41 'open-ils.acq.funding_source.retrieve',
42 openils.User.authtoken, fundingSourceID,
43 {flesh_summary:1, flesh_credits:1,flesh_allocations:1}
46 req.oncomplete = function(r) {
48 fundingSource = msg.content();
49 var evt = openils.Event.parse(fundingSource);
59 /** Some grid rendering accessor functions ----- */
60 function getOrgInfo(rowIndex, item) {
62 var owner = this.grid.store.getValue(item, 'owner');
63 return fieldmapper.aou.findOrgUnit(owner).shortname();
67 function getSummaryInfo(rowIndex) {
68 return new String(fundingSource.summary()[this.field]);
71 /** builds the credits grid ----- */
72 function loadFSGrid() {
73 if(!fundingSource) return;
74 var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
76 fundingSourceGrid.setStore(store);
77 fundingSourceGrid.render();
81 /** builds the credits grid ----- */
82 function loadCreditGrid() {
83 if(fsCreditGrid.isLoaded) return;
85 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.credits())});
87 fsCreditGrid.setStore(store);
88 fsCreditGrid.render();
89 fsCreditGrid.isLoaded = true;
92 /** builds the allocations grid ----- */
93 function loadAllocationGrid() {
94 if(fsAllocationGrid.isLoaded) return;
95 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.allocations())});
97 fsAllocationGrid.setStore(store);
98 fsAllocationGrid.render();
99 fsAllocationGrid.isLoaded = true;
102 openils.Util.addOnLoad(loadFS);