]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/lineitem/related.js
Acq: always show "add to new selection list" / "create new PO" buttons in
[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         }
56     );
57 }
58
59 function fetchBib() {
60     new openils.BibTemplate({ 
61         record : targetId, 
62         org_unit : fieldmapper.aou.findOrgUnit(openils.User.user.ws_ou()).shortname()
63     }).render();
64
65     new openils.PermaCrud().retrieve('bre', targetId, {
66         oncomplete : function(r) {
67             bibRecord = openils.Util.readResponse(r);
68             // render bib details
69             // perhaps we just pull these from the beating heart of bibtemplate
70         }
71     }) 
72 }
73
74 function createLi(oncomplete) {
75     return function() {
76         progressDialog.show();
77         liTable.reset();
78         fieldmapper.standardRequest(
79             ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
80                 "params": [
81                     openils.User.authtoken, [bibRecord.id()], {
82                         "flesh_attrs": true,
83                         "flesh_cancel_reason": true,
84                         "flesh_notes": true
85                     }
86                 ],
87                 "async": true,
88                 "onresponse": function(r) {
89                     var li = openils.Util.readResponse(r);
90                     if (typeof(li) == "object") {
91                         liTable.show("list");
92                         liTable.addLineitem(li);
93                         dojo.query(
94                             "input[name='selectbox']", liTable._findLiRow(li)
95                         )[0].checked = true;
96                     }
97                 },
98                 "oncomplete": function() {
99                     progressDialog.hide();
100                     oncomplete();
101                 }
102             }
103         );
104     };
105 }
106
107 function prepareButtons() {
108     addToPlButton.onClick = createLi(
109         function() { /* oncomplete */
110             liTable._loadPLSelect(paramPL);
111             acqLitSavePlDialog.show();
112         }
113     );
114     createPoButton.onClick = createLi(
115         function() { /* oncomplete */
116             liTable._loadPOSelect();
117             acqLitPoCreateDialog.show();
118         }
119     );
120 }
121
122 function load() {
123     var cgi = new openils.CGI();
124
125     identTarget = cgi.param('target');
126     paramPL = cgi.param('pl');
127 //    paramPO = cgi.param('po');
128
129     if (identTarget == 'bib') {
130         fetchBib();
131     } else {
132         fetchLi(); 
133     }
134
135     liTable = new AcqLiTable();
136     liTable.reset();
137     liTable._isRelatedViewer = true;
138
139     prepareButtons();
140     fetchRelated();
141 }
142
143 openils.Util.addOnLoad(load);