]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/financial/list_funds.js
cache has no object when a new object is created. if not in the cache, assume balanc...
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / financial / list_funds.js
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');
12
13 function getOrgInfo(rowIndex, item) {
14     if(!item) return ''; 
15     var owner = this.grid.store.getValue(item, 'org'); 
16     return fieldmapper.aou.findOrgUnit(owner).shortname();
17 }
18
19 function getBalanceInfo(rowIndex, item) {
20     if(!item) return '';
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;
25     return 0;
26 }
27
28 function loadFundGrid() {
29     var yearStore = {identifier:'year', name:'year', items:[]};
30     var yearsAdded = {}; /* don't duplicate the years in the selector */
31
32     fieldmapper.standardRequest(
33        [ 'open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
34        {    async: true,
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));
40                     var year = lf.year();
41                     if(!(year in yearsAdded)) {
42                         yearStore.items.push({year:year});
43                         yearsAdded[year] = 1;
44                     }
45                 }
46             },
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);
54             }
55         }
56     );
57 }
58
59 function filterGrid() {
60     var year = fundFilterYearSelect.getValue();
61     console.log(year);
62     if(year) 
63         lfGrid.setQuery({year:year});
64     else
65         lfGrid.setQuery({id:'*'});
66     
67     lfGrid.update();
68 }
69
70 openils.Util.addOnLoad(loadFundGrid);
71