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 pickup_lib_selected;
13 function init_pickup_lib_selector() {
14 var User = new openils.User();
15 User.buildPermOrgSelector(
16 "RETRIEVE_RESERVATION_PULL_LIST", pickup_lib_selector, null,
18 pickup_lib_selected = pickup_lib_selector.getValue();
19 dojo.connect(pickup_lib_selector, "onChange",
20 function() { pickup_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, pickup_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 var results = fieldmapper.standardRequest(
107 "open-ils.booking.asset.get_copy_fleshed_just_right"
109 [xulG.auth.session.key, barcodes]
113 alert(localeStrings.COPY_LOOKUP_NO_RESPONSE);
115 } else if (is_ils_error(results)) {
116 alert(my_ils_error(localeStrings.COPY_LOOKUP_ERROR, results));
123 function fill_in_pull_list_details(list, acp_cache) {
124 for (var i in list) {
126 if (one.target_resource_type.catalog_item() == "t") {
127 /* FIXME: This block could stand to be a lot more elegant. */
128 var call_number_el = document.getElementById(
129 dom_table_rowid(one.current_resource.id()) + "_call_number"
131 var copy_location_el = document.getElementById(
132 dom_table_rowid(one.current_resource.id()) + "_copy_location"
134 var copy_number_el = document.getElementById(
135 dom_table_rowid(one.current_resource.id()) + "_copy_number"
138 var bc = one.current_resource.barcode();
141 if (call_number_el && acp_cache[bc].call_number()) {
142 var value = acp_cache[bc].call_number().label();
143 if (value) call_number_el.innerHTML = value;
145 if (copy_location_el && acp_cache[bc].location()) {
146 var value = acp_cache[bc].location().name();
147 if (value) copy_location_el.innerHTML = value;
149 if (copy_number_el) {
150 var value = acp_cache[bc].copy_number();
151 if (value) copy_number_el.innerHTML = value;
154 alert(localeStrings.COPY_MISSING + bc);
160 function populate_pull_list(form) {
161 /* Step 1: get the pull list from the server. */
163 var results = retrieve_pull_list(form.interval_in_days.value);
165 alert(localeStrings.PULL_LIST_ERROR + E);
168 if (results == null) {
169 alert(localeStrings.PULL_LIST_NO_RESPONSE);
171 } else if (is_ils_error(results)) {
172 alert(my_ils_error(localeStrings.PULL_LIST_ERROR, results));
176 /* Step 2: render the table with the pull list */
177 render_pull_list_fundamentals(results);
179 /* Step 3: asynchronously fill in the copy details we're missing */
180 setTimeout(function() {
182 if ((acp_cache = get_all_relevant_acp(results)))
183 fill_in_pull_list_details(results, acp_cache);
188 init_pickup_lib_selector();
189 init_auto_l10n(document.getElementById("auto_l10n_start_here"));