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');
18 var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
19 var cgi = new openils.CGI();
23 if (cgi.param('eg_bib')) {
24 changeBib(cgi.param('eg_bib'));
27 if (cgi.param('lineitem')) {
28 changeLI(cgi.param('lineitem'));
31 if (cgi.param('usr')) {
32 var usr_obj = fieldmapper.standardRequest(
35 'open-ils.actor.user.fleshed.retrieve.authoritative'
38 params: [openils.User.authtoken, cgi.param('usr')]
41 if (typeof usr_obj.textcode == 'undefined') {
42 changeUser(usr_obj.id(),usr_obj.card().barcode());
44 alert(usr_obj.textcode + ' : ' + usr_obj.desc);
55 function drawRequest() {
56 var pcrud = new openils.PermaCrud({ authtoken : openils.User.authtoken });
57 aur_obj = pcrud.retrieve('aur',reqId);
59 // hide the grid and the context selector
60 dijit.byId('stackContainer').forward();
62 // purge any previous lineitem display
63 // FIXME: I thought it would be cool to have this, but I can't get it
64 // to look right with our dojo div/contentPanes. So just testing for
65 // a DOM hook for now.
66 if (dojo.byId('lineitem')) {
67 //openils.Util.hide( 'lineitem_container' );
68 dojo.byId('lineitem').innerHTML = '';
71 // toggle the View Picklist/Add to Picklist button label
72 if (aur_obj.lineitem()) {
73 openils.Util.hide( 'add_to_picklist' );
74 openils.Util.show( 'view_picklist' );
76 openils.Util.hide( 'view_picklist' );
77 openils.Util.show( 'add_to_picklist' );
80 // draw a detail page for a particular request
81 var div = document.getElementById('detail_content_pane');
82 while (div.lastChild) { div.removeChild( div.lastChild ); }
83 var pane = new openils.widget.EditPane({
88 pane.hideActionButtons = true;
92 if (dojo.byId('lineitem') && aur_obj.lineitem()) {
93 //openils.Util.show( 'lineitem_container' );
94 openils.acq.Lineitem.fetchAndRender(aur_obj.lineitem(), {},
96 dojo.byId('lineitem').innerHTML = html;
101 // including ability to add request to a picklist
102 // and to "reject" it (aka apply a cancel reason)
104 dojo.byId("acq-ur-cancel-reason").innerHTML = '';
105 var widget = new openils.widget.AutoFieldWidget({
106 "fmField": "cancel_reason",
108 "parentNode": dojo.byId("acq-ur-cancel-reason"),
109 "orgLimitPerms": ["CREATE_PURCHASE_REQUEST"],
115 acqUrCancelReasonSubmit.onClick = function() {
116 if (w.attr("value")) {
117 if (confirm( localeStrings.UR_CANCEL_CONFIRM )) {
118 fieldmapper.standardRequest(
119 [ 'open-ils.acq', 'open-ils.acq.user_request.cancel.batch' ],
121 params: [openils.User.authtoken, [reqId], w.attr("value")],
122 oncomplete: function(r) {
123 location.href = location.href; // kludge to reload the interface
134 function fooPicklist() {
135 if (aur_obj.lineitem()) {
142 function viewPicklist() {
143 var lineitem = fieldmapper.standardRequest(
144 [ 'open-ils.acq', 'open-ils.acq.lineitem.retrieve.authoritative' ],
146 params: [openils.User.authtoken, aur_obj.lineitem()]
149 location.href = oilsBasePath + "/acq/picklist/view/" + lineitem.picklist();
152 function addToPicklist() {
153 // reqId, from detail view
154 location.href = oilsBasePath + "/acq/picklist/brief_record?ur=" + reqId + "&prepop=" + encodeURIComponent(js2JSON({
155 "1": aur_obj.title() || aur_obj.article_title() || aur_obj.volume(),
156 "2": aur_obj.author(),
158 "9": aur_obj.publisher(),
159 "10": aur_obj.pubdate()
163 function setNoHold() {
164 // reqId, from detail view
165 fieldmapper.standardRequest(
166 [ 'open-ils.acq', 'open-ils.acq.user_request.set_no_hold.batch' ],
168 params: [openils.User.authtoken, [reqId]],
169 oncomplete: function(r) {
170 location.href = location.href; // kludge to reload the interface
176 // format the title data as id:title
177 function getTitle(idx, item) {
179 return this.grid.store.getValue(item, 'id') + ':' +
180 this.grid.store.getValue(item, 'title');
185 // turn id:title into a url
186 function formatTitle(value) {
188 var parts = value.split(/:/);
189 return '<a href="' + oilsBasePath +
190 '/acq/picklist/user_request/' + parts[0] + '">' + parts[1] + '</a>';
194 function drawList() {
197 var connect = function() {
198 dojo.connect(contextOrgSelector, 'onChange',
200 contextOrg = this.attr('value');
207 new openils.User().buildPermOrgSelector(
208 'CREATE_PICKLIST', contextOrgSelector, null, connect);
211 function buildGrid() {
213 if(contextOrg == null)
214 contextOrg = openils.User.user.ws_ou();
217 cancel_reason : null,
219 home_ou : fieldmapper.aou.descendantNodeList(contextOrg).map(
220 function(item) { return item.id(); })
225 delete query['+au']['home_ou'];
226 query['+au']['id'] = contextUsr;
230 query['eg_bib'] = contextEg_bib;
234 query['lineitem'] = contextLI;
239 { order_by : {aur : 'request_date'},
246 function changeBib(value) {
247 contextEg_bib = value;
248 rGrid.overrideEditWidgets.eg_bib = new dijit.form.TextBox({"disabled": true});
249 rGrid.overrideEditWidgets.eg_bib.shove = { create : contextEg_bib };
252 function changeLI(value,display_value) {
254 contextLITextbox.setValue( contextLI );
255 contextLITextbox.setDisplayedValue( display_value || contextLI );
256 rGrid.overrideEditWidgets.lineitem = new dijit.form.TextBox({"disabled": true});
257 rGrid.overrideEditWidgets.lineitem.shove = { create : contextLI };
260 function changeLIPrompt() {
261 var lineitem = window.prompt(localeStrings.UR_FILTER_LINEITEM);
262 if(lineitem != '' && (lineitem == null || Number(lineitem) == NaN)) {
269 function changeUser(value,display_value) {
271 contextUsrTextbox.setValue( contextUsr );
272 contextUsrTextbox.setDisplayedValue( display_value || contextUsr );
273 rGrid.overrideEditWidgets.usr = new dijit.form.TextBox({"disabled": true});
274 rGrid.overrideEditWidgets.usr.shove = { create : contextUsr };
277 function changeUserPrompt() {
278 var barcode = window.prompt(localeStrings.UR_FILTER_USER);
279 if(barcode == null) {
282 if(typeof xulG != 'undefined' && xulG.get_barcode) {
283 // We have a "complete the barcode" function, call it (actor = users only)
284 var new_barcode = xulG.get_barcode(window, 'actor', barcode);
285 // If we got a result (boolean false is "no result") check it
287 // user_false string means they picked "None of the above"
288 // Abort before any other events can fire
289 if(new_barcode == "user_false") return;
290 // No error means we have a (hopefully valid) completed barcode to use.
291 // Otherwise, fall through to other methods of checking
292 if(typeof new_barcode.ilsevent == 'undefined')
293 barcode = new_barcode.barcode;
299 var usr_obj = fieldmapper.standardRequest(
302 'open-ils.actor.user.fleshed.retrieve_by_barcode.authoritative'
305 params: [openils.User.authtoken, barcode]
308 if (typeof usr_obj.textcode != 'undefined') {
309 alert(usr_obj.textcode + ' : ' + usr_obj.desc);
312 changeUser(usr_obj.id(),usr_obj.card().barcode());
318 openils.Util.addOnLoad(setup);