]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/opac_utils.js
new javascript
[Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / opac_utils.js
1 var IAMXUL = false;
2 function isXUL() { return IAMXUL; }
3
4
5 /* - Request ------------------------------------------------------------- */
6 function Request(type) {
7         var s = type.split(":");
8         this.request = new RemoteRequest(s[0], s[1]);
9         for( var x = 1; x!= arguments.length; x++ ) 
10                 this.request.addParam(arguments[x]);
11 }
12
13 Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
14 Request.prototype.send          = function(block){this.request.send(block);}
15 /* ----------------------------------------------------------------------- */
16
17
18 /* finds the name of the current page */
19 function findCurrentPage() {
20         for( var p in config.page ) {
21                 var path = location.pathname;
22
23                 if(!path.match(/.*\.xml$/))
24                         path += "index.xml"; /* in case they go to  / */
25
26                 if( config.page[p] == path)
27                         return p;
28         }
29         return null;
30 }
31
32
33 /* builds an opac URL.  If no page is defined, the current page is used
34         if slim, then only everything after the ? is returned (no host portion)
35  */
36 function  buildOPACLink(args, slim) {
37
38         if(!args) args = {};
39
40         if(!slim) {
41                 var string = location.protocol + "//" + location.host;
42                 if(args.page) string += config.page[args.page];
43                 else string += config.page[findCurrentPage()];
44         }
45
46         string += "?";
47
48         for( var x in args ) {
49                 if(x == "page" || args[x] == null) continue;
50                 string += "&" + x + "=" + encodeURIComponent(args[x]);
51         }
52
53         string += _appendParam(TERM,            PARAM_TERM, args, getTerm, string);
54         string += _appendParam(STYPE,           PARAM_STYPE, args, getStype, string);
55         string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
56         string += _appendParam(DEPTH,           PARAM_DEPTH, args, getDepth, string);
57         string += _appendParam(FORM,            PARAM_FORM, args, getForm, string);
58         string += _appendParam(OFFSET,  PARAM_OFFSET, args, getOffset, string);
59         string += _appendParam(COUNT,           PARAM_COUNT, args, getDisplayCount, string);
60         string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
61         string += _appendParam(MRID,            PARAM_MRID, args, getMrid, string);
62         string += _appendParam(RID,             PARAM_RID, args, getRid, string);
63         return string.replace(/\&$/,'').replace(/\?\&/,"?");    
64 }
65
66 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
67         var ret = "";
68         if( fieldVar != null && overrideArgs[fieldName] == null ) 
69                 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
70         return ret;
71 }
72
73
74
75
76
77 /* ----------------------------------------------------------------------- */
78 /* some useful exceptions */
79 function EX(message) { this.init(message); }
80
81 EX.prototype.init = function(message) {
82    this.message = message;
83 }
84
85 EX.prototype.toString = function() {
86    return "\n *** Exception Occured \n" + this.message;
87 }  
88
89 EXCommunication.prototype              = new EX();
90 EXCommunication.prototype.constructor  = EXCommunication;
91 EXCommunication.baseClass              = EX.prototype.constructor;
92
93 function EXCommunication(message) {
94    this.init("EXCommunication: " + message);
95 }                          
96 /* ----------------------------------------------------------------------- */
97
98 function cleanISBN(isbn) {
99    if(isbn) {
100       isbn = isbn.toString().replace(/^\s+/,"");
101       var idx = isbn.indexOf(" ");
102       if(idx > -1) { isbn = isbn.substring(0, idx); }
103    } else isbn = "";
104    return isbn;
105 }       
106
107
108 function doLogin() {
109 }
110
111
112 /* ----------------------------------------------------------------------- */
113 /* builds a link that goes to the title listings for a metarecord */
114 function buildTitleLink(rec, link) {
115
116         var t = rec.title(); 
117         t = normalize(truncate(t, 65));
118         link.appendChild(text(t));
119
120         var args = {};
121         args.page = RRESULT;
122         args[PARAM_OFFSET] = 0;
123         args[PARAM_MRID] = rec.doc_id();
124         link.setAttribute("href", buildOPACLink(args));
125 }
126
127 /* builds an author search link */
128 function buildAuthorLink(rec, link) {
129
130         var a = rec.author(); 
131         a = normalize(truncate(a, 65));
132         link.appendChild(text(a));
133
134         var args = {};
135         args.page = MRESULT;
136         args[PARAM_OFFSET] = 0;
137         args[PARAM_STYPE] = "author";
138         args[PARAM_TERM] = rec.author();
139         link.setAttribute("href", buildOPACLink(args));
140
141 }
142 /* ----------------------------------------------------------------------- */
143
144
145
146
147
148