]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/dojo/openils/CGI.js
Serial Control: Use Dijit-based issuance editor
[working/Evergreen.git] / Open-ILS / web / js / dojo / openils / CGI.js
1 /* ---------------------------------------------------------------------------
2  * Copyright (C) 2008  Georgia Public Library Service
3  * Bill Erickson <erickson@esilibrary.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * ---------------------------------------------------------------------------
15  */
16
17 if(!dojo._hasResource["openils.CGI"]) {
18
19     dojo._hasResource["openils.CGI"] = true;
20     dojo.provide("openils.CGI");
21     dojo.declare('openils.CGI', null, {
22
23         constructor : function() {
24
25             this._keys = new Array();
26             this.data = new Object();
27
28             var string = location.search.replace(/^\?/,"");
29             this.server_name = location.href.replace(/^https?:\/\/([^\/]+).+$/,"$1");
30
31             var key = ""; 
32             var value = "";
33             var inkey = true;
34             var invalue = false;
35
36             for( var idx = 0; idx!= string.length; idx++ ) {
37
38                 var c = string.charAt(idx);
39
40                 if( c == "=" )  {
41                     invalue = true;
42                     inkey = false;
43                     continue;
44                 } 
45
46                 if(c == "&" || c == ";") {
47                     inkey = 1;
48                     invalue = 0;
49                     if( ! this.data[key] ) this.data[key] = [];
50                     this.data[key].push(decodeURIComponent(value));
51                     this._keys.push(key);
52                     key = ""; value = "";
53                     continue;
54                 }
55
56                 if(inkey) key += c;
57                 else if(invalue) value += c;
58             }
59
60             if( ! this.data[key] ) this.data[key] = [];
61             this.data[key].push(decodeURIComponent(value));
62             this._keys.push(key);
63         },
64
65         /* returns the value for the given param.  If there is only one value for the
66            given param, it returns that value.  Otherwise it returns an array of values
67          */
68         param : function(p) {
69             if(this.data[p] == null) return null;
70             if(this.data[p].length == 1)
71                 return this.data[p][0];
72             return this.data[p];
73         },
74
75         /* returns an array of param names */
76         keys : function() {
77             return this._keys;
78         },
79
80         /* debugging method */
81         toString : function() {
82             var string = "";
83             var keys = this.keys();
84
85             for( var k in keys ) {
86                 string += keys[k] + " : ";
87                 var params = this.param(keys[k]);
88
89                 for( var p in params ) {
90                     string +=  params[p] + " ";
91                 }
92                 string += "\n";
93             }
94             return string;
95         }
96     });
97 }
98
99