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 */);
70 new openils.widget.AutoFieldWidget({
72 /* We're not really using LIDs here, we just need some class
73 * that has a fund field to take advantage of AutoFieldWidget's
76 "labelFormat": ["${0} (${1})", "code", "year"],
77 "searchFormat": ["${0} (${1})", "code", "year"],
78 "searchFilter": {"active": "t"},
79 "searchOptions": {"order_by" : {"acqf":"year DESC, code"}},
80 "parentNode": dojo.byId("oils-acq-funding-source-fund-allocate"),
81 "orgLimitPerms": ["MANAGE_FUND"], //???
82 "dijitArgs": { "name" : "fund" }
83 }).build(function(w, ww) {});
86 /** Some grid rendering accessor functions ----- */
87 function getOrgInfo(rowIndex, item) {
89 var owner = this.grid.store.getValue(item, 'owner');
90 return fieldmapper.aou.findOrgUnit(owner).shortname();
94 function getSummaryInfo(rowIndex) {
95 return new String(fundingSource.summary()[this.field]);
98 function getFund(rowIndex, item) {
100 var fId = this.grid.store.getValue(item, 'fund');
101 return openils.acq.Fund.retrieve(fId);
105 function formatFund(fund) {
107 return '<a href="' + oilsBasePath + '/acq/fund/view/'+fund.id()+'">'+fund.code()+'</a>';
111 /** builds the summary grid ----- */
112 function loadFSGrid() {
113 if(!fundingSource) return;
114 var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
115 fundingSourceGrid.setStore(store);
116 fundingSourceGrid.render();
120 /** builds the credits grid ----- */
121 function loadCreditGrid(reset_first) {
122 if (fsCreditGrid.isLoaded) return;
123 if (reset_first) fsCreditGrid.resetStore();
124 fsCreditGrid.loadAll(
125 {"order_by": {"acqfscred": "effective_date DESC"}},
126 {"funding_source": fundingSource.id()}
128 fsCreditGrid.isLoaded = true;
131 function loadAllocationGrid(reset_first) {
132 if (fsAllocationGrid.isLoaded) return;
133 if (reset_first) fsCreditGrid.resetStore();
134 fsAllocationGrid.loadAll(
135 {"order_by": {"acqfa": "create_time DESC"}},
136 {"funding_source": fundingSource.id()}
138 fsAllocationGrid.isLoaded = true;
141 openils.Util.addOnLoad(loadFS);