]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/lineitem/related.js
switch to authoritative methods for various acq retrievals
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / lineitem / related.js
1 dojo.require("openils.acq.Lineitem");
2 dojo.require("openils.Util");
3 dojo.require("openils.XUL");
4 dojo.require("openils.CGI");
5 dojo.require("openils.PermaCrud");
6 dojo.require('openils.BibTemplate');
7 dojo.require('fieldmapper.OrgUtils');
8
9 var liTable;
10 var identTarget;
11 var bibRecord;
12 var paramPL;
13 var paramPO;
14
15 function fetchLi() {
16     fieldmapper.standardRequest(
17         ["open-ils.acq", "open-ils.acq.lineitem.retrieve.authoritative"], {
18             "async": true,
19             "params": [openils.User.authtoken, targetId, {
20                 "flesh_attrs": true,
21                 "flesh_li_details": true,
22                 "flesh_fund_debit": true,
23                 "flesh_cancel_reason": true
24             }],
25             "oncomplete": function(r) {
26                 var li = openils.Util.readResponse(r);
27                 fetchBib(li.eg_bib_id());
28             }
29         }
30     );
31 }
32
33
34 function fetchRelated() {
35     var method = 'open-ils.acq.lineitems_for_bib.by_lineitem_id';
36     if(identTarget == 'bib')
37         var method = 'open-ils.acq.lineitems_for_bib.by_bib_id';
38
39     var total = 0;
40     fieldmapper.standardRequest(
41         ["open-ils.acq", method], {
42             "async": true,
43             "params": [openils.User.authtoken, targetId, {
44                 "flesh_attrs": true,
45                 "flesh_notes": true,
46                 "flesh_cancel_reason": true
47             }],
48             "onresponse": function(r) {
49                 var resp = openils.Util.readResponse(r);
50                 if (resp) {
51                     total++;
52                     liTable.show("list");
53                     liTable.addLineitem(resp);
54                 }
55             }
56         }
57     );
58 }
59
60 function fetchBib(bibId) {
61     bibId = bibId || targetId;
62     new openils.BibTemplate({ 
63         record : bibId, 
64         org_unit : fieldmapper.aou.findOrgUnit(openils.User.user.ws_ou()).shortname()
65     }).render();
66
67     new openils.PermaCrud().retrieve('bre', bibId, {
68         oncomplete : function(r) {
69             bibRecord = openils.Util.readResponse(r);
70             // render bib details
71             // perhaps we just pull these from the beating heart of bibtemplate
72         }
73     }) 
74 }
75
76 function createLi(oncomplete) {
77     return function() {
78         progressDialog.show();
79         liTable.reset();
80         fieldmapper.standardRequest(
81             ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
82                 "params": [
83                     openils.User.authtoken, [bibRecord.id()], {
84                         "flesh_attrs": true,
85                         "flesh_cancel_reason": true,
86                         "flesh_notes": true
87                     }
88                 ],
89                 "async": false,
90                 "onresponse": function(r) {
91                     var li = openils.Util.readResponse(r);
92                     if (typeof(li) == "object") {
93                         liTable.show("list");
94                         liTable.addLineitem(li);
95                         dojo.query(
96                             "input[name='selectbox']", liTable._findLiRow(li)
97                         )[0].checked = true;
98                     }
99                 },
100                 "oncomplete": function() {
101                     progressDialog.hide();
102                     oncomplete();
103                 }
104             }
105         );
106     };
107 }
108
109 function prepareButtons() {
110     addToPlButton.onClick = createLi(
111         function() { /* oncomplete */
112             liTable._loadPLSelect(paramPL);
113             acqLitSavePlDialog.show();
114         }
115     );
116     createPoButton.onClick = createLi(
117         function() { /* oncomplete */
118             liTable._loadPOSelect();
119             acqLitPoCreateDialog.show();
120         }
121     );
122 }
123
124 function load() {
125     var cgi = new openils.CGI();
126
127     identTarget = cgi.param('target');
128     paramPL = cgi.param('pl');
129 //    paramPO = cgi.param('po');
130
131     if (identTarget == 'bib') {
132         fetchBib();
133     } else {
134         fetchLi(); 
135     }
136
137     liTable = new AcqLiTable();
138     liTable.reset();
139     liTable._isRelatedViewer = true;
140
141     prepareButtons();
142     fetchRelated();
143 }
144
145 openils.Util.addOnLoad(load);