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();
41 function getFundingSource(rowIndex, item) {
43 var fsId = this.grid.store.getValue(item, 'funding_source');
44 return openils.acq.FundingSource.retrieve(fsId);
48 function formatFundingSource(fs) {
50 return '<a href="' + oilsBasePath + '/acq/funding_source/view/'+fs.id()+'">'+fs.code()+'</a>';
54 function getXferDest(rowIndex, item) {
56 var xfer_destination = this.grid.store.getValue(item, 'xfer_destination');
57 if(!(item && xfer_destination)) return '';
58 return xfer_destination;
61 function loadFundGrid() {
62 var store = new dojo.data.ItemFileReadStore({data:acqf.toStoreData([fund])});
63 fundGrid.setStore(store);
67 function loadAllocationGrid() {
68 if(fundAllocationGrid.isLoaded) return;
69 /* XXX If we want to show allocating user with a username instead of just
70 * ID#, the following pcrud search will have to be replaced with an API
72 fundAllocationGrid.loadAll({order_by : {acqfa : 'create_time DESC'}}, {fund : fundID});
73 fundAllocationGrid.isLoaded = true;
76 function loadDebitGrid() {
77 if(fundDebitGrid.isLoaded) return;
78 fundDebitGrid.loadAll({order_by : {acqfdeb : 'create_time DESC'}}, {fund : fundID});
79 fundDebitGrid.isLoaded = true;
82 function fetchFund() {
83 fieldmapper.standardRequest(
84 ['open-ils.acq', 'open-ils.acq.fund.retrieve'],
87 openils.User.authtoken, fundID,
88 {flesh_summary:1, flesh_tags:1}
90 oncomplete: function(r) {
91 fund = r.recv().content();
98 function TransferManager() {
101 this._init = function() {
102 new openils.widget.AutoFieldWidget({
104 /* We're not really using LIDs here, we just need some class
105 * that has a fund field to take advantage of AutoFieldWidget's
108 "labelFormat": ["${0} (${1})", "code", "year"],
109 "searchFormat": ["${0} (${1})", "code", "year"],
110 "searchFilter": {"active": "t"}, /* consider making it possible
111 to select inactive? */
112 "parentNode": dojo.byId("oils-acq-fund-xfer-d-selector"),
113 "orgLimitPerms": ["ADMIN_ACQ_FUND"], /* XXX is there a more
114 appropriate permission
117 "onChange": function() {
119 this.item.currency_type == fund.currency_type() ?
121 ]("oils-acq-fund-xfer-dest-amount", "table-row");
125 }).build(function(w, ww) { self.fundSelector = w; });
127 dijit.byId("oils-acq-fund-xfer-same-o-d").onChange = function() {
128 dijit.byId("oils-acq-fund-xfer-d-amount").attr(
129 "disabled", this.attr("checked")
136 this.clearFundSelector = function() {
137 if (this.fundSelector.attr("value"))
138 this.fundSelector.attr("value", "");
141 this.setFundName = function(fund) {
142 dojo.byId("oils-acq-fund-xfer-name-fund").innerHTML =
143 fund.code() + " (" + fund.year() + ") / " + fund.name();
146 this.submit = function() {
147 var values = xferDialog.getValues();
148 var dfund = this.fundSelector.item;
149 var dfund_id = typeof(dfund.id) == "object" ? dfund.id[0] : dfund.id;
151 if (dfund_id == fund.id()) {
152 alert(localeStrings.FUND_XFER_SAME_SOURCE_AND_DEST);
155 if (confirm(localeStrings.FUND_XFER_CONFIRM)) {
156 fieldmapper.standardRequest(
157 ["open-ils.acq", "open-ils.acq.funds.transfer_money"], {
159 openils.User.authtoken,
163 (dfund.currency_type != fund.currency_type() &&
164 values.same_o_d.length) ? null : values.d_amount,
168 "oncomplete": function(r) {
169 if (openils.Util.readResponse(r) == 1) {
170 location.href = location.href;
180 tagManager = new TagManager(dojo.byId("oils-acq-tag-manager-display"));
181 tagManager.prepareTagSelector(tagSelector);
183 xferManager = new TransferManager();
188 openils.Util.addOnLoad(load);