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('openils.widget.PCrudAutocompleteBox');
8 dojo.require('fieldmapper.OrgUtils');
10 dojo.requireLocalization('openils.acq', 'acq');
11 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
20 fieldmapper.standardRequest(
21 ["open-ils.acq", "open-ils.acq.lineitem.retrieve.authoritative"], {
23 "params": [openils.User.authtoken, targetId, {
25 "flesh_li_details": true,
26 "flesh_fund_debit": true,
27 "flesh_cancel_reason": true
29 "oncomplete": function(r) {
30 var li = openils.Util.readResponse(r);
31 fetchBib(li.eg_bib_id());
38 function fetchRelated() {
39 var method = 'open-ils.acq.lineitems_for_bib.by_lineitem_id';
40 if(identTarget == 'bib')
41 var method = 'open-ils.acq.lineitems_for_bib.by_bib_id';
44 fieldmapper.standardRequest(
45 ["open-ils.acq", method], {
47 "params": [openils.User.authtoken, targetId, {
50 "flesh_cancel_reason": true
52 "onresponse": function(r) {
53 var resp = openils.Util.readResponse(r);
57 liTable.addLineitem(resp);
64 function fetchBib(bibId) {
65 bibId = bibId || targetId;
66 new openils.BibTemplate({
68 org_unit : fieldmapper.aou.findOrgUnit(openils.User.user.ws_ou()).shortname()
71 new openils.PermaCrud().retrieve('bre', bibId, {
72 oncomplete : function(r) {
73 bibRecord = openils.Util.readResponse(r);
75 // perhaps we just pull these from the beating heart of bibtemplate
80 function createLi(oncomplete) {
82 progressDialog.show();
84 fieldmapper.standardRequest(
85 ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
87 openils.User.authtoken, [bibRecord.id()], {
89 "flesh_cancel_reason": true,
94 "onresponse": function(r) {
95 var li = openils.Util.readResponse(r);
96 if (typeof(li) == "object") {
98 liTable.addLineitem(li);
100 "input[name='selectbox']", liTable._findLiRow(li)
104 "oncomplete": function() {
105 progressDialog.hide();
113 function prepareButtons() {
114 addToPlButton.onClick = createLi(
115 function() { /* oncomplete */
116 acqLitSavePlDialog.show();
119 addToPoButton.onClick = createLi(
120 function() { /* oncomplete */
121 addToPoDialog.show();
124 createPoButton.onClick = createLi(
125 function() { /* oncomplete */
126 liTable._loadPOSelect();
127 acqLitPoCreateDialog.show();
133 var cgi = new openils.CGI();
135 identTarget = cgi.param('target');
136 paramPL = cgi.param('pl');
137 // paramPO = cgi.param('po');
139 if (identTarget == 'bib') {
145 liTable = new AcqLiTable();
146 liTable.enableActionsDropdownOptions("vp");
148 liTable._isRelatedViewer = true;
150 // render the batch updater to activate fund selection, but leave
151 // it hidden for now since it's not fully functional in this UI.
152 liTable.initBatchUpdater(null, true);
157 /* addToPoDialog now requires this function be defined to tell it what
158 * lineitem IDs to add to the PO. Part of making it reusable in more
160 addToPoDialog._get_li = function() {
161 return liTable.getSelected()[0].id();
165 openils.Util.addOnLoad(load);