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("dijit.form.CheckBox");
8 dojo.require('dojo.data.ItemFileReadStore');
9 dojo.require("fieldmapper.OrgUtils");
10 dojo.require('openils.acq.Fund');
11 dojo.require('openils.acq.FundingSource');
12 dojo.require('openils.Event');
13 dojo.require('openils.User');
14 dojo.require('openils.Util');
15 dojo.require("openils.widget.AutoFieldWidget");
21 function getSummaryInfo(rowIndex, item) {
23 return new String(fund.summary()[this.field]);
26 function createAllocation(fields) {
28 if(isNaN(fields.percent)) fields.percent = null;
29 if(isNaN(fields.amount)) fields.amount = null;
30 openils.acq.Fund.createAllocation(fields,
31 function(r){location.href = location.href;});
33 function getOrgInfo(rowIndex, item) {
35 var owner = this.grid.store.getValue(item, 'org');
36 return fieldmapper.aou.findOrgUnit(owner).shortname();
40 function getXferDest(rowIndex, item) {
42 var xfer_destination = this.grid.store.getValue(item, 'xfer_destination');
43 if(!(item && xfer_destination)) return '';
44 return xfer_destination;
47 function loadFundGrid() {
48 var store = new dojo.data.ItemFileReadStore({data:acqf.toStoreData([fund])});
49 fundGrid.setStore(store);
53 function loadAllocationGrid() {
54 if(fundAllocationGrid.isLoaded) return;
55 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.allocations())});
56 fundAllocationGrid.setStore(store);
57 fundAllocationGrid.render();
58 fundAllocationGrid.isLoaded = true;
61 function loadDebitGrid() {
62 if(fundDebitGrid.isLoaded) return;
63 var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fund.debits())});
64 fundDebitGrid.setStore(store);
65 fundDebitGrid.render();
66 fundDebitGrid.isLoaded = true;
69 function fetchFund() {
70 fieldmapper.standardRequest(
71 ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
74 openils.User.authtoken, fundID,
75 {flesh_summary:1, flesh_allocations:1, flesh_debits:1, flesh_tags:1}
76 /* TODO grab allocations and debits only on as-needed basis */
78 oncomplete: function(r) {
79 fund = r.recv().content();
86 function TransferManager() {
89 this._init = function() {
90 new openils.widget.AutoFieldWidget({
92 /* We're not really using LIDs here, we just need some class
93 * that has a fund field to take advantage of AutoFieldWidget's
96 "labelFormat": ["${0} (${1})", "code", "year"],
97 "searchFormat": ["${0} (${1})", "code", "year"],
98 "searchFilter": {"active": "t"}, /* consider making it possible
99 to select inactive? */
100 "parentNode": dojo.byId("oils-acq-fund-xfer-d-selector"),
101 "orgLimitPerms": ["ADMIN_ACQ_FUND"], /* XXX is there a more
102 appropriate permission
105 "onChange": function() {
107 this.item.currency_type == fund.currency_type() ?
109 ]("oils-acq-fund-xfer-dest-amount", "table-row");
113 }).build(function(w, ww) { self.fundSelector = w; });
115 dijit.byId("oils-acq-fund-xfer-same-o-d").onChange = function() {
116 dijit.byId("oils-acq-fund-xfer-d-amount").attr(
117 "disabled", this.attr("checked")
124 this.clearFundSelector = function() {
125 if (this.fundSelector.attr("value"))
126 this.fundSelector.attr("value", "");
129 this.setFundName = function(fund) {
130 dojo.byId("oils-acq-fund-xfer-name-fund").innerHTML =
131 fund.code() + " (" + fund.year() + ") / " + fund.name();
134 this.submit = function() {
135 var values = xferDialog.getValues();
136 var dfund = this.fundSelector.item;
137 var dfund_id = typeof(dfund.id) == "object" ? dfund.id[0] : dfund.id;
139 if (dfund_id == fund.id()) {
140 alert(localeStrings.FUND_XFER_SAME_SOURCE_AND_DEST);
143 if (confirm(localeStrings.FUND_XFER_CONFIRM)) {
144 fieldmapper.standardRequest(
145 ["open-ils.acq", "open-ils.acq.funds.transfer_money"], {
147 openils.User.authtoken,
151 (dfund.currency_type != fund.currency_type() &&
152 values.same_o_d.length) ? null : values.d_amount,
156 "oncomplete": function(r) {
157 if (openils.Util.readResponse(r) == 1) {
158 location.href = location.href;
168 tagManager = new TagManager(dojo.byId("oils-acq-tag-manager-display"));
169 tagManager.prepareTagSelector(tagSelector);
171 xferManager = new TransferManager();
176 openils.Util.addOnLoad(load);