]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/common/js/added_content.js
4240b4f3204c0dff8ff3364b5cab012fc0bd4d4b
[working/Evergreen.git] / Open-ILS / web / opac / common / js / added_content.js
1 /**
2 * This function should return a URL which points to the book cover image based on ISBN.
3 */
4
5
6 function buildISBNSrc(isbn, size) {
7         size = (size) ? size : 'small';
8         var protocol = (OILS_OPAC_STATIC_PROTOCOL) ? OILS_OPAC_STATIC_PROTOCOL + ':' : location.protocol;
9     if(OILS_OPAC_IMAGES_HOST)
10         return protocol + '//' + OILS_OPAC_IMAGES_HOST + size + '/' + isbn;
11         return '../../../../extras/ac/jacket/'+size+'/'+isbn;
12 }      
13
14
15 function acMakeURL(type, key) {
16         return '../../../../extras/ac/' + type + '/html/' + key;
17 }
18
19
20 function acCollectData( key, callback ) {
21         var context = { key : key, callback: callback, data : {} };
22         acCollectItem(context, 'summary');
23         acCollectItem(context, 'reviews');
24         acCollectItem(context, 'toc');
25         acCollectItem(context, 'excerpt');
26         acCollectItem(context, 'anotes');
27 }
28
29 function acCheckDone(context) {
30         if(     context.data.reviews && context.data.reviews.done &&
31                         context.data.toc                && context.data.toc.done &&
32                         context.data.excerpt && context.data.excerpt.done &&
33                         context.data.anotes     && context.data.anotes.done ) {
34
35                 if(context.callback) context.callback(context.data);
36         }
37 }
38
39 function acCollectItem(context, type) {
40         var req = buildXMLRequest();
41         req.open('GET', acMakeURL(type, context.key), true);
42         req.onreadystatechange = function() {
43                 if( req.readyState == 4 ) {
44                         context.data[type] = { done : true }
45
46                         if(IE) {
47
48                                 /* Someone please explain why IE treats status 404 as status 200?? 
49                                         On second thought, don't bother.
50                                 */
51                                 if( ! req.responseText.match(
52                                         /The requested URL.*was not found on this server/) )
53                                         context.data[type].html = req.responseText;
54
55                         } else {
56                                 if( req.status != 404 ) 
57                                         context.data[type].html = req.responseText;
58                         }
59                         acCheckDone(context);
60                 }
61         }
62         req.send(null);
63 }
64
65