]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/financial/view_fund.js
Merging acq-experiment to trunk, since rel_1_4 has been branched.
[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.Grid');
6
7 dojo.require("fieldmapper.OrgUtils");
8 dojo.require('openils.acq.Fund');
9 dojo.require('openils.acq.FundingSource');
10 dojo.require('openils.Event');
11 dojo.require('openils.User');
12 dojo.require('openils.Util');
13
14 var fund = null;
15
16 function getSummaryInfo(rowIndex) {
17     return new String(fund.summary()[this.field]);
18 }
19
20 function createAllocation(fields) {
21     fields.fund = fundID;
22     if(isNaN(fields.percent)) fields.percent = null;
23     if(isNaN(fields.amount)) fields.amount = null;
24     //openils.acq.Fund.createAllocation(fields, resetPage);
25     openils.acq.Fund.createAllocation(fields, 
26         function(r){location.href = location.href;});
27 }
28
29 function getOrgInfo(rowIndex) {
30     data = fundGrid.model.getRow(rowIndex);
31     if(!data) return;
32     return fieldmapper.aou.findOrgUnit(data.org).shortname();
33 }
34
35 function getXferDest(rowIndex) {
36     data = this.grid.model.getRow(rowIndex);
37     if(!(data && data.xfer_destination)) return '';
38     return data.xfer_destination;
39 }
40
41 function loadFundGrid() {
42     var store = new dojo.data.ItemFileReadStore({data:acqf.toStoreData([fund])});
43     var model = new dojox.grid.data.DojoData(
44         null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
45     fundGrid.setModel(model);
46     fundGrid.update();
47 }
48
49 function loadAllocationGrid() {
50     if(fundAllocationGrid.isLoaded) return;
51     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.allocations())});
52     var model = new dojox.grid.data.DojoData(
53         null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
54     fundAllocationGrid.setModel(model);
55     fundAllocationGrid.update();
56     fundAllocationGrid.isLoaded = true;
57 }
58
59 function loadDebitGrid() {
60     if(fundDebitGrid.isLoaded) return;
61     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.debits())});
62     var model = new dojox.grid.data.DojoData(
63         null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
64     fundDebitGrid.setModel(model);
65     fundDebitGrid.update();
66     fundDebitGrid.isLoaded = true;
67 }
68
69 function fetchFund() {
70     fieldmapper.standardRequest(
71         ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
72         {   async: true,
73             params: [
74                 openils.User.authtoken, fundID, 
75                 {flesh_summary:1, flesh_allocations:1, flesh_debits:1} 
76                 /* TODO grab allocations and debits only on as-needed basis */
77             ],
78             oncomplete: function(r) {
79                 fund = r.recv().content();
80                 loadFundGrid(fund);
81             }
82         }
83     );
84 }
85
86 openils.Util.addOnLoad(fetchFund);