]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/financial/view_fund.js
move to 1.2 markup grid
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / financial / view_fund.js
1 dojo.require("dijit.Dialog");
2 dojo.require('dijit.form.FilteringSelect');
3 dojo.require('dijit.layout.TabContainer');
4 dojo.require('dijit.layout.ContentPane');
5 dojo.require('dojox.grid.DataGrid');
6 dojo.require('dijit.form.CurrencyTextBox');
7 dojo.require('dojo.data.ItemFileReadStore');
8 dojo.require("fieldmapper.OrgUtils");
9 dojo.require('openils.acq.Fund');
10 dojo.require('openils.acq.FundingSource');
11 dojo.require('openils.Event');
12 dojo.require('openils.User');
13 dojo.require('openils.Util');
14
15 var fund = null;
16
17 function getSummaryInfo(rowIndex, item) {
18     if(!item) return'';
19     return new String(fund.summary()[this.field]);
20 }
21
22 function createAllocation(fields) {
23     fields.fund = fundID;
24     if(isNaN(fields.percent)) fields.percent = null;
25     if(isNaN(fields.amount)) fields.amount = null;
26     openils.acq.Fund.createAllocation(fields, 
27         function(r){location.href = location.href;});
28 }
29 function getOrgInfo(rowIndex, item) {
30     if(!item) return ''; 
31     var owner = this.grid.store.getValue(item, 'org'); 
32     return fieldmapper.aou.findOrgUnit(owner).shortname();
33
34 }
35
36 function getXferDest(rowIndex, item) {
37     if(!item) return '';
38     var xfer_destination = this.grid.store.getValue(item, 'xfer_destination');
39     if(!(item && xfer_destination)) return '';
40     return xfer_destination;
41 }
42
43 function loadFundGrid() {
44     var store = new dojo.data.ItemFileReadStore({data:acqf.toStoreData([fund])});
45     fundGrid.setStore(store);
46     fundGrid.render();
47 }
48
49 function loadAllocationGrid() {
50     if(fundAllocationGrid.isLoaded) return;
51     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.allocations())});
52     fundAllocationGrid.setStore(store);
53     fundAllocationGrid.render();
54     fundAllocationGrid.isLoaded = true;
55 }
56
57 function loadDebitGrid() {
58     if(fundDebitGrid.isLoaded) return;
59     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.debits())});
60     fundDebitGrid.setStore(store);
61     fundDebitGrid.render();
62     fundDebitGrid.isLoaded = true;
63 }
64
65 function fetchFund() {
66     fieldmapper.standardRequest(
67         ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
68         {   async: true,
69             params: [
70                 openils.User.authtoken, fundID, 
71                 {flesh_summary:1, flesh_allocations:1, flesh_debits:1} 
72                 /* TODO grab allocations and debits only on as-needed basis */
73             ],
74             oncomplete: function(r) {
75                 fund = r.recv().content();
76                 loadFundGrid(fund);
77             }
78         }
79     );
80 }
81
82 openils.Util.addOnLoad(fetchFund);