]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/financial/view_fund.js
Acq: Resurrect an old "view fund" interface, add some tag mapping managment
[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 var tagManager;
17
18 function getSummaryInfo(rowIndex, item) {
19     if(!item) return'';
20     return new String(fund.summary()[this.field]);
21 }
22
23 function createAllocation(fields) {
24     fields.fund = fundID;
25     if(isNaN(fields.percent)) fields.percent = null;
26     if(isNaN(fields.amount)) fields.amount = null;
27     openils.acq.Fund.createAllocation(fields, 
28         function(r){location.href = location.href;});
29 }
30 function getOrgInfo(rowIndex, item) {
31     if(!item) return ''; 
32     var owner = this.grid.store.getValue(item, 'org'); 
33     return fieldmapper.aou.findOrgUnit(owner).shortname();
34
35 }
36
37 function getXferDest(rowIndex, item) {
38     if(!item) return '';
39     var xfer_destination = this.grid.store.getValue(item, 'xfer_destination');
40     if(!(item && xfer_destination)) return '';
41     return xfer_destination;
42 }
43
44 function loadFundGrid() {
45     var store = new dojo.data.ItemFileReadStore({data:acqf.toStoreData([fund])});
46     fundGrid.setStore(store);
47     fundGrid.render();
48 }
49
50 function loadAllocationGrid() {
51     if(fundAllocationGrid.isLoaded) return;
52     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.allocations())});
53     fundAllocationGrid.setStore(store);
54     fundAllocationGrid.render();
55     fundAllocationGrid.isLoaded = true;
56 }
57
58 function loadDebitGrid() {
59     if(fundDebitGrid.isLoaded) return;
60     var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.debits())});
61     fundDebitGrid.setStore(store);
62     fundDebitGrid.render();
63     fundDebitGrid.isLoaded = true;
64 }
65
66 function fetchFund() {
67     fieldmapper.standardRequest(
68         ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
69         {   async: true,
70             params: [
71                 openils.User.authtoken, fundID, 
72                 {flesh_summary:1, flesh_allocations:1, flesh_debits:1, flesh_tags:1} 
73                 /* TODO grab allocations and debits only on as-needed basis */
74             ],
75             oncomplete: function(r) {
76                 fund = r.recv().content();
77                 loadFundGrid(fund);
78             }
79         }
80     );
81 }
82
83 function load() {
84     tagManager = new TagManager(dojo.byId("oils-acq-tag-manager-display"));
85     tagManager.prepareTagSelector(tagSelector);
86     fetchFund();
87 }
88
89 openils.Util.addOnLoad(load);