1 dojo.require("openils.User");
2 dojo.require("openils.PermaCrud");
3 dojo.require("fieldmapper.OrgUtils");
4 dojo.require("openils.widget.OrgUnitFilteringSelect");
5 dojo.requireLocalization("openils.booking", "pull_list");
7 var localeStrings = dojo.i18n.getLocalization("openils.booking", "pull_list");
8 var pcrud = new openils.PermaCrud();
10 var owning_lib_selected;
13 function init_owning_lib_selector() {
14 var User = new openils.User();
15 User.buildPermOrgSelector(
16 "RETRIEVE_RESERVATION_PULL_LIST", owning_lib_selector, null,
18 owning_lib_selected = owning_lib_selector.getValue();
19 dojo.connect(owning_lib_selector, "onChange",
20 function() { owning_lib_selected = this.getValue(); }
26 function retrieve_pull_list(ivl_in_days) {
27 var secs = Number(ivl_in_days) * 86400;
29 if (isNaN(secs) || secs < 1)
30 throw new Error("Invalid interval");
32 return fieldmapper.standardRequest(
33 ["open-ils.booking", "open-ils.booking.reservations.get_pull_list"],
34 [xulG.auth.session.key, null, secs, owning_lib_selected]
38 function dom_table_rowid(resource_id) {
39 return "pull_list_resource_" + resource_id;
42 function generate_result_row(one) {
43 function cell(id, content) {
44 var td = document.createElement("td");
45 if (id != undefined) td.setAttribute("id", id);
46 td.appendChild(document.createTextNode(content));
50 function reservation_info_cell(one) {
51 var td = document.createElement("td");
52 for (var i in one.reservations) {
53 var one_resv = one.reservations[i];
54 var div = document.createElement("div");
55 var s = humanize_timestamp_string(one_resv.start_time()) + " - " +
56 humanize_timestamp_string(one_resv.end_time()) + " " +
57 formal_name(one_resv.usr());
58 /* FIXME: The above need patron barcode instead of name, but
59 * that requires a fix in the middle layer to flesh on the
61 div.appendChild(document.createTextNode(s));
67 var baseid = dom_table_rowid(one.current_resource.id());
70 cells.push(cell(undefined, one.target_resource_type.name()));
71 cells.push(cell(undefined, one.current_resource.barcode()));
72 cells.push(cell(baseid + "_call_number", "-"));
73 cells.push(cell(baseid + "_copy_location", "-"));
74 cells.push(cell(baseid + "_copy_number", "-"));
75 cells.push(reservation_info_cell(one));
77 var row = document.createElement("tr");
78 row.setAttribute("id", baseid);
80 for (var i in cells) row.appendChild(cells[i]);
84 function render_pull_list_fundamentals(list) {
88 rows.push(generate_result_row(list[i]));
90 document.getElementById("the_table_body").innerHTML = "";
93 document.getElementById("the_table_body").appendChild(rows[i]);
96 function get_all_relevant_acp(list) {
99 if (list[i].target_resource_type.catalog_item()) {
100 /* There shouldn't be any duplicates. No need to worry bout that */
101 barcodes.push(list[i].current_resource.barcode());
104 if (barcodes.length > 0) {
105 var results = fieldmapper.standardRequest(
108 "open-ils.booking.asset.get_copy_fleshed_just_right"
110 [xulG.auth.session.key, barcodes]
114 alert(localeStrings.COPY_LOOKUP_NO_RESPONSE);
116 } else if (is_ils_event(results)) {
117 alert(my_ils_error(localeStrings.COPY_LOOKUP_ERROR, results));
125 function fill_in_pull_list_details(list, acp_cache) {
126 for (var i in list) {
128 if (one.target_resource_type.catalog_item() == "t") {
129 /* FIXME: This block could stand to be a lot more elegant. */
130 var call_number_el = document.getElementById(
131 dom_table_rowid(one.current_resource.id()) + "_call_number"
133 var copy_location_el = document.getElementById(
134 dom_table_rowid(one.current_resource.id()) + "_copy_location"
136 var copy_number_el = document.getElementById(
137 dom_table_rowid(one.current_resource.id()) + "_copy_number"
140 var bc = one.current_resource.barcode();
143 if (call_number_el && acp_cache[bc].call_number()) {
144 var value = acp_cache[bc].call_number().label();
145 if (value) call_number_el.innerHTML = value;
147 if (copy_location_el && acp_cache[bc].location()) {
148 var value = acp_cache[bc].location().name();
149 if (value) copy_location_el.innerHTML = value;
151 if (copy_number_el) {
152 var value = acp_cache[bc].copy_number();
153 if (value) copy_number_el.innerHTML = value;
156 alert(localeStrings.COPY_MISSING + bc);
162 function populate_pull_list(form) {
163 /* Step 1: get the pull list from the server. */
165 var results = retrieve_pull_list(form.interval_in_days.value);
167 alert(localeStrings.PULL_LIST_ERROR + E);
170 if (results == null) {
171 alert(localeStrings.PULL_LIST_NO_RESPONSE);
173 } else if (is_ils_event(results)) {
174 alert(my_ils_error(localeStrings.PULL_LIST_ERROR, results));
178 if (results.length) {
179 reveal_dom_element(document.getElementById("table_goes_here"));
180 hide_dom_element(document.getElementById("no_results"));
182 /* Step 2: render the table with the pull list */
183 render_pull_list_fundamentals(results);
185 /* Step 3: asynchronously fill in the copy details we're missing */
186 setTimeout(function() {
188 if ((acp_cache = get_all_relevant_acp(results)))
189 fill_in_pull_list_details(results, acp_cache);
192 hide_dom_element(document.getElementById("table_goes_here"));
193 reveal_dom_element(document.getElementById("no_results"));
199 hide_dom_element(document.getElementById("table_goes_here"));
200 hide_dom_element(document.getElementById("no_results"));
201 init_owning_lib_selector();
202 init_auto_l10n(document.getElementById("auto_l10n_start_here"));