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 var acqclet_template_parent = dojo.byId("acqclet-tbody");
30 this.eventTypeTemplate = acqclet_template_parent.removeChild(
31 nodeByName("acqclet-template", acqclet_template_parent)
34 dojo.byId("acq-lit-li-claim-dia-claim").onclick = function() {
35 var lid_ids = self.getSelectedEligible();
37 dojo.byId("acq-eligible-claim-submit").onclick = function() {
38 self.finalDialog.hide();
42 self.finalDialog.show();
45 alert(localeStrings.NO_LID_TO_CLAIM);
49 new openils.widget.AutoFieldWidget({
51 "selfReference": true,
52 "dijitArgs": {"required": true},
53 "parentNode": dojo.byId("acq-eligible-claim-type")
54 }).build(function(w) { self.claimType = w; });
56 this.reset = function(li) {
58 this.anyEligible = false;
59 this.showingLidNodes = {};
61 openils.Util.hide("acq-lit-li-claim-dia-initiate");
62 openils.Util.hide("acq-lit-li-claim-dia-show");
63 openils.Util.hide("acqclet-display");
65 dojo.empty("acqclet-tbody");
66 dojo.empty(this.showingList);
67 dojo.empty(this.eligibleList);
70 this.show = function(li, preselected) {
72 this.prepare(li, preselected);
76 this.hide = function() { this.dialog.hide(); };
78 this.prepare = function(li, preselected) {
81 dojo.byId("acq-lit-li-claim-dia-li-title").innerHTML =
82 li.attributes().filter(
83 function(o) { return Boolean(o.attr_name() == "title"); }
85 dojo.byId("acq-lit-li-claim-dia-li-id").innerHTML = li.id();
87 li.lineitem_details().forEach(
90 function(claim) { self.addClaim(lid, claim); }
92 if (self.eligibleLidByLi[li.id()].indexOf(lid.id()) != -1) {
93 self.addEligible(lid, preselected == lid.id());
98 if (!li.claim_policy())
99 this.showClaimEventTypes();
102 this.showClaimEventTypes = function() {
103 if (!this._cached_event_types) {
104 this._cached_event_types = new openils.PermaCrud({
105 "authtoken": openils.User.authtoken
107 "acqclet", {"order_by": {"acqclet": "code"}}
111 if (this._cached_event_types && this._cached_event_types.length) {
112 openils.Util.show("acqclet-display");
113 dojo.empty("acqclet-tbody");
114 this._cached_event_types.forEach(
115 function(clet) { self._render_event_type_row(clet); }
120 this.selectedEventTypes = function() {
121 var selected = dojo.query("[id^='acqclet-checkbox-']").filter(
123 return dojo.attr(node, "checked");
127 return dojo.attr(node, "id").match(/-(\d+)$/)[1];
131 return selected.length ? selected : null;
134 this._render_event_type_row = function(clet) {
135 var row = dojo.clone(this.eventTypeTemplate);
137 var checkbox = nodeByName("acqclet-checkbox", row);
138 var label = nodeByName("acqclet-label", row);
140 var checkbox_id = "acqclet-checkbox-" + clet.id();
141 dojo.attr(checkbox, "id", checkbox_id);
142 dojo.attr(label, "for", checkbox_id);
144 label.innerHTML = dojo.string.substitute(label.innerHTML, {
145 "description": clet.description(),
147 "library_initiated": clet.library_initiated() ?
148 localeStrings.LIBRARY_INITIATED : "",
149 "ou": aou.findOrgUnit(clet.org_unit()).shortname()
152 dojo.place(row, "acqclet-tbody");
155 this._reprReceived = function(lid) {
156 if (lid.cancel_reason())
157 return localeStrings.CANCELED + ": " + lid.cancel_reason().label();
158 else if (lid.recv_time())
159 return localeStrings.RECVD + " " + lid.recv_time();
161 return localeStrings.NOT_RECVD;
164 this.addClaim = function(lid, claim) {
166 openils.Util.show("acq-lit-li-claim-dia-show");
169 var lidNode = this.showingLidNodes[lid.id()];
171 lidNode = dojo.clone(this.showingLidTemplate);
172 nodeByName("barcode", lidNode).innerHTML = lid.barcode();
173 nodeByName("recvd", lidNode).innerHTML = this._reprReceived(lid);
175 this.showingLidNodes[lid.id()] = lidNode;
176 dojo.place(lidNode, this.showingList, "last");
179 var claimNode = dojo.clone(this.showingClaimTemplate);
180 nodeByName("type", claimNode).innerHTML = claim.type().code();
181 nodeByName("voucher", claimNode).onclick = function() {
183 fieldmapper.standardRequest(
185 "open-ils.acq.claim.voucher.by_lineitem_detail"], {
186 "params": [openils.User.authtoken, lid.id()],
188 "onresponse": function(r) {
189 if (r = openils.Util.readResponse(r)) {
191 win = openClaimVoucherWindow();
193 dojo.byId("main", win.document).innerHTML +=
194 (r.template_output().data() + "<hr />");
196 "oncomplete": function() {
197 var print_button = dojo.byId("print", win.document);
198 print_button.innerHTML = localeStrings.PRINT;
199 print_button.disabled = false;
206 claimNode, nodeByName("claims", lidNode), "last"
210 this.addEligible = function(lid, preselect) {
211 if (!this.anyEligible)
212 openils.Util.show("acq-lit-li-claim-dia-initiate");
213 this.anyEligible = true;
215 var eligibleNode = dojo.clone(this.eligibleTemplate);
216 var checkbox = nodeByName("claimable_lid", eligibleNode);
218 checkbox.value = lid.id();
219 dojo.attr(checkbox, "id", "claim-lid-" + lid.id());
220 dojo.attr(checkbox, "for", "claim-lid-" + lid.id());
222 dojo.attr(checkbox, "checked", true);
224 nodeByName("barcode", eligibleNode).innerHTML = lid.barcode();
225 nodeByName("recvd", eligibleNode).innerHTML = this._reprReceived(lid);
227 dojo.place(eligibleNode, this.eligibleList, "last");
230 this.getSelectedEligible = function() {
231 return dojo.query("input[name='claimable_lid']", this.eligibleList).
232 filter(function(o) { return o.checked; }).
233 map(function(o) { return o.value; });
236 this.claim = function(lid_ids) {
237 progressDialog.show(true);
239 fieldmapper.standardRequest(
240 ["open-ils.acq", "open-ils.acq.claim.lineitem_detail.atomic"], {
242 openils.User.authtoken, lid_ids, null,
243 this.claimType.attr("value"),
244 dijit.byId("acq-eligible-claim-note").attr("value"),
246 this.selectedEventTypes()
249 "onresponse": function(r) {
250 if (r = openils.Util.readResponse(r)) {
252 openils.Util.printHtmlString(
255 return o.template_output().data();
261 progressDialog.hide();
262 self.claimCallback(self.workingLi);