3 @param record the id of the target item
4 @param type is the hold level (M, T, V, C) for metarecord, title,
5 volume, and copy respectively.
6 @param requestor is the user object (fieldmapper) for the requestor
7 @param recipient is the user object (fieldmapper) for the hold recipient
8 role in the holds process
9 @param requestor_login is the login session of the hold requestor
11 function HoldsWindow(record, type, requestor, recipient, requestor_login) {
14 this.div = elem("div");
15 this.requestor = requestor;
16 this.recipient = recipient;
18 this.session = requestor_login;
21 add_css_class(this.div, "holds_window");
22 add_css_class(this.div, "hide_me");
23 getDocument().body.appendChild(this.div);
27 HoldsWindow.prototype.process = function() {
29 /* collect the checked items */
31 if(this.type == "M") {
32 for(var idx in resourceFormats) {
33 var form = resourceFormats[idx];
34 var item = getById( form + "_hold_checkbox");
36 formats += modsFormatToMARC(form);
40 if(formats.length == 0) {
41 alert("Please select at least one item format");
46 var sel = getById("holds_org_selector");
47 var orgNode = sel.options[sel.selectedIndex];
48 var org = findOrgUnit(orgNode.value);
51 var email = this.recipient.email();
52 var phone = this.recipient.day_phone();
54 this.sendHoldsRequest(formats, org, email, phone);
57 /* formats is a string of format characters, org is the
58 org unit used for delivery */
59 HoldsWindow.prototype.sendHoldsRequest = function(formats, org, email, phone) {
61 if(isXUL()) { /* staff member entered barcode, now fetch the user */
62 var recip_barcode = getById("recipient_barcode").value;
63 if(!recip_barcode || recip_barcode == "") {
64 alert("Please enter the user's barcode");
67 this.recipient = grabUserByBarcode(recip_barcode);
68 } catch(E) { alert(E.err_msg()); }
72 hold.pickup_lib(org.id());
73 hold.requestor(this.requestor.id());
74 hold.usr(this.recipient.id());
75 hold.hold_type(this.type);
76 hold.email_notify(email);
77 hold.phone_notify(phone);
79 if(this.type == "M") hold.holdable_formats(formats);
80 hold.target(this.record);
82 var req = new RemoteRequest(
84 "open-ils.circ.holds.create",
88 var res = req.getResultObject();
90 alert("Hold request was succesfully submitted");
94 /* returns false if we don't have a recipient for the hold */
95 HoldsWindow.prototype.buildWindow = function(node) {
97 if(this.built) return true;
101 var usr = this.recipient;
102 var barcodebox = null;
105 /* used by xul to enter the recipient barcode */
106 barcodebox = elem("input",{type:"text",id:"recipient_barcode"});
111 var func = function(usr) {
112 obj.recipient = usr.userObject;
113 obj.requestor = usr.userObject;
114 obj.session = usr.session_id;
117 var diag = new LoginDialog(func);
125 var org = usr.home_ou();
126 d.appendChild(this.buildPickuplibSelector(org));
129 d.appendChild(this.buildResourceSelector());
132 d.appendChild(barcodebox);
134 d.appendChild(this.buildSubmit());
136 this.div.appendChild(d);
141 HoldsWindow.prototype.toggle = function(node) {
143 debug("Building window with node " + node);
145 if(!this.buildWindow(node)) return;
147 swapClass( this.div, "hide_me", "show_me" );
150 /* workaround for IE select box widget bleed through, blegh... */
153 var sels = getDocument().getElementsByTagName("select");
154 if(sels.length == 0) return true;
156 if(this.div.className.indexOf("hide_me") != -1) {
157 for(var i = 0; i!= sels.length; i++) {
159 if(s && s.id != "holds_org_selector") {
160 remove_css_class(s, "invisible");
161 add_css_class(s, "visible");
166 if(this.div.className.indexOf("show_me") != -1) {
167 for(var i = 0; i!= sels.length; i++) {
169 if(s && s.id != "holds_org_selector") {
170 remove_css_class(s, "visible");
171 add_css_class(s, "invisible");
183 HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
186 var func = function() {
188 var wrapper = elem("div");
189 var id = hwindow.record.doc_id();
191 var org = UserSession.instance().userObject.home_ou();
192 wrapper.appendChild(hwindow.buildPickuplibSelector(org));
194 wrapper.appendChild(hwindow.buildResourceSelector());
195 wrapper.appendChild(hwindow.buildSubmit());
197 hwindow.win = window.open(null,"PLACE_HOLD_" + id,
198 "location=0,menubar=0,status=0,resizeable,resize," +
199 "outerHeight=500,outerWidth=500,height=500," +
200 "width=500,scrollbars=1," +
201 "alwaysraised, chrome" )
203 hwindow.win.document.write("<html>" + wrapper.innerHTML + "</html>");
204 hwindow.win.document.close();
205 hwindow.win.document.title = "View MARC";
213 HoldsWindow.prototype.buildSubmit = function() {
214 var div = elem("div");
218 var bdiv = elem("div",
220 "border-top: 1px solid lightgrey;" +
221 "border-bottom: 1px solid lightgrey;" +
222 "width:100%;text-align:center;"});
225 var bdiv = elem("div");
226 add_css_class(bdiv, "holds_window_buttons");
228 var button = elem("input",
229 {type:"submit", style:"margin-right: 10px;", value:"Place Hold"});
231 var cancel = elem("input",
232 {type:"submit", style:"margin-left: 10px;",value:"Cancel"});
235 cancel.onclick = function() { obj.toggle(); }
236 button.onclick = function() { obj.toggle(); obj.process(); }
238 div.appendChild(elem("br"));
239 bdiv.appendChild(button);
240 bdiv.appendChild(cancel);
241 div.appendChild(bdiv);
246 /* builds a selecor where the client can select the location to which
248 HoldsWindow.prototype.buildPickuplibSelector = function(selected_id) {
250 var div = elem("div");
251 var tdiv = elem("div",{style:"margin-left:10px"}, null,
252 "1. Select the location where the item(s) shall be delivered");
254 var sdiv = elem("div");
255 var selector = elem("select",{id:"holds_org_selector"});
257 /* this is not copied over... XXX fix me */
258 selector.onchange = function() {
259 var idx = selector.selectedIndex;
260 var option = selector.options[idx];
261 var org = findOrgUnit(option.value);
263 var d = getById("selector_error_div");
264 if(d) div.removeChild(d);
266 if(parseInt(findOrgType(org.ou_type()).depth()) < 2) {
267 var err = elem("div",
268 {id:"selector_error_div", style:"color:red"},null,
269 org.name() + " is a library system, please select a single branch");
270 div.appendChild(err);
275 var center = elem("center");
276 center.appendChild(selector);
277 sdiv.appendChild(center);
278 _buildOrgList(selector, selected_id, null);
280 div.appendChild(elem("br"));
281 div.appendChild(tdiv);
282 div.appendChild(elem("br"));
283 div.appendChild(sdiv);
287 /* utility function for building a org list selector object */
288 function _buildOrgList(selector, selected_id, org) {
290 if(selected_id == null) selected_id = -1;
295 } else { /* add the org to the list */
296 var index = selector.options.length;
298 var node = elem("pre");
299 for(var x=2; x <= findOrgType(org.ou_type()).depth(); x++) {
300 node.appendChild(mktext(" "));
302 node.appendChild(mktext(org.name()));
303 var select = new Option("", org.id());
304 selector.options[index] = select;
305 select.appendChild(node);
308 var pad = (findOrgType(org.ou_type()).depth() - 1) * 12;
309 var select = new Option(org.name(), org.id());
310 select.setAttribute("style", "padding-left: " + pad);
311 selector.options[index] = select;
314 if(parseInt(org.id()) == parseInt(selected_id)) {
315 selector.selectedIndex = index;
316 selector.options[index].selected = true;
320 for(var idx in org.children())
321 _buildOrgList(selector, selected_id, org.children()[idx]);
324 HoldsWindow.prototype.buildResourceSelector = function() {
327 var big_div = elem('div', {style:"margin-left: 10px;"});
329 var desc_div = elem("div",null, null,
330 "2. Select all acceptible item formats");
333 var table = elem("table");
335 for( var idx in resourceFormats ) {
336 var row = table.insertRow(table.rows.length)
338 var pic_cell = row.insertCell(0);
339 var name_cell = row.insertCell(1);
340 var box_cell = row.insertCell(2);
341 var box = elem("input",
342 {type:"checkbox", id: resourceFormats[idx] + "_hold_checkbox"}, null);
344 if(idx == 0) { /* select text by default */
345 box.setAttribute("checked","checked");
349 pic_cell.appendChild(mkResourceImage(resourceFormats[idx]));
350 name_cell.appendChild(mktext(resourceFormats[idx]));
351 box_cell.appendChild(mktext(" "));
352 box_cell.appendChild(box);
355 big_div.appendChild(elem("br"));
356 big_div.appendChild(desc_div);
357 big_div.appendChild(elem("br"));
358 big_div.appendChild(table);