]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
js for the record details page
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2 attachEvt("common", "run", rdetailDraw);
3 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
5
6 var record = null;
7 var cp_statuses = null;
8
9 function rdetailDraw() {
10
11         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
12         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
13         var req = new Request(FETCH_RMODS, getRid());
14         req.callback(_rdetailDraw);
15         req.send();
16 }
17
18 function rdetailShowLocalCopies() {
19         var rows = getId("first_copy_info_row").parentNode.getElementsByTagName("tr");
20         var found = false;
21         for( var r in rows ) {
22                 if(r == 0) continue;
23                 hideMe(rows[r]);
24                 if(!isNull(rows[r]) && rows[r].getAttribute && 
25                         rows[r].getAttribute("local")) {
26                         unHideMe(rows[r]);
27                         found = true;
28                 }
29         }
30         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
31         hideMe(G.ui.rdetail.cp_info_local);
32         unHideMe(G.ui.rdetail.cp_info_all);
33 }
34
35 function rdetailShowAllCopies() {
36         var rows = getId("first_copy_info_row").parentNode.getElementsByTagName("tr");
37         for( var r in rows ) unHideMe(rows[r]);
38         hideMe(G.ui.rdetail.cp_info_all);
39         unHideMe(G.ui.rdetail.cp_info_local);
40         hideMe(G.ui.rdetail.cp_info_none);
41 }
42
43
44 function _rdetailDraw(r) {
45         record = r.getResultObject();
46
47         G.ui.rdetail.title.appendChild(text(record.title()));
48         G.ui.rdetail.author.appendChild(text(record.author()));
49         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
50         G.ui.rdetail.edition.appendChild(text(record.edition()));
51         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
52         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
53         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()));
54         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
55
56         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
57         runEvt("rdetail", "recordDrawn");
58 }
59
60 var _statusPositions = {};
61 function rdetailBuildStatusColumns() {
62
63         rdetailGrabCopyStatuses();
64         var parent = G.ui.rdetail.cp_status.parentNode;
65         var template = parent.removeChild(G.ui.rdetail.cp_status);
66
67         var i = 0;
68         for( i = 0; i < cp_statuses.length; i++ ) {
69                 var c = cp_statuses[i];
70                 if(c && c.holdable()) {
71                         _statusPositions[i] = c;
72                         var node = template.cloneNode(true);
73                         node.appendChild(text("#" + c.name()));
74                         parent.appendChild(node);
75                 }       
76         }       
77 }
78
79 function rdetailBuildInfoRows() {
80         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
81         req.callback(_rdetailBuildInfoRows);
82         req.send();
83 }
84
85 function _rdetailSortSummary(a,b) {
86         a = findOrgUnit(a[0]).name().toLowerCase();
87         b = findOrgUnit(b[0]).name().toLowerCase();
88         if(a<b) return -1;
89         if(a>b) return 1;
90         return 0;
91 }
92
93 function _rdetailBuildInfoRows(r) {
94
95         var summary = r.getResultObject();
96
97         var curLoc = getLocation();
98
99         summary = summary.sort(_rdetailSortSummary);
100
101         /* remove the 'now loading' thingy */
102         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
103                 G.ui.rdetail.cp_info_loading);
104
105         var parent = G.ui.rdetail.cp_info_row.parentNode;
106         var template = parent.removeChild(G.ui.rdetail.cp_info_row);
107
108         var found = false;
109         for( var i = 0; i != summary.length; i++ ) {
110
111                 var arr = summary[i];
112                 var node = template.cloneNode(true);
113                 if(i == 0) node.id = "first_copy_info_row";
114                 if(parseInt(arr[0]) != curLoc)  hideMe(node); 
115                 else {found = true; node.setAttribute("local", "1");}
116
117                 if(i%2) addCSSClass(node, config.css.color_3);
118                 var lib = findNodeByName(node, config.names.rdetail.lib_cell);
119                 var cn = findNodeByName(node, config.names.rdetail.cn_cell);
120                 var tdtemplate = node.removeChild(findNodeByName(node, config.names.rdetail.cp_count_cell));
121
122                 lib.appendChild(text(findOrgUnit(arr[0]).name()));
123                 cn.appendChild(text(arr[1]));
124                 parent.appendChild(node);
125
126                 for( var j in _statusPositions ) {
127                         var stat = _statusPositions[j];
128                         var val = arr[2][stat.id()];
129                         var nn = tdtemplate.cloneNode(true);
130                         if(val) nn.appendChild(text(val));
131                         else nn.appendChild(text(0));
132                         node.appendChild(nn);   
133                 }
134         }
135         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
136 }
137
138
139 function _rdetailSortStatuses(a, b) {
140         return parseInt(a.id()) - parseInt(b.id());
141 }
142
143
144 function rdetailGrabCopyStatuses() {
145         if(cp_statuses) return cp_statuses;
146    var req = new Request(FETCH_COPY_STATUSES);
147    req.send(true);
148         cp_statuses = req.result();
149         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
150 }
151
152
153
154