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.Grid');
9 dojo.require("fieldmapper.OrgUtils");
10 dojo.require('openils.acq.FundingSource');
11 dojo.require('openils.acq.Fund');
12 dojo.require('openils.Event');
14 var ses = new OpenSRF.ClientSession('open-ils.acq');
15 var fundingSource = null;
17 function resetPage() {
19 fsCreditGrid.isLoaded = false;
20 fsAllocationGrid.isLoaded = false;
24 /** creates a new funding_source_credit from the dialog ----- */
25 function applyFSCredit(fields) {
26 fields.funding_source = fundingSourceID;
27 openils.acq.FundingSource.createCredit(fields, resetPage);
30 function applyFSAllocation(fields) {
31 fields.funding_source = fundingSourceID;
32 if(isNaN(fields.percent)) fields.percent = null;
33 if(isNaN(fields.amount)) fields.amount = null;
34 openils.acq.Fund.createAllocation(fields, resetPage);
37 /** fetch the fleshed funding source ----- */
39 var req = ses.request(
40 'open-ils.acq.funding_source.retrieve',
41 openils.User.authtoken, fundingSourceID,
42 {flesh_summary:1, flesh_credits:1,flesh_allocations:1}
45 req.oncomplete = function(r) {
47 fundingSource = msg.content();
48 var evt = openils.Event.parse(fundingSource);
58 /** Some grid rendering accessor functions ----- */
59 function getOrgInfo(rowIndex) {
60 data = fundingSourceGrid.model.getRow(rowIndex);
62 return fieldmapper.aou.findOrgUnit(data.owner).shortname();
65 function getSummaryInfo(rowIndex) {
66 return new String(fundingSource.summary()[this.field]);
69 /** builds the credits grid ----- */
70 function loadFSGrid() {
71 if(!fundingSource) return;
72 var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
73 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
74 fundingSourceGrid.setModel(model);
75 fundingSourceGrid.update();
79 /** builds the credits grid ----- */
80 function loadCreditGrid() {
81 if(fsCreditGrid.isLoaded) return;
82 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.credits())});
83 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
84 fsCreditGrid.setModel(model);
85 fsCreditGrid.update();
86 fsCreditGrid.isLoaded = true;
89 /** builds the allocations grid ----- */
90 function loadAllocationGrid() {
91 if(fsAllocationGrid.isLoaded) return;
92 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.allocations())});
93 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
94 fsAllocationGrid.setModel(model);
95 fsAllocationGrid.update();
96 fsAllocationGrid.isLoaded = true;
99 dojo.addOnLoad(loadFS);