Passed
Push — main ( 8fa9e1...957ef0 )
by Thierry
06:37
created

jaxon-js/src/config.js   A

Complexity

Total Complexity 18
Complexity/F 1.2

Size

Lines of Code 265
Function Count 15

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 85
c 0
b 0
f 0
dl 0
loc 265
rs 10
wmc 18
mnd 3
bc 3
fnc 15
bpm 0.2
cpm 1.2
noi 0
1
/*
2
    @package jaxon
3
    @version $Id: jaxon.core.js 327 2007-02-28 16:55:26Z calltoconstruct $
4
    @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
5
    @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson
6
    @copyright Copyright (c) 2017 by Thierry Feuzeu, Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson
7
    @license https://opensource.org/license/bsd-3-clause/ BSD License
8
*/
9
10
/**
11
 * Class: jaxon
12
 */
13
var jaxon = {
14
    /**
15
     * Version number
16
     */
17
    version: {
18
        number: '5.0.11',
19
    },
20
21
    debug: {
22
        /**
23
         * Class: jaxon.debug.verbose
24
         *
25
         * Provide a high level of detail which can be used to debug hard to find problems.
26
         */
27
        verbose: {},
28
    },
29
30
    ajax: {
31
        callback: {},
32
        command: {},
33
        parameters: {},
34
        request: {},
35
        response: {},
36
        upload: {},
37
    },
38
39
    cmd: {
40
        node: {},
41
        script: {},
42
        event: {},
43
        dialog: {},
44
    },
45
46
    parser: {
47
        attr: {},
48
        call: {},
49
        query: {},
50
    },
51
52
    utils: {
53
        dom: {},
54
        form: {},
55
        queue: {},
56
        types: {},
57
        string: {},
58
        logger: {},
59
    },
60
61
    dom: {},
62
63
    dialog: {},
64
65
    config: {},
66
};
67
68
/**
69
 * This object contains all the default configuration settings.
70
 * These are application level settings; however, they can be overridden by
71
 * specifying the appropriate configuration options on a per call basis.
72
 */
73
(function(self, logger) {
74
    /**
75
     * An array of header entries where the array key is the header option name and
76
     * the associated value is the value that will set when the request object is initialized.
77
     *
78
     * These headers will be set for both POST and GET requests.
79
     */
80
    self.commonHeaders = {
81
        'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT'
82
    };
83
84
    /**
85
     * An array of header entries where the array key is the header option name and the
86
     * associated value is the value that will set when the request object is initialized.
87
     */
88
    self.postHeaders = {};
89
90
    /**
91
     * An array of header entries where the array key is the header option name and the
92
     * associated value is the value that will set when the request object is initialized.
93
     */
94
    self.getHeaders = {};
95
96
    /**
97
     * true if jaxon should display a wait cursor when making a request, false otherwise.
98
     */
99
    self.waitCursor = false;
100
101
    /**
102
     * true if jaxon should log the status to the console during a request, false otherwise.
103
     */
104
    self.statusMessages = false;
105
106
    /**
107
     * The base document that will be used throughout the code for locating elements by ID.
108
     */
109
    self.baseDocument = document;
110
111
    /**
112
     * The URI that requests will be sent to.
113
     *
114
     * @var {string}
115
     */
116
    self.requestURI = document.URL;
117
118
    /**
119
     * The request mode.
120
     * - 'asynchronous' - The request will immediately return, the response will be processed
121
     *   when (and if) it is received.
122
     * - 'synchronous' - The request will block, waiting for the response.
123
     *   This option allows the server to return a value directly to the caller.
124
     */
125
    self.defaultMode = 'asynchronous';
126
127
    /**
128
     * The Hyper Text Transport Protocol version designated in the header of the request.
129
     */
130
    self.defaultHttpVersion = 'HTTP/1.1';
131
132
    /**
133
     * The content type designated in the header of the request.
134
     */
135
    self.defaultContentType = 'application/x-www-form-urlencoded';
136
137
    /**
138
     * The delay time, in milliseconds, associated with the <jaxon.callback.onRequestDelay> event.
139
     */
140
    self.defaultResponseDelayTime = 1000;
141
142
    /**
143
     * Always convert the reponse content to json.
144
     */
145
    self.convertResponseToJson = true;
146
147
    /**
148
     * The amount of time to wait, in milliseconds, before a request is considered expired.
149
     * This is used to trigger the <jaxon.callback.onExpiration event.
150
     */
151
    self.defaultExpirationTime = 10000;
152
153
    /**
154
     * The method used to send requests to the server.
155
     * - 'POST': Generate a form POST request
156
     * - 'GET': Generate a GET request; parameters are appended to <jaxon.config.requestURI> to form a URL.
157
     */
158
    self.defaultMethod = 'POST'; // W3C = Method is case sensitive
159
160
    /**
161
     * The number of times a request should be retried if it expires.
162
     */
163
    self.defaultRetry = 5;
164
165
    /**
166
     * The maximum depth of recursion allowed when serializing objects to be sent to the server in a request.
167
     */
168
    self.maxObjectDepth = 20;
169
170
    /**
171
     * The maximum number of members allowed when serializing objects to be sent to the server in a request.
172
     */
173
    self.maxObjectSize = 2000;
174
175
    /**
176
     * The maximum number of commands allowed in a single response.
177
     */
178
    self.commandQueueSize = 1000;
179
180
    /**
181
     * The maximum number of requests that can be processed simultaneously.
182
     */
183
    self.requestQueueSize = 1000;
184
185
    /**
186
     * Common options for all HTTP requests to the server.
187
     */
188
    self.httpRequestOptions = {
189
        mode: "cors", // no-cors, *cors, same-origin
190
        cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
191
        credentials: "same-origin", // include, *same-origin, omit
192
        redirect: "manual", // manual, *follow, error
193
    };
194
195
    /**
196
     * Class: jaxon.config.status
197
     *
198
     * Provides support for updating the browser's status bar during the request process.
199
     * By splitting the status bar functionality into an object, the jaxon developer has the opportunity
200
     * to customize the status bar messages prior to sending jaxon requests.
201
     */
202
    self.status = {
203
        /**
204
         * A set of event handlers that will be called by the
205
         * jaxon framework to set the status bar messages.
206
         *
207
         * @type {object}
208
         */
209
        update: {
210
            onPrepare: () => logger.consoleMode().debug('Sending Request...'),
211
            onRequest: () => logger.consoleMode().debug('Waiting for Response...'),
212
            onProcessing: () => logger.consoleMode().debug('Processing...'),
213
            onComplete: () => logger.consoleMode().debug('Done.'),
214
        },
215
216
        /**
217
         * A set of event handlers that will be called by the
218
         * jaxon framework where status bar updates would normally occur.
219
         *
220
         * @type {object}
221
         */
222
        dontUpdate: {
223
            onPrepare: () => {},
224
            onRequest: () => {},
225
            onProcessing: () => {},
226
            onComplete: () => {}
227
        },
228
    };
229
230
    /**
231
     * Class: jaxon.config.cursor
232
     *
233
     * Provides the base functionality for updating the browser's cursor during requests.
234
     * By splitting this functionality into an object of it's own, jaxon developers can now
235
     * customize the functionality prior to submitting requests.
236
     */
237
    self.cursor = {
238
        /**
239
         * Constructs and returns a set of event handlers that will be called by the
240
         * jaxon framework to effect the status of the cursor during requests.
241
         *
242
         * @type {object}
243
         */
244
        update: {
245
            onRequest: () => {
246
                if (jaxon.config.baseDocument.body) {
247
                    jaxon.config.baseDocument.body.style.cursor = 'wait';
248
                }
249
            },
250
            onComplete: () => {
251
                if (jaxon.config.baseDocument.body) {
252
                    jaxon.config.baseDocument.body.style.cursor = 'auto';
253
                }
254
            },
255
            onFailure: function() {
256
                if (jaxon.config.baseDocument.body) {
257
                    jaxon.config.baseDocument.body.style.cursor = 'auto';
258
                }
259
            },
260
        },
261
262
        /**
263
         * Constructs and returns a set of event handlers that will be called by the jaxon framework
264
         * where cursor status changes would typically be made during the handling of requests.
265
         *
266
         * @type {object}
267
         */
268
        dontUpdate: {
269
            onRequest: () => {},
270
            onComplete: () => {},
271
            onFailure: () => {},
272
        },
273
    };
274
})(jaxon.config, jaxon.utils.logger);
275
276
// Make jaxon accessible with the dom.findFunction function.
277
window.jaxon = jaxon;
278