1 /* ---------------------------------------------------------------------------
2 * Copyright (C) 2008 Georgia Public Library Service
3 * Bill Erickson <erickson@esilibrary.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * ---------------------------------------------------------------------------
17 if(!dojo._hasResource['openils.acq.FundingSource']) {
18 dojo._hasResource['openils.acq.FundingSource'] = true;
19 dojo.provide('openils.acq.FundingSource');
20 dojo.require('fieldmapper.Fieldmapper');
21 dojo.require('fieldmapper.dojoData');
23 /** Declare the FundingSource class with dojo */
24 dojo.declare('openils.acq.FundingSource', null, {
25 /* add instance methods here if necessary */
28 /** cached funding_source objects */
29 openils.acq.FundingSource.cache = {};
31 openils.acq.FundingSource.createStore = function(onComplete) {
32 /** Fetches the list of funding_sources and builds a grid from them */
33 var ses = new OpenSRF.ClientSession('open-ils.acq');
34 var req = ses.request('open-ils.acq.funding_source.org.retrieve',
35 openils.User.authtoken, null, {flesh_summary:1});
37 req.oncomplete = function(r) {
41 while(msg = r.recv()) {
43 openils.acq.FundingSource.cache[src.id()] = src;
46 onComplete(acqfs.toStoreData(items));
55 * Create a new funding source object
56 * @param fields Key/value pairs used to create the new funding source
58 openils.acq.FundingSource.create = function(fields, onCreateComplete) {
61 for(var field in fields)
62 fs[field](fields[field]);
64 var ses = new OpenSRF.ClientSession('open-ils.acq');
65 var req = ses.request('open-ils.acq.funding_source.create', openils.User.authtoken, fs);
67 req.oncomplete = function(r) {
69 var id = msg.content();
77 * Synchronous funding_source retrievel method
79 openils.acq.FundingSource.retrieve = function(id) {
80 if(openils.acq.FundingSource.cache[id])
81 return openils.acq.FundingSource.cache[id];
82 openils.acq.FundingSource.cache[id] = fieldmapper.standardRequest(
83 ['open-ils.acq', 'open-ils.acq.funding_source.retrieve'],
84 [openils.User.authtoken, id]
86 return openils.acq.FundingSource.cache[id];
90 openils.acq.FundingSource.createCredit = function(fields, onCreateComplete) {
92 var fsc = new acqfscred()
93 for(var field in fields)
94 fsc[field](fields[field]);
96 var ses = new OpenSRF.ClientSession('open-ils.acq');
97 var req = ses.request(
98 'open-ils.acq.funding_source_credit.create', openils.User.authtoken, fsc);
100 req.oncomplete = function(r) {
102 var id = msg.content();
104 onCreateComplete(id);
110 openils.acq.FundingSource.deleteFromGrid = function(grid, onComplete) {
112 var selected = grid.selection.getSelected();
113 for(var rowIdx in selected)
114 list.push(grid.model.getDatum(selected[rowIdx], 0));
115 openils.acq.FundingSource.deleteList(list, onComplete);
118 openils.acq.FundingSource.deleteList = function(list, onComplete) {
119 openils.acq.FundingSource._deleteList(list, 0, onComplete);
122 openils.acq.FundingSource._deleteList = function(list, idx, onComplete) {
123 if(idx >= list.length)
126 var ses = new OpenSRF.ClientSession('open-ils.acq');
127 var req = ses.request('open-ils.acq.funding_source.delete', openils.User.authtoken, list[idx]);
128 delete openils.acq.FundingSource.cache[list[idx]];
130 req.oncomplete = function(r) {
132 stat = msg.content();
133 /* XXX CHECH FOR EVENT */
134 openils.acq.FundingSource._deleteList(list, ++idx, onComplete);
140 } /* end dojo._hasResource[] */