]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/openils/acq/PO.js
Merging acq-experiment to trunk, since rel_1_4 has been branched.
[working/Evergreen.git] / Open-ILS / web / js / dojo / openils / acq / PO.js
1 /* ---------------------------------------------------------------------------
2  * Copyright (C) 2008  Georgia Public Library Service
3  * Bill Erickson <erickson@esilibrary.com>
4  *
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.
9  *
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  * ---------------------------------------------------------------------------
15  */
16
17 if(!dojo._hasResource['openils.acq.PO']) {
18
19     dojo._hasResource['openils.acq.PO'] = true;
20     dojo.provide('openils.acq.PO');
21     dojo.require('fieldmapper.Fieldmapper');
22     dojo.require('fieldmapper.dojoData');
23     dojo.require('openils.Util');
24
25     /** Declare the PO class with dojo */
26     dojo.declare('openils.acq.PO', null, {
27         /* add instance methods here if necessary */
28     });
29
30     openils.acq.PO.cache = {};
31
32     openils.acq.PO.retrieve = function(id, oncomplete, args) {
33
34         var req = ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'];
35         var par = [openils.User.authtoken, id, args];
36
37         if(oncomplete) {
38             fieldmapper.standardRequest(
39                 req, 
40                 {   params:par, 
41                     async: true,
42                     oncomplete:function(r) {
43                         var po = openils.Util.extractResponse(r)
44                         if(po) {
45                             openils.acq.PO.cache[po.id()] = po;
46                             oncomplete(po);
47                         }
48                     }
49                 }
50             );
51         } else {
52             return openils.acq.PO.cache[po.id()] = 
53                 fieldmapper.standardRequest(req, par);
54         }
55     }
56
57     openils.acq.PO.create = function(po, oncomplete) {
58         var req = ['open-ils.acq', 'open-ils.acq.purchase_order.create'];
59         var par = [openils.User.authtoken, po];
60
61         fieldmapper.standardRequest(
62             req,
63             {   params: par,
64                 async: true, 
65                 oncomplete: function(r) {
66                     var po_id = r.recv().content();
67                     po.id(po_id);
68                     openils.acq.PO.cache[po_id] = po;
69                     oncomplete(po_id);
70                 }
71             }
72         );
73     }
74 };
75         
76