1 dojo.require("dijit.Dialog");
2 dojo.require("dijit.form.FilteringSelect");
3 dojo.require('dijit.form.Button');
4 dojo.require('dojox.grid.DataGrid');
5 dojo.require('dojo.data.ItemFileWriteStore');
6 dojo.require('openils.widget.OrgUnitFilteringSelect');
7 dojo.require('openils.acq.CurrencyType');
8 dojo.require('openils.Event');
9 dojo.require('openils.Util');
10 dojo.require('openils.acq.Fund');
11 dojo.require('openils.widget.AutoGrid');
13 function getOrgInfo(rowIndex, item) {
15 var owner = this.grid.store.getValue(item, 'org');
16 return fieldmapper.aou.findOrgUnit(owner).shortname();
19 function getBalanceInfo(rowIndex, item) {
21 var id = this.grid.store.getValue( item, 'id');
22 var fund = openils.acq.Fund.cache[id];
23 if(fund && fund.summary())
24 return fund.summary().combined_balance;
28 function loadFundGrid() {
29 var yearStore = {identifier:'year', name:'year', items:[]};
30 var yearsAdded = {}; /* don't duplicate the years in the selector */
32 fieldmapper.standardRequest(
33 [ 'open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
35 params: [openils.User.authtoken, null, {flesh_summary:1}],
36 onresponse : function(r) {
37 if(lf = openils.Util.readResponse(r)) {
38 openils.acq.Fund.cache[lf.id()] = lf;
39 lfGrid.store.newItem(acqf.toStoreItem(lf));
41 if(!(year in yearsAdded)) {
42 yearStore.items.push({year:year});
47 oncomplete : function(r) {
48 // sort the unique list of years and set the selector to "now" if possible
49 yearStore.items = yearStore.items.sort().reverse();
50 fundFilterYearSelect.store = new dojo.data.ItemFileReadStore({data:yearStore});
51 var today = new Date().getFullYear().toString();
52 if(today in yearsAdded)
53 fundFilterYearSelect.setValue(today);
59 function filterGrid() {
60 var year = fundFilterYearSelect.getValue();
63 lfGrid.setQuery({year:year});
65 lfGrid.setQuery({id:'*'});
70 openils.Util.addOnLoad(loadFundGrid);