1 dojo.require("dojo.cookie");
2 dojo.require("dojox.xml.parser");
3 dojo.require("openils.BibTemplate");
4 dojo.require("openils.widget.ProgressDialog");
9 function do_pull_list() {
10 progress_dialog.show(true);
14 fieldmapper.standardRequest(
15 ['open-ils.circ','open-ils.circ.hold_pull_list.print.stream'],
19 org_id : cgi.param('o'),
20 limit : cgi.param('limit'),
21 offset : cgi.param('offset'),
22 chunk_size : cgi.param('chunk_size'),
26 onresponse : function (r) {
28 dojo.forEach( openils.Util.readResponse(r), function (hold_fm) {
31 var hold = hold_fm.toHash(true);
32 hold.usr = hold_fm.usr().toHash(true);
33 hold.usr.card = hold_fm.usr().card().toHash(true);
34 hold.current_copy = hold_fm.current_copy().toHash(true);
35 hold.current_copy.location = hold_fm.current_copy().location().toHash(true);
36 hold.current_copy.call_number = hold_fm.current_copy().call_number().toHash(true);
37 hold.current_copy.call_number.record = hold_fm.current_copy().call_number().record().toHash(true);
38 hold.current_copy.call_number.prefix = hold_fm.current_copy().call_number().prefix().toHash(true);
39 hold.current_copy.call_number.suffix = hold_fm.current_copy().call_number().suffix().toHash(true);
40 hold.current_copy.parts_stringified = '';
41 dojo.forEach( hold_fm.current_copy().parts(), function(part) {
42 hold.current_copy.parts_stringified += ' ' + part.label();
46 // clone the template's html
48 dojo.query("tr", dojo.byId('template'))[0]
50 dojo.query("td:not([type])", tr).forEach(
53 dojo.string.substitute(td.innerHTML, hold);
57 new openils.BibTemplate({
59 xml : dojox.xml.parser.parse(hold.current_copy.call_number.record.marc),
63 dojo.place(tr, "target");
66 oncomplete : function () {
67 progress_dialog.hide();
70 if (any) window.print();
71 else alert(dojo.byId("no_results").innerHTML);
72 }, 500 /* give the progress_dialog more time to go away */
79 function place_by_sortkey(node, container) {
80 /*Don't use a forEach() or anything like that here. too slow.*/
81 var sortkey = dojo.attr(node, "sortkey");
82 for (var i = 0; i < container.childNodes.length; i++) {
83 var rover = container.childNodes[i];
84 if (rover.nodeType != 1) continue;
85 if (dojo.attr(rover, "sortkey") > sortkey) {
86 dojo.place(node, rover, "before");
90 dojo.place(node, container, "last");
93 function hashify_fields(fields) {
97 "barcode": fields.barcode,
99 "label": fields.label,
100 "record": {"marc": fields.marc}
102 "location": {"name": fields.name}
107 hold.usr.display_name = fields.alias;
109 hold.usr.display_name = [
110 (fields.family_name ? fields.family_name : ""),
111 (fields.first_given_name ? fields.first_given_name : ""),
112 (fields.second_given_name ? fields.second_given_name : "")
116 ["first_given_name","second_given_name","family_name","alias"].forEach(
117 function(k) { hold.usr[k] = fields[k]; }
120 hold.current_copy.call_number.prefix = fields.prefix;
121 hold.current_copy.call_number.suffix = fields.suffix;
122 hold.current_copy.parts_stringified = ''; /* no real support for parts here */
126 function do_clear_holds() {
127 progress_dialog.show(true);
130 fieldmapper.standardRequest(
131 ["open-ils.circ", "open-ils.circ.hold.clear_shelf.process"], {
133 "params": [authtoken, cgi.param("o")],
134 "onresponse": function(r) {
135 if (r = openils.Util.readResponse(r)) {
136 if (r.cache_key) { /* complete */
137 launcher = dojo.byId("clear_holds_launcher");
138 launcher.innerHTML = "Re-fetch for Printing"; /* XXX i18n */
140 function() { do_clear_holds_from_cache(r.cache_key); };
141 dojo.byId("clear_holds_set_label").innerHTML = r.cache_key;
142 } else if (r.maximum) {
143 progress_dialog.update(r);
147 "oncomplete": function() {
148 progress_dialog.hide();
149 if (launcher) launcher.onclick();
150 else alert(dojo.byId("no_results").innerHTML);
156 function do_clear_holds_from_cache(cache_key) {
157 progress_dialog.show(true);
160 var target = dojo.byId("target");
162 var template = dojo.query("tr", dojo.byId("template"))[0];
163 fieldmapper.standardRequest(
165 "open-ils.circ.hold.clear_shelf.get_cache"], {
167 "params": [authtoken, cache_key, cgi.param("chunk_size")],
168 "onresponse": function(r) {
170 openils.Util.readResponse(r),
173 progress_dialog.update(resp);
177 var hold = hashify_fields(resp.hold_details);
178 hold.action = resp.action;
180 var tr = dojo.clone(template);
183 dojo.query("td:not([type])", tr).forEach(
186 dojo.string.substitute(td.innerHTML, hold);
190 new openils.BibTemplate({
192 "xml": dojox.xml.parser.parse(
193 hold.current_copy.call_number.record.marc
198 dojo.attr(tr, "sortkey", hold.usr.display_name);
199 place_by_sortkey(tr, target);
202 progress_dialog.update({"progress": any});
204 "oncomplete": function() {
205 progress_dialog.hide();
208 if (any) window.print();
209 else alert(dojo.byId("no_results").innerHTML);
210 }, 500 /* give the progress_dialog more time to go away */