1 dojo.require('openils.CGI');
2 dojo.require('openils.Util');
3 dojo.require('openils.User');
4 dojo.require('openils.widget.AutoGrid');
5 dojo.require('fieldmapper.OrgUtils');
6 dojo.require('openils.widget.OrgUnitFilteringSelect');
7 dojo.require('openils.widget.EditPane');
8 dojo.require("dijit.layout.StackContainer");
9 dojo.require('openils.PermaCrud');
10 dojo.requireLocalization("openils.acq", "acq");
11 dojo.require('openils.acq.Lineitem');
19 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
20 var cgi = new openils.CGI();
24 if (cgi.param('eg_bib')) {
25 changeBib(cgi.param('eg_bib'));
28 if (cgi.param('lineitem')) {
29 changeLI(cgi.param('lineitem'));
32 if (cgi.param('usr')) {
33 var usr_obj = fieldmapper.standardRequest(
36 'open-ils.actor.user.fleshed.retrieve.authoritative'
39 params: [openils.User.authtoken, cgi.param('usr')]
42 if (typeof usr_obj.textcode == 'undefined') {
43 contextUsrObj = usr_obj;
44 changeUser(usr_obj.id(),usr_obj.card().barcode());
46 alert(usr_obj.textcode + ' : ' + usr_obj.desc);
57 function drawRequest() {
58 var pcrud = new openils.PermaCrud({ authtoken : openils.User.authtoken });
59 aur_obj = pcrud.retrieve('aur',reqId);
61 // hide the grid and the context selector
62 dijit.byId('stackContainer').forward();
64 // purge any previous lineitem display
65 // FIXME: I thought it would be cool to have this, but I can't get it
66 // to look right with our dojo div/contentPanes. So just testing for
67 // a DOM hook for now.
68 if (dojo.byId('lineitem')) {
69 //openils.Util.hide( 'lineitem_container' );
70 dojo.byId('lineitem').innerHTML = '';
73 // toggle the View Picklist/Add to Picklist button label
74 if (aur_obj.lineitem()) {
75 openils.Util.hide( 'add_to_picklist' );
76 openils.Util.show( 'view_picklist' );
78 openils.Util.hide( 'view_picklist' );
79 openils.Util.show( 'add_to_picklist' );
82 // draw a detail page for a particular request
83 var div = document.getElementById('detail_content_pane');
84 while (div.lastChild) { div.removeChild( div.lastChild ); }
85 var pane = new openils.widget.EditPane({
90 pane.hideActionButtons = true;
94 if (dojo.byId('lineitem') && aur_obj.lineitem()) {
95 //openils.Util.show( 'lineitem_container' );
96 openils.acq.Lineitem.fetchAndRender(aur_obj.lineitem(), {},
98 dojo.byId('lineitem').innerHTML = html;
103 // including ability to add request to a picklist
104 // and to "reject" it (aka apply a cancel reason)
106 dojo.byId("acq-ur-cancel-reason").innerHTML = '';
107 var widget = new openils.widget.AutoFieldWidget({
108 "fmField": "cancel_reason",
110 "parentNode": dojo.byId("acq-ur-cancel-reason"),
111 "orgLimitPerms": ["CREATE_PURCHASE_REQUEST"],
117 acqUrCancelReasonSubmit.onClick = function() {
118 if (w.attr("value")) {
119 if (confirm( localeStrings.UR_CANCEL_CONFIRM )) {
120 fieldmapper.standardRequest(
121 [ 'open-ils.acq', 'open-ils.acq.user_request.cancel.batch' ],
123 params: [openils.User.authtoken, [reqId], w.attr("value")],
124 oncomplete: function(r) {
125 location.href = location.href; // kludge to reload the interface
136 function fooPicklist() {
137 if (aur_obj.lineitem()) {
144 function viewPicklist() {
145 var lineitem = fieldmapper.standardRequest(
146 [ 'open-ils.acq', 'open-ils.acq.lineitem.retrieve.authoritative' ],
148 params: [openils.User.authtoken, aur_obj.lineitem()]
151 location.href = oilsBasePath + "/acq/picklist/view/" + lineitem.picklist();
154 function addToPicklist() {
155 // reqId, from detail view
156 location.href = oilsBasePath + "/acq/picklist/brief_record?ur=" + reqId + "&prepop=" + encodeURIComponent(js2JSON({
157 "1": aur_obj.title() || aur_obj.article_title() || aur_obj.volume(),
158 "2": aur_obj.author(),
160 "9": aur_obj.publisher(),
161 "10": aur_obj.pubdate()
165 function setNoHold() {
166 // reqId, from detail view
167 fieldmapper.standardRequest(
168 [ 'open-ils.acq', 'open-ils.acq.user_request.set_no_hold.batch' ],
170 params: [openils.User.authtoken, [reqId]],
171 oncomplete: function(r) {
172 location.href = location.href; // kludge to reload the interface
178 // format the title data as id:title
179 function getTitle(idx, item) {
181 return this.grid.store.getValue(item, 'id') + ':' +
182 this.grid.store.getValue(item, 'title');
187 // turn id:title into a url
188 function formatTitle(value) {
190 var parts = value.split(/:/);
191 return '<a href="' + oilsBasePath +
192 '/acq/picklist/user_request/' + parts[0] + '">' + parts[1] + '</a>';
196 function drawList() {
199 var connect = function() {
200 dojo.connect(contextOrgSelector, 'onChange',
202 contextOrg = this.attr('value');
209 new openils.User().buildPermOrgSelector(
210 'CREATE_PICKLIST', contextOrgSelector, null, connect);
213 function buildGrid() {
215 if(contextOrg == null)
216 contextOrg = openils.User.user.ws_ou();
219 cancel_reason : null,
221 home_ou : fieldmapper.aou.descendantNodeList(contextOrg).map(
222 function(item) { return item.id(); })
227 delete query['+au']['home_ou'];
228 query['+au']['id'] = contextUsr;
232 query['eg_bib'] = contextEg_bib;
236 query['lineitem'] = contextLI;
241 { order_by : {aur : 'request_date'},
248 function changeBib(value) {
249 contextEg_bib = value;
250 rGrid.overrideEditWidgets.eg_bib = new dijit.form.TextBox({"disabled": true});
251 rGrid.overrideEditWidgets.eg_bib.shove = { create : contextEg_bib };
254 function changeLI(value,display_value) {
256 contextLITextbox.setValue( contextLI );
257 contextLITextbox.setDisplayedValue( display_value || contextLI );
258 rGrid.overrideEditWidgets.lineitem = new dijit.form.TextBox({"disabled": true});
259 rGrid.overrideEditWidgets.lineitem.shove = { create : contextLI };
262 function changeLIPrompt() {
263 var lineitem = window.prompt(localeStrings.UR_FILTER_LINEITEM);
264 if(lineitem != '' && (lineitem == null || Number(lineitem) == NaN)) {
271 function changeUser(value,display_value) {
273 contextUsrTextbox.setValue( contextUsr );
274 contextUsrTextbox.setDisplayedValue( display_value || contextUsr );
275 rGrid.overrideEditWidgets.usr = new dijit.form.TextBox({"disabled": true});
276 rGrid.overrideEditWidgets.usr.shove = { create : contextUsr };
279 function changeUserPrompt() {
280 var barcode = window.prompt(localeStrings.UR_FILTER_USER);
281 if(barcode == null) {
284 if(typeof xulG != 'undefined' && xulG.get_barcode) {
285 // We have a "complete the barcode" function, call it (actor = users only)
286 var new_barcode = xulG.get_barcode(window, 'actor', barcode);
287 // If we got a result (boolean false is "no result") check it
289 // user_false string means they picked "None of the above"
290 // Abort before any other events can fire
291 if(new_barcode == "user_false") return;
292 // No error means we have a (hopefully valid) completed barcode to use.
293 // Otherwise, fall through to other methods of checking
294 if(typeof new_barcode.ilsevent == 'undefined')
295 barcode = new_barcode.barcode;
299 contextUsrObj = null;
302 var usr_obj = fieldmapper.standardRequest(
305 'open-ils.actor.user.fleshed.retrieve_by_barcode.authoritative'
308 params: [openils.User.authtoken, barcode]
311 if (typeof usr_obj.textcode != 'undefined') {
312 alert(usr_obj.textcode + ' : ' + usr_obj.desc);
315 contextUsrObj = usr_obj;
316 changeUser(usr_obj.id(),usr_obj.card().barcode());
322 function createRequest() {
327 rGrid.overrideEditWidgets.pickup_lib = new dijit.form.TextBox({"disabled": true});
328 rGrid.overrideEditWidgets.pickup_lib.shove = { create : contextUsrObj.home_ou() };
329 rGrid.showCreateDialog();
333 openils.Util.addOnLoad(setup);