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");
16 dojo.require("openils.widget.AutoGrid");
22 function getSummaryInfo(rowIndex, item) {
24 return new String(fund.summary()[this.field]);
27 function createAllocation(fields) {
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 fundAllocationGrid.loadAll({order_by : {acqfa : 'create_time DESC'}});
56 fundAllocationGrid.isLoaded = true;
59 function loadDebitGrid() {
60 if(fundDebitGrid.isLoaded) return;
61 fundDebitGrid.loadAll({order_by : {acqfdeb : 'create_time DESC'}});
62 fundDebitGrid.isLoaded = true;
65 function fetchFund() {
66 fieldmapper.standardRequest(
67 ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
70 openils.User.authtoken, fundID,
71 {flesh_summary:1, flesh_tags:1}
73 oncomplete: function(r) {
74 fund = r.recv().content();
81 function TransferManager() {
84 this._init = function() {
85 new openils.widget.AutoFieldWidget({
87 /* We're not really using LIDs here, we just need some class
88 * that has a fund field to take advantage of AutoFieldWidget's
91 "labelFormat": ["${0} (${1})", "code", "year"],
92 "searchFormat": ["${0} (${1})", "code", "year"],
93 "searchFilter": {"active": "t"}, /* consider making it possible
94 to select inactive? */
95 "parentNode": dojo.byId("oils-acq-fund-xfer-d-selector"),
96 "orgLimitPerms": ["ADMIN_ACQ_FUND"], /* XXX is there a more
97 appropriate permission
100 "onChange": function() {
102 this.item.currency_type == fund.currency_type() ?
104 ]("oils-acq-fund-xfer-dest-amount", "table-row");
108 }).build(function(w, ww) { self.fundSelector = w; });
110 dijit.byId("oils-acq-fund-xfer-same-o-d").onChange = function() {
111 dijit.byId("oils-acq-fund-xfer-d-amount").attr(
112 "disabled", this.attr("checked")
119 this.clearFundSelector = function() {
120 if (this.fundSelector.attr("value"))
121 this.fundSelector.attr("value", "");
124 this.setFundName = function(fund) {
125 dojo.byId("oils-acq-fund-xfer-name-fund").innerHTML =
126 fund.code() + " (" + fund.year() + ") / " + fund.name();
129 this.submit = function() {
130 var values = xferDialog.getValues();
131 var dfund = this.fundSelector.item;
132 var dfund_id = typeof(dfund.id) == "object" ? dfund.id[0] : dfund.id;
134 if (dfund_id == fund.id()) {
135 alert(localeStrings.FUND_XFER_SAME_SOURCE_AND_DEST);
138 if (confirm(localeStrings.FUND_XFER_CONFIRM)) {
139 fieldmapper.standardRequest(
140 ["open-ils.acq", "open-ils.acq.funds.transfer_money"], {
142 openils.User.authtoken,
146 (dfund.currency_type != fund.currency_type() &&
147 values.same_o_d.length) ? null : values.d_amount,
151 "oncomplete": function(r) {
152 if (openils.Util.readResponse(r) == 1) {
153 location.href = location.href;
163 tagManager = new TagManager(dojo.byId("oils-acq-tag-manager-display"));
164 tagManager.prepareTagSelector(tagSelector);
166 xferManager = new TransferManager();
171 openils.Util.addOnLoad(load);