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