]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/lineitem/related.js
Acq: from the lineitem details pane, one can view other LIs of same bib
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / lineitem / related.js
1 dojo.require("openils.acq.Lineitem");
2 dojo.require("openils.Util");
3 dojo.require("openils.XUL");
4
5 var liTable;
6
7 function attrDefByName(attr) {
8     return openils.acq.Lineitem.attrDefs[
9         attr.attr_type().replace(/lineitem_(.*)_attr_definition/, "$1")
10     ].filter(
11         function(o) { return (o.code() == attr.attr_name()); }
12     ).pop();
13 }
14
15 function drawLiInfo(li) {
16     var infoTbody = dojo.byId("acq-related-info-tbody");
17     var infoRow = infoTbody.removeChild(dojo.byId("acq-related-info-row"));
18
19     li.attributes().forEach(
20         function(attr) {
21             var row = dojo.clone(infoRow);
22
23             nodeByName("label", row).innerHTML =
24                 attrDefByName(attr).description();
25             nodeByName("value", row).innerHTML = attr.attr_value();
26
27             infoTbody.appendChild(row);
28
29             if (["title", "author"].indexOf(attr.attr_name()) != -1) {
30                 nodeByName(
31                     attr.attr_name(), dojo.byId("acq-related-mini-display")
32                 ).innerHTML = attr.attr_value();
33             }
34         }
35     );
36 }
37
38 function fetchLi() {
39     fieldmapper.standardRequest(
40         ["open-ils.acq", "open-ils.acq.lineitem.retrieve"], {
41             "async": true,
42             "params": [openils.User.authtoken, liId, {
43                 "flesh_attrs": true,
44                 "flesh_li_details": true,
45                 "flesh_fund_debit": true
46             }],
47             "oncomplete": function(r) {
48                 drawLiInfo(openils.Util.readResponse(r));
49             }
50         }
51     );
52 }
53
54 function hideDetails() {
55     openils.Util.show("acq-related-mini");
56     openils.Util.hide("acq-related-info-div");
57 }
58
59 function showDetails() {
60     openils.Util.show("acq-related-info-div");
61     openils.Util.hide("acq-related-mini");
62 }
63
64 function fetchRelated() {
65     fieldmapper.standardRequest(
66         ["open-ils.acq", "open-ils.acq.lineitems_for_bib.by_lineitem_id"], {
67             "async": true,
68             "params": [openils.User.authtoken, liId, {
69                 "flesh_attrs": true, "flesh_notes": true
70             }],
71             "onresponse": function(r) {
72                 var resp = openils.Util.readResponse(r);
73                 if (resp) {
74                     liTable.show("list");
75                     liTable.addLineitem(resp);
76                 }
77             }
78         }
79     );
80 }
81 function load() {
82     openils.acq.Lineitem.fetchAttrDefs(fetchLi);
83     dojo.byId("acq-related-info-back-button").onclick = hideDetails;
84     dojo.byId("acq-related-info-show-button").onclick = showDetails;
85
86     liTable = new AcqLiTable();
87     liTable.reset();
88     liTable._isRelatedViewer = true;
89
90     fetchRelated();
91 }
92
93 openils.Util.addOnLoad(load);