function load_sub_grid(id, oncomplete) {
if (!pcrud) return; /* first run, onLoad hasn't fired yet */
if (!sub_grid._fresh) {
+ var dist_ids = pcrud.search(
+ "sdist", {"subscription": id}, {"id_list": true}
+ );
pcrud.retrieve(
"ssub", id, {
"onresponse": function(r) {
if (r = openils.Util.readResponse(r)) {
sub = r;
+ var data = ssub.toStoreData([r]);
+ data.items[0].num_dist = dist_ids ? dist_ids.length : 0;
sub_grid.setStore(
- new dojo.data.ItemFileReadStore(
- {"data": ssub.toStoreData([r])}
- )
+ new dojo.data.ItemFileReadStore({"data": data})
);
sub_grid._fresh = true;
}
<span dojoType="dijit.form.Button"
onClick="dist_grid.refresh();">Refresh Grid</span>
<span dojoType="dijit.form.Button"
- onClick="dist_grid.showCreateDialog();">New Distribution</span>
+ onClick="sub_grid._fresh = false; dist_grid.showCreateDialog();">
+ New Distribution
+ </span>
<span dojoType="dijit.form.Button"
- onClick="dist_grid.deleteSelected();">Delete Selected</span>
+ onClick="sub_grid._fresh = false; dist_grid.deleteSelected();">
+ Delete Selected
+ </span>
</div>
</div>
<div dojoType="dijit.layout.ContentPane" layout="top">
<table
jsId="dist_grid"
dojoType="openils.widget.AutoGrid"
- autoHeight="true"
+ style="height: 550px;"
fieldOrder="['subscription','label','holding_lib']"
suppressFields="['record_entry','subscription','receive_call_number','bind_call_number','bind_unit_template']"
suppressEditFields="['record_entry','receive_call_number','bind_call_number','bind_unit_template']"
- defaultCellWidth="'auto'"
fmClass="sdist"
query="{id: '*'}"
editOnEnter="true"
showPaginator="true">
<thead>
<tr>
- <th field="label"
+ <th field="label" width="35%"
get="get_sdist" formatter="format_sdist_label"></th>
</tr>
</thead>
this._call_number_cache = null;
this._prepared_call_number_controls = {};
this._location_by_lib = {};
+ this._copy_template_cache = {};
/* empty the entry receiving table if we're starting over */
if (this.item_cache) {
dojo.query("menupopup", control)[0],
"first"
);
+ control.value = -1;
return control;
};
var node = dojo.query("*", node_by_name(field, row))[0];
- if (typeof(value) == "undefined")
+ if (typeof(value) == "undefined") {
return node.value;
- else
+ } else {
+ /* XXX The new two lines /should/ each do the same thing, but
+ * apparently they don't. With only one or the other, I get
+ * skipped fields when this is called by the code that
+ * pre-populates fields based on copy templates. This may
+ * have something to do with Dojo and XUL not getting along
+ * completely? */
+ dojo.attr(node, "value", value);
node.value = value;
+ }
}
this._user_wants_autogen = function() {
};
+ this._update_copy_template_cache = function() {
+ var templates_needed = openils.Util.uniqueElements(
+ openils.Util.objectProperties(this.item_cache).map(
+ function(id) {
+ return self.item_cache[id].stream().distribution().
+ receive_unit_template();
+ }
+ )
+ ).filter(
+ function(id) { return !self._copy_template_cache[id]; }
+ );
+
+ if (templates_needed.length) {
+ this.pcrud.search("act", {"id": templates_needed}).forEach(
+ function(tmpl) {
+ self._copy_template_cache[tmpl.id()] = tmpl;
+ }
+ );
+ }
+ }
+
+ this.apply_copy_templates = function() {
+ this._update_copy_template_cache(); /* sync */
+
+ for (var id in this.item_cache) {
+ var item = this.item_cache[id];
+ var template_id =
+ item.stream().distribution().receive_unit_template();
+ var template = this._copy_template_cache[template_id];
+
+ var row = this.rows[id];
+
+ var tmpl_mod = template.circ_modifier();
+ var tmpl_loc = template.location();
+ var tmpl_price = template.price();
+ if (tmpl_mod != null) {
+ this._row_field_value(
+ row, "circ_modifier", tmpl_mod == "" ? 0 : tmpl_mod
+ );
+ }
+ if (tmpl_loc)
+ this._row_field_value(row, "location", tmpl_loc);
+ if (tmpl_price > 0)
+ this._row_field_value(row, "price", tmpl_price);
+ }
+ };
+
this.load_entry_form = function(issuance) {
if (typeof(issuance) == "undefined") {
var issuance_id = dojo.byId("issuance_chooser").value;
busy(false);
if (list = openils.Util.readResponse(r, false, true)) {
-
if (list.length) {
busy(true);
show("form_holder");
list.forEach(function(o) {self.add_entry_row(o);});
self.build_batch_entry_row();
- dojo.byId("batch_receive_with_units").doCommand();
+
+ var recv_with_units =
+ dojo.byId("batch_receive_with_units");
+ recv_with_units.doCommand();
+ if (recv_with_units.checked)
+ self.apply_copy_templates();
show("batch_receive_entry");
busy(false);