source: trunk/template-common/scripts.js @ 3930

Last change on this file since 3930 was 3282, checked in by plg, 15 years ago

change: according to topic:15067, svn:keywords property was removed

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