]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/cn_browse.js
94b8c8b3460e3092c4fa9dfacdb57ebbdf058c89
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / cn_browse.js
1 var cnOffset = 0;
2 var cnCount = 9;
3 var cnBrowseCN;
4 var cnBrowseOrg;
5
6 if( findCurrentPage() == CNBROWSE ) {
7         attachEvt("common", "run", cnBrowseLoadSearch);
8         attachEvt( "common", "locationUpdated", cnBrowseResubmit );
9         attachEvt( "common", "depthChanged", cnBrowseResubmit );
10 }
11
12
13 function cnBrowseLoadSearch() {
14         unHideMe($('cn_browse'));
15         cnBrowseGo(getCallnumber(), getLocation(), getDepth());
16 }
17
18
19 function cnBrowseResubmit() {
20         var args = {}
21         args[PARAM_CN] = cnBrowseCN;
22         args[PARAM_DEPTH] = depthSelGetDepth();
23         args[PARAM_LOCATION] = getNewSearchLocation();
24         goTo(buildOPACLink(args));
25 }
26
27
28
29 function cnBrowseGo(cn, org, depth) { 
30         if(depth == null) depth = getDepth();
31
32         org = findOrgUnit(org);
33         cnOffset = 0;
34
35         do {
36                 var t = findOrgType(org.ou_type());
37                 if( t.depth() > depth ) 
38                         org = findOrgUnit(org.parent_ou());
39                 else break;
40         } while(true); 
41
42         cnBrowseOrg = org;
43         cnBrowseCN = cn;
44
45         _cnBrowseGo( cn, org );
46         appendClear($('cn_browse_where'), text(org.name()));
47 }
48
49
50 function _cnBrowseGo( cn, org ) {
51         var req = new Request( FETCH_CNBROWSE, cn, org.id(), cnCount, cnOffset );
52         req.callback( cnBrowseDraw );
53         req.send();
54 }
55
56 function cnBrowseNext() {
57         cnOffset++;
58         _cnBrowseGo( cnBrowseCN, cnBrowseOrg );
59 }
60
61 function cnBrowsePrev() {
62         cnOffset--;
63         _cnBrowseGo( cnBrowseCN, cnBrowseOrg );
64 }
65
66
67 function cnBrowseDraw( r ) {
68         var list = r.getResultObject();
69         _cnBrowseDraw(list);
70 }
71
72
73 var cnTbody;
74 var cnRowT;
75 var cnTdT;
76 function _cnBrowseDraw( list ) {
77
78         if(!cnTbody) {
79                 cnTbody = $('cn_tbody');
80                 cnRowT = $('cn_browse_row');
81                 cnTdT = cnRowT.removeChild($('cn_browse_td'));
82                 cnTbody.removeChild(cnRowT);
83         }
84         removeChildren(cnTbody);
85
86         var counter = 1;
87         var currentRow = cnRowT.cloneNode(true);
88         cnTbody.appendChild(currentRow);
89
90         for( var idx in list ) {
91                 
92
93                 var currentTd = cnTdT.cloneNode(true);
94                 currentRow.appendChild(currentTd);
95
96                 var td = cnTdT.cloneNode(true);
97
98                 var obj = list[idx];
99                 var cn  = obj.cn;
100                 var mods = obj.mods;
101
102                 var cn_td                       = $n(currentTd, 'cn_browse_cn');
103                 var lib_td                      = $n(currentTd, 'cn_browse_lib');
104                 var title_td            = $n(currentTd, 'cn_browse_title');
105                 var author_td           = $n(currentTd, 'cn_browse_author');
106                 var pic_td                      = $n(currentTd, 'cn_browse_pic');
107
108                 if (parseInt(cn.prefix().id()) > -1) {
109             cn_td.appendChild(text(cn.prefix().label()));
110             cn_td.appendChild(text(' '));
111         }
112
113                 cn_td.appendChild(text(cn.label()));
114
115                 if (parseInt(cn.suffix().id()) > -1) {
116             cn_td.appendChild(text(' '));
117             cn_td.appendChild(text(cn.suffix().label()));
118         }
119
120                 lib_td.appendChild(text(findOrgUnit(cn.owning_lib()).name()));
121                 cnBrowseDrawTitle(mods, title_td, author_td, pic_td);
122
123                 if( counter++ % 3 == 0 ) {
124                         counter = 1;
125                         currentRow = cnRowT.cloneNode(true);
126                         cnTbody.appendChild(currentRow);
127                 }
128         }
129 }
130
131
132 function cnBrowseDrawTitle(mods, title_td, author_td, pic_td) {
133
134         buildTitleDetailLink(mods, title_td); 
135         buildSearchLink(STYPE_AUTHOR, mods.author(), author_td);
136         pic_td.setAttribute("src", buildISBNSrc(cleanISBN(mods.isbn())));
137
138         var args = {};
139         args.page = RDETAIL;
140         args[PARAM_OFFSET] = 0;
141         args[PARAM_RID] = mods.doc_id();
142         args[PARAM_MRID] = 0;
143         pic_td.parentNode.setAttribute("href", buildOPACLink(args));
144 }
145