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) {
67 case 2: return new String(fundingSource.summary().balance);
68 case 3: return new String(fundingSource.summary().credit_total);
69 case 4: return new String(fundingSource.summary().allocation_total);
73 /** builds the credits grid ----- */
74 function loadFSGrid() {
75 if(!fundingSource) return;
76 var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
77 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
78 fundingSourceGrid.setModel(model);
79 fundingSourceGrid.update();
83 /** builds the credits grid ----- */
84 function loadCreditGrid() {
85 if(fsCreditGrid.isLoaded) return;
86 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.credits())});
87 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
88 fsCreditGrid.setModel(model);
89 fsCreditGrid.update();
90 fsCreditGrid.isLoaded = true;
93 /** builds the allocations grid ----- */
94 function loadAllocationGrid() {
95 if(fsAllocationGrid.isLoaded) return;
96 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.allocations())});
97 var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
98 fsAllocationGrid.setModel(model);
99 fsAllocationGrid.update();
100 fsAllocationGrid.isLoaded = true;
103 dojo.addOnLoad(loadFS);