source: trunk/themes/default/js/scripts.js @ 6577

Last change on this file since 6577 was 6577, checked in by rvelices, 14 years ago

merge r6575-6576 from branch 2.1
-removed use of fix-khtml.css (I tried Safari and it does not need it)

  • better javascript funcs + shorter notation
  • Property svn:eol-style set to LF
File size: 3.9 KB
Line 
1function SelectAll( formulaire )
2{
3var elts = formulaire.elements;
4for(var i=0; i <elts.length; i++)
5{
6        if (elts[i].type=='checkbox')
7                elts[i].checked = true;
8}
9}
10
11function DeselectAll( formulaire )
12{
13var elts = formulaire.elements;
14for(var i=0; i <elts.length; i++)
15{
16        if (elts[i].type=='checkbox')
17                elts[i].checked = false;
18}
19}
20
21function Inverser( formulaire )
22{
23var elts = formulaire.elements;
24for(var i=0; i <elts.length; i++)
25{
26        if (elts[i].type=='checkbox')
27                elts[i].checked = !elts[i].checked;
28}
29}
30
31function phpWGOpenWindow(theURL,winName,features)
32{
33        img = new Image();
34        img.src = theURL;
35        if (img.complete)
36        {
37                var width=img.width+40, height=img.height+40;
38        }
39        else
40        {
41                var width=640, height=480;
42                img.onload = function () { newWin.resizeTo( img.width+50, img.height+100); };
43        }
44        newWin = window.open(theURL,winName,features+',left=2,top=1,width=' + width + ',height=' + height);
45}
46
47function popuphelp(url)
48{
49        window.open( url, 'dc_popup',
50                'alwaysRaised=yes,dependent=yes,toolbar=no,height=420,width=500,menubar=no,resizable=yes,scrollbars=yes,status=no'
51        );
52}
53
54Function.prototype.pwgBind = function() {
55                var __method = this, object = arguments[0], args = Array.prototype.slice.call(arguments,1);
56                return function() {
57                                return __method.apply(object, args.concat(arguments) );
58                }
59}
60function PwgWS(urlRoot)
61{
62        this.urlRoot = urlRoot;
63        this.options = {
64                method: "GET",
65                async:  true,
66                onFailure: null,
67                onSuccess: null
68        };
69};
70
71PwgWS.prototype = {
72
73        callService : function(method, parameters, options)
74        {
75                if (options)
76                {
77                        for (var property in options)
78                                this.options[property] = options[property];
79                }
80                try { this.transport = new XMLHttpRequest();}
81                catch(e) {
82                        try { this.transport = new ActiveXObject('Msxml2.XMLHTTP'); }
83                        catch(e) {
84                                try { this.transport = new ActiveXObject('Microsoft.XMLHTTP'); }
85                                catch (e){
86                                        dispatchError(0, "Cannot create request object");
87                                }
88                        }
89                }
90                this.transport.onreadystatechange = this.onStateChange.pwgBind(this);
91
92                var url = this.urlRoot+"ws.php?format=json";
93
94                var body = "method="+method;
95                if (parameters)
96                {
97                        for (var property in parameters)
98                        {
99                                if ( typeof parameters[property] == 'object' && parameters[property])
100                                {
101                                        for (var i=0; i<parameters[property].length; i++)
102                                                body += "&"+property+"[]="+encodeURIComponent(parameters[property][i]);
103                                }
104                                else
105                                        body += "&"+property+"="+encodeURIComponent(parameters[property]);
106                        }
107                }
108
109                if (this.options.method == "POST" )
110                {
111                        this.transport.open(this.options.method, url, this.options.async);
112                        this.transport.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
113                        this.transport.send(body);
114                }
115                else
116                {
117                        url += "&"+body;
118                        this.transport.open(this.options.method, url, this.options.async);
119                        this.transport.send(null);
120                }
121        },
122
123        onStateChange: function() {
124                var readyState = this.transport.readyState;
125                if (readyState==4)
126                        this.respondToReadyState(readyState);
127        },
128
129        dispatchError: function( httpCode, text )
130        {
131                !this.options.onFailure || this.options.onFailure( httpCode, text);
132        },
133
134        respondToReadyState: function(readyState)
135        {
136                var transport = this.transport;
137                if (readyState==4 && transport.status == 200)
138                {
139                        var resp;
140                        try {
141                                eval('resp = ' + transport.responseText);
142                        }
143                        catch (e) {
144                                this.dispatchError( 200, e.message + '\n' + transport.responseText.substr(0,512) );
145                        }
146                        if (resp!=null)
147                        {
148                                if (resp.stat==null)
149                                        this.dispatchError( 200, "Invalid response" );
150                                else if (resp.stat=='ok')
151                                {
152                                        if (this.options.onSuccess) this.options.onSuccess( resp.result );
153                                }
154                                else
155                                        this.dispatchError( 200, resp.err + " " + resp.message);
156                        }
157                }
158                if (readyState==4 && transport.status != 200)
159                        this.dispatchError( transport.status, transport.statusText );
160        },
161
162
163        transport: null,
164        urlRoot: null,
165        options: {}
166}
167
168function pwgAddEventListener(elem, evt, fn)
169{
170        if (window.attachEvent)
171                elem.attachEvent('on'+evt, fn);
172        else
173                elem.addEventListener(evt, fn, false);
174}
Note: See TracBrowser for help on using the repository browser.