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 var r = grabUserByBarcode(this.session, recip_barcode);
68 //debug("Done grabbing user");
71 } catch(E) { if(E.err_msg) alert(E.err_msg()); else alert(E); }
75 hold.pickup_lib(org.id());
76 hold.requestor(this.requestor.id());
77 hold.usr(this.recipient.id());
78 hold.hold_type(this.type);
79 hold.email_notify(email);
80 hold.phone_notify(phone);
82 if(this.type == "M") hold.holdable_formats(formats);
83 hold.target(this.record);
85 var req = new RemoteRequest(
87 "open-ils.circ.holds.create",
91 var res = req.getResultObject();
93 alert("Hold request was succesfully submitted");
97 /* returns false if we don't have a recipient for the hold */
98 HoldsWindow.prototype.buildWindow = function(node) {
100 if(this.built) return true;
102 var id = this.record;
104 var usr = this.recipient;
105 var barcodediv = null;
108 /* used by xul to enter the recipient barcode */
110 var barcodediv = elem("div",{style:"margin-left: 10px"},null,"2. Enter User Barcode");
111 var barcodebox = elem("input",{style:"margin-left: 10px;", type:"text",id:"recipient_barcode"});
112 barcodediv.appendChild(barcodebox);
113 barcodediv.appendChild(elem("br"));
119 var func = function(usr) {
120 obj.recipient = usr.userObject;
121 obj.requestor = usr.userObject;
122 obj.session = usr.session_id;
125 var diag = new LoginDialog(func);
133 var org = usr.home_ou();
134 d.appendChild(this.buildPickuplibSelector(org));
137 d.appendChild(this.buildResourceSelector());
140 d.appendChild(elem("br"));
141 d.appendChild(barcodediv);
144 d.appendChild(this.buildSubmit());
146 this.div.appendChild(d);
151 HoldsWindow.prototype.toggle = function(node) {
153 debug("Building window with node " + node);
155 if(!this.buildWindow(node)) return;
157 swapClass( this.div, "hide_me", "show_me" );
160 /* workaround for IE select box widget bleed through, blegh... */
163 var sels = getDocument().getElementsByTagName("select");
164 if(sels.length == 0) return true;
166 if(this.div.className.indexOf("hide_me") != -1) {
167 for(var i = 0; i!= sels.length; i++) {
169 if(s && s.id != "holds_org_selector") {
170 remove_css_class(s, "invisible");
171 add_css_class(s, "visible");
176 if(this.div.className.indexOf("show_me") != -1) {
177 for(var i = 0; i!= sels.length; i++) {
179 if(s && s.id != "holds_org_selector") {
180 remove_css_class(s, "visible");
181 add_css_class(s, "invisible");
193 HoldsWindow.prototype.buildHoldsWindowCallback = function(type) {
196 var func = function() {
198 var wrapper = elem("div");
199 var id = hwindow.record.doc_id();
201 var org = UserSession.instance().userObject.home_ou();
202 wrapper.appendChild(hwindow.buildPickuplibSelector(org));
204 wrapper.appendChild(hwindow.buildResourceSelector());
205 wrapper.appendChild(hwindow.buildSubmit());
207 hwindow.win = window.open(null,"PLACE_HOLD_" + id,
208 "location=0,menubar=0,status=0,resizeable,resize," +
209 "outerHeight=500,outerWidth=500,height=500," +
210 "width=500,scrollbars=1," +
211 "alwaysraised, chrome" )
213 hwindow.win.document.write("<html>" + wrapper.innerHTML + "</html>");
214 hwindow.win.document.close();
215 hwindow.win.document.title = "View MARC";
223 HoldsWindow.prototype.buildSubmit = function() {
224 var div = elem("div");
228 var bdiv = elem("div",
230 "border-top: 1px solid lightgrey;" +
231 "border-bottom: 1px solid lightgrey;" +
232 "width:100%;text-align:center;"});
235 var bdiv = elem("div");
236 add_css_class(bdiv, "holds_window_buttons");
238 var button = elem("input",
239 {type:"submit", style:"margin-right: 10px;", value:"Place Hold"});
241 var cancel = elem("input",
242 {type:"submit", style:"margin-left: 10px;",value:"Cancel"});
245 cancel.onclick = function() { obj.toggle(); }
246 button.onclick = function() { obj.toggle(); obj.process(); }
248 div.appendChild(elem("br"));
249 bdiv.appendChild(button);
250 bdiv.appendChild(cancel);
251 div.appendChild(bdiv);
256 /* builds a selecor where the client can select the location to which
258 HoldsWindow.prototype.buildPickuplibSelector = function(selected_id) {
260 var div = elem("div");
261 var tdiv = elem("div",{style:"margin-left:10px"}, null,
262 "1. Select the location where the item(s) shall be delivered");
264 var sdiv = elem("div");
265 var selector = elem("select",{id:"holds_org_selector"});
267 /* this is not copied over... XXX fix me */
268 selector.onchange = function() {
269 var idx = selector.selectedIndex;
270 var option = selector.options[idx];
271 var org = findOrgUnit(option.value);
273 var d = getById("selector_error_div");
274 if(d) div.removeChild(d);
276 if(parseInt(findOrgType(org.ou_type()).depth()) < 2) {
277 var err = elem("div",
278 {id:"selector_error_div", style:"color:red"},null,
279 org.name() + " is a library system, please select a single branch");
280 div.appendChild(err);
285 var center = elem("center");
286 center.appendChild(selector);
287 sdiv.appendChild(center);
288 _buildOrgList(selector, selected_id, null);
290 div.appendChild(elem("br"));
291 div.appendChild(tdiv);
292 div.appendChild(elem("br"));
293 div.appendChild(sdiv);
297 /* utility function for building a org list selector object */
298 function _buildOrgList(selector, selected_id, org) {
300 if(selected_id == null) selected_id = -1;
305 } else { /* add the org to the list */
306 var index = selector.options.length;
308 var node = elem("pre");
309 for(var x=2; x <= findOrgType(org.ou_type()).depth(); x++) {
310 node.appendChild(mktext(" "));
312 node.appendChild(mktext(org.name()));
313 var select = new Option("", org.id());
314 selector.options[index] = select;
315 select.appendChild(node);
318 var pad = (findOrgType(org.ou_type()).depth() - 1) * 12;
319 var select = new Option(org.name(), org.id());
320 select.setAttribute("style", "padding-left: " + pad);
321 selector.options[index] = select;
324 if(parseInt(org.id()) == parseInt(selected_id)) {
325 selector.selectedIndex = index;
326 selector.options[index].selected = true;
330 for(var idx in org.children())
331 _buildOrgList(selector, selected_id, org.children()[idx]);
334 HoldsWindow.prototype.buildResourceSelector = function() {
337 var big_div = elem('div', {style:"margin-left: 10px;"});
339 var desc_div = elem("div",null, null,
340 "2. Select all acceptible item formats");
343 var table = elem("table");
345 for( var idx in resourceFormats ) {
346 var row = table.insertRow(table.rows.length)
348 var pic_cell = row.insertCell(0);
349 var name_cell = row.insertCell(1);
350 var box_cell = row.insertCell(2);
351 var box = elem("input",
352 {type:"checkbox", id: resourceFormats[idx] + "_hold_checkbox"}, null);
354 if(idx == 0) { /* select text by default */
355 box.setAttribute("checked","checked");
359 pic_cell.appendChild(mkResourceImage(resourceFormats[idx]));
360 name_cell.appendChild(mktext(resourceFormats[idx]));
361 box_cell.appendChild(mktext(" "));
362 box_cell.appendChild(box);
365 big_div.appendChild(elem("br"));
366 big_div.appendChild(desc_div);
367 big_div.appendChild(elem("br"));
368 big_div.appendChild(table);