PageSourceSearch

https://www.lgp.enit.fr/plugins/cms/resources/js/AmetysFront/ServerComm.fr.js

js enit.fr collected 2026-10-02 03:45:04 UTC 9,001 bytes, 235 lines download raw bytes

1/*
2 *  Copyright 2023 Anyware Services
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 */
16
17function ping() 
18{
19    window.setTimeout(function() { 
20        AmetysFront.ServerComm.send({
21            plugin: 'core-ui',
22            url: 'system-startuptime.xml',
23            responseType: 'xml',
24     
25            callback: {
26                handler: function(response) {
27                    ping();
28                },
29                errorHandler: function() {}
30            }
31        }); 
32    }, 60000);
33}
34ping();
35 
36AmetysFront.ServerComm = {
37    
38    SERVERCOMM_URL: undefined,
39    
40    callMethod: function(options)
41    {
42        return this.send({
43            plugin: 'core-ui',
44            url: 'client-call',
45            responseType: 'json',
46            parameters: {
47                role: options.role,
48                id: options.id,
49                methodName: options.methodName,
50                parameters: options.parameters || []
51            },
52            callback: options.callback
53        });
54    },
55    
56    send: function(options)
57    {
58        if (!AmetysFront.ServerComm.SERVERCOMM_URL)
59        {
60            AmetysFront.ServerComm.SERVERCOMM_URL = AmetysFront.getPluginDirectPrefix('cms') + '/servercomm/fo-messages.xml';
61        }
62        
63        var defaultOpts = {
64            pluginOrWorkspace: options.plugin,
65            responseType: 'json',
66            parameters: {},
67            showSuccess: false,
68            showError: true,
69            showWait: false,
70            upload: false
71        };
72        
73        // Copies default options if they don't already exist in options.
74        for (var property in defaultOpts) {
75            if (options[property] === undefined) {
76                options[property] = defaultOpts[property];
77            }
78        }
79        
80        var contentJson = JSON.stringify({
81            pluginOrWorkspace: options.pluginOrWorkspace,
82            url: options.url,
83            parameters: options.parameters,
84            responseType: options.responseType
85        });
86        
87        var contextParamsJson = JSON.stringify(AmetysFront.getAppParameters());
88        
89        var data = new FormData();
90        data.append("content", contentJson);
91        data.append("context.parameters", contextParamsJson);
92
93        // add uploaded files
94        if (options.parameters.parameters && options.parameters.parameters.forEach)
95        {
96            var totalSize = 1000; // Let's keep some size for request overhead
97                
98            options.parameters.parameters.forEach(function(param, index) {
99                if (param instanceof File)
100                {
101                    data.append("file-" + index, param);
102                    options.parameters.parameters[index] = null;
103                    totalSize += param.size;
104                }
105                else if (param instanceof Array)
106                {
107                    for (let i in param)
108                    {
109                        let subParam = param[i];
110                        if (subParam instanceof File)
111                        {
112                            data.append("file-" + index + "-" + i, subParam);
113                            options.parameters.parameters[index][i] = null;
114                            totalSize += subParam.size;
115                        }
116                    }
117                }
118            });
119            
120            if (totalSize > AmetysFront.MAX_UPLOAD_SIZE)
121            {
122                let errorText = "Le ou les fichiers sélectionnés sont trop volumineux : {0} pour {1} de taille maximale autorisée."
123                                    .replace(/\{0\}/g, AmetysFront.Utils.getReadableSize(totalSize))
124                                    .replace(/\{1\}/g, AmetysFront.Utils.getReadableSize(AmetysFront.MAX_UPLOAD_SIZE));
125                if (AmetysFront.Event)
126                {
127                    AmetysFront.Event.fire('loaderFail', {
128                        title: "Taille maximale dépassée",
129                        text : errorText
130                    });
131                }
132                if (options.callback)
133                {
134                    let callback = options.callback;
135                    (callback.errorHandler || callback.handler).apply(callback.scope, [callback.errorHandler ? errorText : null, callback.arguments]);
136                }
137                throw new Error("Cannot send files of " + totalSize + " bytes. The max size is " + AmetysFront.MAX_UPLOAD_SIZE + " bytes.");
138            }
139        }
140        
141        $j.ajax({ 
142            url: AmetysFront.ServerComm.SERVERCOMM_URL, 
143            dataType: "xml",
144            data: data,
145            contentType: false,
146            processData: false,
147            method: 'POST',
148            type: 'POST',
149            
150            success: function(response, status, xhr) 
151            { 
152                var responseElement = response.documentElement;
153                
154                var responseCode = responseElement ? responseElement.getAttribute("code") : null,
155                    isBadResponse = !responseCode || responseCode != '200';
156                
157                var callback = options.callback;
158                
159                if (responseElement && responseElement.tagName == "NotConnected")
160                {
161                    if (AmetysFront.Event)
162                    {
163                        AmetysFront.Event.fire('loaderFail', {
164                                title: "{i18n plugin.cms:PLUGINS_CMS_FRONT_SERVERCOMM_ERROR_FATAL_SESSION_TITLE}}",
165                                text: "{i18n plugin.cms:PLUGINS_CMS_FRONT_SERVERCOMM_ERROR_FATAL_SESSION_DESCRIPTION}}",
166                                details: null,
167                                fatal: 'session'
168                        });
169                        return;
170                    }
171                }
172                else if (isBadResponse)
173                {
174                    if (callback)
175                    {
176                        (callback.errorHandler || callback.handler).apply(callback.scope, [callback.errorHandler ? $j("> message", responseElement).text() : null, callback.arguments]);
177                    }
178                    else if (AmetysFront.Event)
179                    {
180                        AmetysFront.Event.fire('loaderFail', {
181                                title: null,
182                                text: null,
183                                details: null
184                        });
185                    }
186                    return;
187                }
188                
189                var responseData = responseElement; // xml response type
190                if (options.responseType == 'json')
191	            {
192	                responseData = JSON.parse(responseElement.textContent);
193	            }
194	            
195                if (callback)
196                {
197                    callback.handler.apply(callback.scope, [responseData, callback.arguments]);
198                }
199            },
200            
201            error: function(xhr, status, error)
202            {
203                window.console.error("Exception in AmetysFront.ServerComm " + error);
204                
205                if (AmetysFront.Event)
206                {
207                    if (xhr.status == 503)
208                    {
209                        AmetysFront.Event.fire('loaderFail', {
210                                title: "Le serveur est en maintenance",
211                                text: "Une opération de maintenance est en cours sur le serveur. Vous pouvez essayer de recharger la page.",
212                                details: null,
213                                fatal: 'maintenance'
214                        });
215                    }
216                    else
217                    {
218                        AmetysFront.Event.fire('loaderFail', {
219                                title: "La connexion avec le serveur a été perdue",
220                                text: "Cela peut provenir d'un problème de votre connexion au réseau ou d'une opération de maintenance sur le serveur",
221                                details: null,
222                                fatal: 'server'
223                        });
224                    }
225                }
226                
227                var callback = options.callback;
228                if (callback)
229                {
230                    (callback.errorHandler || callback.handler).apply(callback.scope, [null, callback.arguments]);
231                }
232            }
233        });
234    }
235}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.