1 function ClaimDialogManager(
2 dialog, finalDialog, eligibleLidByLi, claimCallback
7 this.anyEligible = false;
8 this.showingLidNodes = {};
11 this.finalDialog = finalDialog;
12 this.eligibleLidByLi = eligibleLidByLi;
13 this.claimCallback = claimCallback;
15 this.showingList = dojo.byId("acq-lit-li-claim-dia-lid-list");
16 this.eligibleList = dojo.byId("acq-lit-li-claim-dia-lid-list-init");
18 this.showingLidTemplate = this.showingList.removeChild(
19 nodeByName("lid", this.showingList)
21 this.showingClaimTemplate =
22 nodeByName("claims", this.showingLidTemplate).removeChild(
23 nodeByName("claim", this.showingLidTemplate)
25 this.eligibleTemplate = this.eligibleList.removeChild(
26 nodeByName("lid_to_claim", this.eligibleList)
29 dojo.byId("acq-lit-li-claim-dia-claim").onclick = function() {
30 var lid_ids = self.getSelectedEligible();
32 dojo.byId("acq-eligible-claim-submit").onclick = function() {
33 self.finalDialog.hide();
37 self.finalDialog.show();
40 alert(localeStrings.NO_LID_TO_CLAIM);
44 new openils.widget.AutoFieldWidget({
46 "selfReference": true,
47 "dijitArgs": {"required": true},
48 "parentNode": dojo.byId("acq-eligible-claim-type")
49 }).build(function(w) { self.claimType = w; });
51 this.reset = function(li) {
53 this.anyEligible = false;
54 this.showingLidNodes = {};
56 openils.Util.hide("acq-lit-li-claim-dia-initiate");
57 openils.Util.hide("acq-lit-li-claim-dia-show");
59 dojo.empty(this.showingList);
60 dojo.empty(this.eligibleList);
63 this.show = function(li, preselected) {
65 this.prepare(li, preselected);
69 this.hide = function() { this.dialog.hide(); };
71 this.prepare = function(li, preselected) {
74 dojo.byId("acq-lit-li-claim-dia-li-title").innerHTML =
75 li.attributes().filter(
76 function(o) { return Boolean(o.attr_name() == "title"); }
78 dojo.byId("acq-lit-li-claim-dia-li-id").innerHTML = li.id();
80 li.lineitem_details().forEach(
83 function(claim) { self.addClaim(lid, claim); }
85 if (self.eligibleLidByLi[li.id()].indexOf(lid.id()) != -1) {
86 self.addEligible(lid, preselected == lid.id());
92 this._reprReceived = function(lid) {
93 if (lid.cancel_reason())
94 return localeStrings.CANCELED + ": " + lid.cancel_reason().label();
95 else if (lid.recv_time())
96 return localeStrings.RECVD + " " + lid.recv_time();
98 return localeStrings.NOT_RECVD;
101 this.addClaim = function(lid, claim) {
103 openils.Util.show("acq-lit-li-claim-dia-show");
106 var lidNode = this.showingLidNodes[lid.id()];
108 lidNode = dojo.clone(this.showingLidTemplate);
109 nodeByName("barcode", lidNode).innerHTML = lid.barcode();
110 nodeByName("recvd", lidNode).innerHTML = this._reprReceived(lid);
112 this.showingLidNodes[lid.id()] = lidNode;
113 dojo.place(lidNode, this.showingList, "last");
116 var claimNode = dojo.clone(this.showingClaimTemplate);
117 nodeByName("type", claimNode).innerHTML = claim.type().code();
118 nodeByName("voucher", claimNode).onclick = function() {
120 fieldmapper.standardRequest(
122 "open-ils.acq.claim.voucher.by_lineitem_detail"], {
123 "params": [openils.User.authtoken, lid.id()],
125 "onresponse": function(r) {
126 if (r = openils.Util.readResponse(r)) {
128 win = openClaimVoucherWindow();
130 dojo.byId("main", win.document).innerHTML +=
131 (r.template_output().data() + "<hr />");
133 "oncomplete": function() {
134 var print_button = dojo.byId("print", win.document);
135 print_button.innerHTML = localeStrings.PRINT;
136 print_button.disabled = false;
143 claimNode, nodeByName("claims", lidNode), "last"
147 this.addEligible = function(lid, preselect) {
148 if (!this.anyEligible)
149 openils.Util.show("acq-lit-li-claim-dia-initiate");
150 this.anyEligible = true;
152 var eligibleNode = dojo.clone(this.eligibleTemplate);
153 var checkbox = nodeByName("claimable_lid", eligibleNode);
155 checkbox.value = lid.id();
156 dojo.attr(checkbox, "id", "claim-lid-" + lid.id());
157 dojo.attr(checkbox, "for", "claim-lid-" + lid.id());
159 dojo.attr(checkbox, "checked", true);
161 nodeByName("barcode", eligibleNode).innerHTML = lid.barcode();
162 nodeByName("recvd", eligibleNode).innerHTML = this._reprReceived(lid);
164 dojo.place(eligibleNode, this.eligibleList, "last");
167 this.getSelectedEligible = function() {
168 return dojo.query("input[name='claimable_lid']", this.eligibleList).
169 filter(function(o) { return o.checked; }).
170 map(function(o) { return o.value; });
173 this.claim = function(lid_ids) {
174 progressDialog.show(true);
177 fieldmapper.standardRequest(
178 ["open-ils.acq", "open-ils.acq.claim.lineitem_detail"], {
180 openils.User.authtoken, lid_ids, null,
181 this.claimType.attr("value"),
182 dijit.byId("acq-eligible-claim-note").attr("value")
185 "onresponse": function(r) {
186 if (r = openils.Util.readResponse(r)) {
188 win = openClaimVoucherWindow();
189 dojo.byId("main", win.document).innerHTML +=
190 (r.template_output().data() + "<hr />");
193 progressDialog.hide();
196 "oncomplete": function() {
197 progressDialog.hide();
198 dojo.byId("print", win.document).innerHTML =
200 dojo.byId("print", win.document).disabled = false;
201 self.claimCallback(self.workingLi);