1 dojo.require("dijit.form.Button");
2 dojo.require("dijit.form.TextBox");
3 dojo.require("openils.acq.Lineitem");
4 dojo.require("openils.widget.OrgUnitFilteringSelect");
5 dojo.require("openils.widget.ProgressDialog");
6 dojo.require("openils.widget.AutoFieldWidget");
10 function nodeByName(n, c) { return dojo.query("[name='" + n + "']", c)[0]; }
12 function EligibleLiTable(filter) {
17 this.numClaimableLids = {};
19 this.claimNote = dijit.byId("acq-eligible-claim-note");
20 this.table = dojo.byId("acq-eligible-li-table");
21 this.tBody = dojo.query("tbody", this.table)[0];
22 this.tHead = dojo.query("thead", this.table)[0];
23 [this.rowTemplate, this.emptyTemplate] =
24 dojo.query("tr", this.tBody).map(
25 function(o) { return self.tBody.removeChild(o); }
28 nodeByName("selector_all", this.tHead).onclick = function() {
29 var value = this.checked;
30 dojo.query("[name='selector']", self.tBody).forEach(
31 function(o) { o.checked = value; }
35 new openils.widget.AutoFieldWidget({
37 "selfReference": true,
38 "dijitArgs": {"required": true},
39 "parentNode": dojo.byId("acq-eligible-claim-type")
40 }).build(function(w) { self.claimType = w; });
42 new openils.User().buildPermOrgSelector(
43 "VIEW_PURCHASE_ORDER", orderingAgency, null,
45 orderingAgency.attr("value", self.filter.ordering_agency);
47 orderingAgency, "onChange",
49 self.filter.ordering_agency = this.attr("value");
57 dojo.byId("acq-eligible-claim-submit").onclick = function() {
58 finalClaimDialog.hide();
59 self.claim(self.getSelected());
62 dojo.query("button[name='claim_submit']").forEach(
64 button.onclick = function() {
65 if (self.getSelected().length)
66 finalClaimDialog.show();
68 alert(localeStrings.NO_LI_TO_CLAIM);
73 this.showEmpty = function() {
74 dojo.place(dojo.clone(this.emptyTemplate), this.tBody, "only");
75 openils.Util.hide("acq-eligible-claim-controls");
78 this.load = function() {
79 progressDialog.show(true);
83 fieldmapper.standardRequest(
84 ["open-ils.acq", "open-ils.acq.claim.eligible.lineitem_detail"], {
85 "params": [openils.User.authtoken, this.filter],
87 "onresponse": function(r) {
88 if (r = openils.Util.readResponse(r)) {
90 openils.Util.show("acq-eligible-claim-controls");
91 self.addIfMissing(r.lineitem());
93 progressDialog.hide();
96 "oncomplete": function() {
97 if (count < 1) self.showEmpty();
98 progressDialog.hide();
104 this.reset = function() {
106 this.numClaimableLids = {};
107 dojo.empty(this.tBody);
110 this._updateLidLink = function(liId) {
111 this.numClaimableLids[liId] = (this.numClaimableLids[liId] || 0) + 1;
112 if (this.numClaimableLids[liId] == 2) {
113 nodeByName("lid_link", "eligible-li-" + liId).onclick =
115 location.href = oilsBasePath + "/acq/po/view/" +
116 self.liCache[liId].purchase_order().id() + "," +
120 nodeByName("lid_link_holder", "eligible-li-" + liId)
125 /* Despite being called with an argument that's a lineitem ID, this method
126 * is actually called once per lineitem _detail_. */
127 this.addIfMissing = function(liId) {
128 this._updateLidLink(liId);
129 if (this.liCache[liId]) return;
131 var row = dojo.clone(this.rowTemplate);
133 var checkbox = nodeByName("selector", row);
134 var desc = nodeByName("description", row);
136 openils.acq.Lineitem.fetchAndRender(
137 liId, null, function(li, contents) {
138 self.liCache[liId] = li;
140 desc.innerHTML = contents;
141 dojo.attr(row, "id", "eligible-li-" + liId);
142 dojo.attr(checkbox, "value", liId);
143 dojo.place(row, self.tBody, "last");
148 /* Despite being called with an argument that's a lineitem ID, this method
149 * is actually called once per lineitem _detail_. */
150 this.removeIfPresent = function(liId) {
151 if (this.liCache[liId]) {
152 delete this.liCache[liId];
153 delete this.numClaimableLids[liId];
154 this.tBody.removeChild(dojo.byId("eligible-li-" + liId));
158 this.getSelected = function() {
159 return dojo.query("[name='selector']", this.tBody).
160 filter(function(o) { return o.checked; }).
161 map(function(o) { return o.value; });
164 this.resetVoucher = function() { this.voucherWin = null; };
166 this.addToVoucher = function(contents) {
167 if (!this.voucherWin)
168 this.voucherWin = openClaimVoucherWindow();
169 dojo.byId("main", this.voucherWin.document).innerHTML +=
170 (contents + "<hr />");
173 this.finishVoucher = function() {
174 var print_btn = dojo.byId("print", this.voucherWin.document);
175 print_btn.disabled = false;
176 print_btn.innerHTML = localeStrings.PRINT;
179 this.claim = function(lineitems) {
180 progressDialog.show(true);
183 fieldmapper.standardRequest(
184 ["open-ils.acq", "open-ils.acq.claim.lineitem"], {
186 openils.User.authtoken, lineitems, null,
187 this.claimType.attr("value"), this.claimNote.attr("value")
190 "onresponse": function(r) {
191 if (r = openils.Util.readResponse(r))
192 self.addToVoucher(r.template_output().data());
194 progressDialog.hide();
196 "oncomplete": function() {
198 function(liId) { self.removeIfPresent(liId); }
200 if (!nodeByName("selector", self.tBody)) // emptiness test
203 self.finishVoucher();
204 progressDialog.hide();
212 var finished_filter = {};
213 if (filter && filter.indexOf(":") != -1) {
214 filter.split(",").forEach(
216 var kvlist = chunk.split(":");
217 finished_filter[kvlist[0]] = kvlist[1];
221 filter = finished_filter;
223 if (!filter.ordering_agency)
224 filter.ordering_agency = openils.User.user.ws_ou();
226 eligibleLiTable = new EligibleLiTable(filter);
229 openils.Util.addOnLoad(init);