]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/result_common.js
memory leak debugging, removed closures
[Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / result_common.js
1
2
3 /* set the search result info, number of hits, which results we're 
4         displaying, links to the next/prev pages, etc. */
5 function resultSetInfo() { 
6         var c;  
7         if( getDisplayCount() > (getHitCount() - getOffset()))  c = getHitCount();
8         else c = getDisplayCount() + getOffset();
9
10         var pages = getHitCount() / getDisplayCount();
11         if(pages % 1) pages = parseInt(pages) + 1;
12
13         G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
14         G.ui.result.num_pages.appendChild(text(pages + ")"));
15
16         var o = getOffset();
17
18         if( !((o + getDisplayCount()) >= getHitCount()) ) {
19
20                 var args = {};
21                 args[PARAM_OFFSET] = o + getDisplayCount();
22                 G.ui.result.next_link.setAttribute("href", buildOPACLink(args)); 
23                 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
24
25                 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
26                 G.ui.result.end_link.setAttribute("href", buildOPACLink(args)); 
27                 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
28         }
29
30         if( o > 0 ) {
31
32                 var args = {};
33                 args[PARAM_OFFSET] = o - getDisplayCount();
34                 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args)); 
35                 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
36
37                 args[PARAM_OFFSET] = 0;
38                 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args)); 
39                 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
40         }
41
42         G.ui.result.offset_start.appendChild(text(o + 1));
43         G.ui.result.offset_end.appendChild(text(c));
44         G.ui.result.result_count.appendChild(text(getHitCount()));
45         unHideMe(G.ui.result.info);
46
47 }
48
49
50 /* display the record info in the record display table */
51 function resultDisplayRecord(rec, rowtemplate, is_mr) {
52
53         if(rec == null) rec = new mvr(); /* so the page won't die */
54
55         /* hide the 'now loading...' message */
56         hideMe(G.ui.common.loading);
57
58         var r = rowtemplate.cloneNode(true);
59
60         var pic = findNodeByName(r, config.names.result.item_jacket);
61         pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
62
63         var title_link = findNodeByName(r, config.names.result.item_title);
64         var author_link = findNodeByName(r, config.names.result.item_author);
65
66         if( is_mr )  buildTitleLink(rec, title_link); 
67         else  buildTitleDetailLink(rec, title_link); 
68         buildAuthorLink(rec, author_link); 
69
70         var countsrow = findNodeByName(r, config.names.result.counts_row);
71
72         /* adjust the width according to how many org counts are added */
73         findNodeByName(r, "result_table_title_cell").width = 
74                 resultAddCopyCounts(countsrow, rec) + "%";
75
76         table.appendChild(r);
77
78 }
79
80
81 /* -------------------------------------------------------------------- */
82 /* dynamically add the copy count rows based on the org type 
83         'countsrow' is the row into which we will add TD's to hold
84         the copy counts 
85         This code generates copy count cells with an id of
86
87         'copy_count_cell_<depth>_<record_id>' for later insertion
88         of copy counts
89
90         return the percent width left over after the each count is added. 
91         if 3 counts are added, returns 100 - (cell.width * 3)
92  */
93
94 function resultAddCopyCounts(countsrow, rec) {
95
96         var ccell = findNodeByName(countsrow, config.names.result.count_cell);
97
98
99         var nodes = orgNodeTrail(findOrgUnit(getLocation()));
100         var node = nodes[0];
101         var type = findOrgType(node.ou_type());
102         ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
103         ccell.title = type.opac_label();
104         addCSSClass(ccell, "copy_count_cell_even");
105
106
107         var lastcell = ccell;
108
109         if(nodes[1]) {
110
111                 var x = 1;
112                 var d = findOrgDepth(nodes[1]);
113                 var d2 = findOrgDepth(nodes[nodes.length -1]);
114
115                 for( var i = d; i <= d2 ; i++ ) {
116         
117                         ccell = ccell.cloneNode(true);
118
119                         if((i % 2))
120                                 removeCSSClass(ccell, "copy_count_cell_even");
121                         else
122                                 addCSSClass(ccell, "copy_count_cell_even");
123
124                         var node = nodes[x++];
125                         var type = findOrgType(node.ou_type());
126         
127                         ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
128                         ccell.title = type.opac_label();
129                         countsrow.insertBefore(ccell, lastcell);
130                         lastcell = ccell;
131                 }
132         }
133
134         return 100 - (nodes.length * 8);
135
136 }
137
138 /* collect copy counts for a record using method 'methodName' */
139 function resultCollectCopyCounts(rec, methodName) {
140         if(rec == null || rec.doc_id() == null) return;
141         var req = new Request(methodName, getLocation(), rec.doc_id() );
142         req.request.userdata = rec;
143         req.callback(resultHandleCopyCounts);
144         req.send();
145 }
146
147 function resultHandleCopyCounts(r) {
148         resultDisplayCopyCounts(r.userdata, r.getResultObject()); 
149 }
150
151
152 /* display the collected copy counts */
153 function resultDisplayCopyCounts(rec, copy_counts) {
154         if(copy_counts == null || rec == null) return;
155         var i = 0;
156         while(copy_counts[i] != null) {
157                 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
158                 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
159                 i++;
160         }
161 }
162
163
164
165
166