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