UNPKG

60.7 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/net/REST/CB_Net_REST.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/net/REST/CB_Net_REST.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} client, services and related management. Contains the {@link CB_Net.REST} static class.
89 * @author Joan Alba Maldonado &lt;workindalian@gmail.com>
90 * @license Creative Commons Attribution 4.0 International. See more at {@link https://crossbrowdy.com/about#what_is_the_crossbrowdy_copyright_and_license}.
91 */
92
93if (typeof(CB_Net) === "undefined") { var CB_Net = function() { return CB_Net; }; }
94
95/**
96 * Static class to manage [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} services and related. It will return itself if it is tried to be instantiated.
97 * @namespace
98 * @todo Think about accepting an onAbort function as option (with also default and permanent).
99 */
100CB_Net.REST = function() { return CB_Net.REST; };
101{
102 CB_Net.REST.initialized = false; //It will tells whether the object has been initialized or not.
103
104
105 /**
106 * Defines the URL for the default [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} server to use when the "serverURL" parameter is not available. Used by the {@link CB_Net.XHR.callREST} function as the default "serverURL" parameter.
107 * @var
108 * @type {string}
109 * @default
110 */
111 CB_Net.REST.SERVER_URL_DEFAULT = "http://localhost/CrossBrowdy/tests/net/fake_rest_server/index.php"; //CHANGE THIS!
112
113
114 /**
115 * Default value when the "avoidProxy" parameter is not available. Used by the {@link CB_Net.REST.actionProcess} function.
116 &lt;br />
117 NOTE: Edit the "CB_proxy.config.php" file to configure the default proxy (set by default in the value of the {@link CB_Configuration.CrossBase.CB_Net_XHR_PROXY_URL} property). Apart from configuring it, adding some security measures is highly recommended.
118 Have in mind that, for safety reasons, the default proxy only allows to request the URLs defined in the "$allowedURLs" array in the "CB_proxy.config.php" file. Just edit it to allow other URLs.
119 * @var
120 * @type {boolean}
121 * @default
122 */
123 CB_Net.REST.avoidProxy_DEFAULT = false;
124
125
126 /**
127 * Default "method" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions. Used by the {@link CB_Net.REST.actionProcess} function.
128 * @var
129 * @type {string}
130 * @default
131 */
132 CB_Net.REST.method_DEFAULT = "GET";
133
134
135 /**
136 * Default "responseType" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions when it is not provided and it is not null. Used by the {@link CB_Net.REST.actionProcess} function.
137 * @var
138 * @type {string}
139 * @default
140 */
141 CB_Net.REST.responseType_DEFAULT = "text";
142
143
144 /**
145 * Callback returning an object that will be used for parsing the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} route. The object returned should follow the same rules as the "JSONObject" parameter of the {@link CB_renderString} function.
146 * @callback CB_Net.REST.actionProcess_ROUTE_WILDCARD_DATA
147 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
148 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
149 * @returns {Object|null} It should return an object containing the wildcards that will be used to parse the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} route of the action being performed. Return null in the case that we do not want to modify anything. The object returned (if any) will be used as the "JSONObject" parameter of the {@link CB_renderString} function (the first parameter will be the route which should be a string) when it is called by {@link CB_Net.REST.actionProcess} internally.
150 */
151
152
153 /**
154 * Permanent function (must return a [JSON]{@link https://en.wikipedia.org/wiki/JSON} object or null if we do not want to modify it) to execute the same way as the "routeWildcardData" parameter (if other "routeWildcardData" are provided or set, they will be executed before this one). The function assigned by default returns null. Used by the {@link CB_Net.REST.actionProcess} function. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
155 * @var
156 * @type {CB_Net.REST.actionProcess_ROUTE_WILDCARD_DATA}
157 * @default
158 */
159 CB_Net.REST.routeWildcardData_PERMANENT =
160 function(actionName, additionalData)
161 {
162 return null;
163 };
164
165
166 /**
167 * Default "routeWildcardData" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions (must be a function returning a [JSON]{@link https://en.wikipedia.org/wiki/JSON} object or null if we do not want to modify the route). The function assigned by default returns null. Used by the {@link CB_Net.REST.actionProcess} function.
168 * @var
169 * @type {CB_Net.REST.actionProcess_ROUTE_WILDCARD_DATA}
170 * @default
171 */
172 CB_Net.REST.routeWildcardData_DEFAULT =
173 function(actionName, additionalData)
174 {
175 return null;
176 };
177
178
179 /**
180 * Tells whether to force [JSON]{@link https://en.wikipedia.org/wiki/JSON} response by default or not. Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "forceJSON" option.
181 * @var
182 * @type {boolean}
183 * @default
184 */
185 CB_Net.REST.forceJSON_DEFAULT = true;
186
187
188 /**
189 * Tells whether get response [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers} by default or not. Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "getHeaders" option.
190 * @var
191 * @type {boolean}
192 * @default
193 */
194 CB_Net.REST.getHeaders_DEFAULT = false;
195
196
197 /**
198 * Tells whether to get response [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers} in one-dimension array by default or not (needs "getHeaders" set to true). Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "getHeadersOneDimension" option.
199 * @var
200 * @type {boolean}
201 * @default
202 */
203 CB_Net.REST.getHeadersOneDimension_DEFAULT = false;
204
205
206 /**
207 * Tells whether to get response [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers} values in one-dimension (just one value per key) by default or not (needs "getHeaders" set to true). Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "getHeadersOneDimensionValues" option.
208 * @var
209 * @type {boolean}
210 * @default
211 */
212 CB_Net.REST.getHeadersOneDimensionValues_DEFAULT = false;
213
214
215 /**
216 * Callback returning an object containing the [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers} which will be used as the "headers" parameter when the {@link CB_Net.XHR.callREST} function is called internally by {@link CB_Net.REST.actionProcess}.
217 * @callback CB_Net.REST.actionProcess_HEADERS
218 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
219 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
220 * @returns {CB_Net.XHR.HEADERS|null} It should return an object containing the [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers}. Return null in the case that we do not want to add anything. The object returned (if any) will be used as the "headers" parameter of the {@link CB_Net.XHR.callREST} function when it is called by {@link CB_Net.REST.actionProcess} internally.
221 */
222
223
224 /**
225 * Permanent function (must be a function returning a {@link CB_Net.XHR.HEADERS} object with the [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers}) to execute the same way as the "headers" parameter. The function assigned by default returns { "Cache-Control" : "no-cache", "Pragma" : "no-cache" }. Used by the {@link CB_Net.REST.actionProcess} function. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
226 * @var
227 * @type {CB_Net.REST.actionProcess_HEADERS}
228 * @default
229 */
230 CB_Net.REST.headers_PERMANENT =
231 function(actionName, additionalData)
232 {
233 return {
234 "Cache-Control" : "no-cache",
235 "Pragma" : "no-cache"
236 }
237 };
238
239
240 /**
241 * Default "headers" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions (must be a function returning a {@link CB_Net.XHR.HEADERS} object with the [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers}). The function assigned by default returns { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }. Used by the {@link CB_Net.REST.actionProcess} function.
242 * @var
243 * @type {CB_Net.REST.actionProcess_HEADERS}
244 * @default
245 */
246 CB_Net.REST.headers_DEFAULT =
247 function(actionName, additionalData)
248 {
249 return {
250 "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8"
251 };
252 };
253
254
255 /**
256 * Tells whether get status transparently from the server by default or not. Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "transparentStatus" option.
257 * @var
258 * @type {boolean}
259 * @default
260 */
261 CB_Net.REST.transparentStatus_DEFAULT = true;
262
263
264 /**
265 * Tells whether get [HTTP headers]{@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers} transparently from the server by default or not. Used by the {@link CB_Net.REST.actionProcess} function when the REST action does not provided it and it is not null, as the "transparentHeaders" option.
266 * @var
267 * @type {boolean}
268 * @default
269 */
270 CB_Net.REST.transparentHeaders_DEFAULT = true;
271
272
273 /**
274 * Callback returning a string containing the URL (GET) data which will be used as the "dataURL" parameter when the {@link CB_Net.XHR.callREST} function is called internally by {@link CB_Net.REST.actionProcess}.
275 * @callback CB_Net.REST.actionProcess_DATA_URL
276 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
277 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
278 * @returns {string} It should return a string containing the URL (GET) data. Return an empty string in the case that we do not want to add anything. The string returned (if any) will be used as the "dataURL" parameter of the {@link CB_Net.XHR.callREST} function when it is called by {@link CB_Net.REST.actionProcess} internally.
279 */
280
281
282 /**
283 * Permanent function (must return a string in URL/GET parameters format) to execute the same way as the "dataURL" parameter. The function assigned by default returns an empty string (""). Used by the {@link CB_Net.REST.actionProcess} function. The returning data will be placed in the beginning of the URL, followed by the rest of the "dataURL" desired (if any). NOTE: remember to use {@link CB_Net.URLValueEncode} if needed. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
284 * @var
285 * @type {CB_Net.REST.actionProcess_DATA_URL}
286 * @default
287 */
288 CB_Net.REST.dataURL_PERMANENT = //NOTE: remember to use CB_Net.URLValueEncode if needed.
289 function(actionName, additionalData)
290 {
291 return "";
292 };
293
294
295 /**
296 * Default "dataURL" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions (must return a string in URL/GET parameters format). The function assigned by default returns an empty string (""). Used by the {@link CB_Net.REST.actionProcess} function. NOTE: remember to use {@link CB_Net.URLValueEncode} if needed.
297 * @var
298 * @type {CB_Net.REST.actionProcess_DATA_URL}
299 * @default
300 */
301 CB_Net.REST.dataURL_DEFAULT = //NOTE: remember to use CB_Net.URLValueEncode if needed.
302 function(actionName, additionalData)
303 {
304 return "";
305 };
306
307
308 /**
309 * Callback returning the data (string or object) which will be used as the "data" parameter when the {@link CB_Net.XHR.callREST} function is called internally by {@link CB_Net.REST.actionProcess}. The values returned by all functions that are mean to return the data should always return the same type of data (all strinngs or all objects) since {@link CB_Net.REST.actionProcess} will use the {@link CB_combineAutomatically} function to combine them.
310 * @callback CB_Net.REST.actionProcess_DATA
311 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
312 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
313 * @returns {string|Object} It should return a string or object containing the data. Return null or an empty string (recommended) in the case that we do not want to add anything. The value returned (if any) will be used as the "data" parameter of the {@link CB_Net.XHR.callREST} function when it is called by {@link CB_Net.REST.actionProcess} internally.
314 */
315
316
317 /**
318 * Permanent function (must return a string in URL/GET parameters format or a [JSON]{@link https://en.wikipedia.org/wiki/JSON} format string) to execute the same way as the "data" parameter. The function assigned by default returns an empty string (""). Used by the {@link CB_Net.REST.actionProcess} function. The values returned by all functions that are mean to return the data should always return the same type of data (all strinngs or all objects) since {@link CB_Net.REST.actionProcess} will use the {@link CB_combineAutomatically} function to combine them. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action. NOTE: remember to use {@link CB_Net.URLValueEncode} if needed.
319 * @var
320 * @type {CB_Net.REST.actionProcess_DATA}
321 * @default
322 */
323 CB_Net.REST.data_PERMANENT = //NOTE: remember to use CB_Net.URLValueEncode if needed.
324 function(actionName, additionalData)
325 {
326 return "";
327 };
328
329
330 /**
331 * Default "data" for [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions (must return a string in URL/GET parameters format or a [JSON]{@link https://en.wikipedia.org/wiki/JSON} format string). The function assigned by default returns an empty string (""). Used by the {@link CB_Net.REST.actionProcess} function. The values returned by all functions that are mean to return the data should always return the same type of data (all strinngs or all objects) since {@link CB_Net.REST.actionProcess} will use the {@link CB_combineAutomatically} function to combine them. NOTE: remember to use {@link CB_Net.URLValueEncode} if needed.
332 * @var
333 * @type {CB_Net.REST.actionProcess_DATA}
334 * @default
335 */
336 CB_Net.REST.data_DEFAULT = //NOTE: remember to use CB_Net.URLValueEncode if needed.
337 function(actionName, additionalData)
338 {
339 return "";
340 };
341
342
343 /**
344 * Permanent values for the "allowedSuccessStatuses" parameter, containing the statuses to considerer a successful [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (must be a numeric array of integers). Used by the {@link CB_Net.REST.actionProcess} function. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
345 * @var
346 * @type {array}
347 * @default
348 */
349 CB_Net.REST.allowedSuccessStatuses_PERMANENT = [];
350
351
352 /**
353 * Default "allowedSuccessStatuses", containing the statuses to considerer a successful [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (must be a numeric array of integers). Used by the {@link CB_Net.REST.actionProcess} function.
354 * @var
355 * @type {array}
356 * @default
357 */
358 CB_Net.REST.allowedSuccessStatuses_DEFAULT = [200, 201, 206];
359
360
361 /**
362 * Callback that will be run before performing a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action and must return a boolean defining whether we want to continue performing the action (returning true) or not (returning false).
363 * @callback CB_Net.REST.actionProcess_CALLBACK_BEFORE
364 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
365 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
366 * @returns {boolean} It should return true in the case that we want to continue performing the current [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action or false otherwise.
367 */
368
369
370 /**
371 * Permanent callback function before performing each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action returning a boolean (to decide whether to do it or not). Executed before the default or the set "callbackBefore" function (if any). The function assigned by default returns true. Used by the {@link CB_Net.REST.actionProcess} function. This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
372 * @var
373 * @type {CB_Net.REST.actionProcess_CALLBACK_BEFORE}
374 * @default
375 */
376 CB_Net.REST.callbackBefore_PERMANENT =
377 function(actionName, additionalData)
378 {
379 return true; //Must return true if we want to perform the action.
380 };
381
382
383 /**
384 * Default "callbackBefore", containing a callback function before performing each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action returning a boolean (to decide whether to do it or not). The function assigned by default returns true. Used by the {@link CB_Net.REST.actionProcess} function.
385 * @var
386 * @type {CB_Net.REST.actionProcess_CALLBACK_BEFORE}
387 * @default
388 */
389 CB_Net.REST.callbackBefore_DEFAULT =
390 function(actionName, additionalData)
391 {
392 return true; //Must return true if we want to perform the action.
393 };
394
395
396
397 /**
398 * Callback that will be run when the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has been performed successfully.
399 * @callback CB_Net.REST.actionProcess_CALLBACK_OK
400 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
401 * @param {Object} [XHR] - The [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object that has been used to perform the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
402 * @param {CB_Net.REST.actionProcess_CALLBACK_ERROR} callbackError - The error callback function associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed, just in case we want to call it.
403 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
404 */
405
406
407 /**
408 * Permanent callback function when each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has been successful. Used by the {@link CB_Net.REST.actionProcess} function. Executed before the default or the set "callbackOk" function (if any). This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
409 * @var
410 * @type {CB_Net.REST.actionProcess_CALLBACK_OK}
411 * @default
412 */
413 CB_Net.REST.callbackOk_PERMANENT =
414 function(actionName, XHR, callbackError, additionalData)
415 {
416 //Do things here.
417 };
418
419
420 /**
421 * Default "callbackOk", containing a callback function when the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has been successful. Used by the {@link CB_Net.REST.actionProcess} function.
422 * @var
423 * @type {CB_Net.REST.actionProcess_CALLBACK_OK}
424 * @default
425 */
426 CB_Net.REST.callbackOk_DEFAULT =
427 function(actionName, XHR, callbackError, additionalData)
428 {
429 //Do things here.
430 };
431
432
433 /**
434 * Callback that will be run when the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has been performed successfully.
435 * @callback CB_Net.REST.actionProcess_CALLBACK_ERROR
436 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
437 * @param {Object} [XHR] - The [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object that has been used to perform the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
438 * @param {*} additionalData - Any additional data associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (belongs to the "additionalData" parameter used when the {@link CB_Net.REST.actionProcess} function was called).
439 */
440
441
442 /**
443 * Permanent callback function when an error happens processing any [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action. Used by the {@link CB_Net.REST.actionProcess} function. Executed before the default or the set "callbackError" function (if any). This is permanent for each [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
444 * @var
445 * @type {CB_Net.REST.actionProcess_CALLBACK_ERROR}
446 * @default
447 */
448 CB_Net.REST.callbackError_PERMANENT =
449 function(actionName, XHR, additionalData)
450 {
451 //Do things here.
452 };
453
454
455 /**
456 * Default "callbackError", containing a callback function when an error happens processing the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action. Used by the {@link CB_Net.REST.actionProcess} function.
457 * @var
458 * @type {CB_Net.REST.actionProcess_CALLBACK_ERROR}
459 * @default
460 */
461 CB_Net.REST.callbackError_DEFAULT =
462 function(actionName, XHR, additionalData)
463 {
464 //Do things here.
465 };
466
467
468 /**
469 * Object that represents a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action.
470 * @memberof CB_Net.REST
471 * @typedef {Object} CB_Net.REST.actionProcess_ACTIONS
472 * @property {string} route - The [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} route (path). Belongs to the "route" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally. It is mandatory.
473 * @property {CB_Net.REST.actionProcess_CALLBACK_BEFORE} [callbackBefore={@link CB_Net.REST.callbackBefore_DEFAULT}] - Callback run before performing the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action which will decide whether to continue with it or not.
474 * @property {boolean} [avoidProxy={@link CB_Net.REST.avoidProxy_DEFAULT}] - Belongs to the "avoidProxy" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
475 * @property {CB_Net.REST.actionProcess_ROUTE_WILDCARD_DATA} [routeWildcardData={@link CB_Net.REST.routeWildcardData_DEFAULT}] - Callback returning an object that will be used for parsing the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} route. The object returned should follow the same rules as the "JSONObject" parameter of the {@link CB_renderString} function.
476 * @property {CB_Net.REST.actionProcess_DATA_URL} [dataURL={@link CB_Net.REST.dataURL_DEFAULT}] - Belongs to the "dataURL" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
477 * @property {CB_Net.REST.actionProcess_DATA} [data={@link CB_Net.REST.data_DEFAULT}] - Belongs to the "data" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
478 * @property {CB_Net.REST.actionProcess_HEADERS} [headers={@link CB_Net.REST.headers_DEFAULT}] - Belongs to the "headers" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
479 * @property {array} [allowedSuccessStatuses={@link CB_Net.REST.allowedSuccessStatuses_DEFAULT}] - Belongs to the "allowedSuccessStatuses" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
480 * @property {CB_Net.REST.actionProcess_CALLBACK_ERROR} [callbackError={@link CB_Net.REST.callbackError_DEFAULT}] - Callback run when the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has not been performed successfully.
481 * @property {CB_Net.REST.actionProcess_CALLBACK_OK} [callbackOk={@link CB_Net.REST.callbackOk_DEFAULT}] - Callback run when the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action has been performed successfully.
482 * @property {string} [serverURL={@link CB_Net.REST.SERVER_URL_DEFAULT}] - Belongs to the "serverURL" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
483 * @property {string} [method={@link CB_Net.REST.method_DEFAULT}] - Belongs to the "method" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
484 * @property {string} [responseType={@link CB_Net.REST.responseType_DEFAULT}] - Belongs to the "responseType" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.responseType_DEFAULT} instead.
485 * @property {boolean} [forceJSON={@link CB_Net.REST.forceJSON_DEFAULT}] - Belongs to the "forceJSON" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.forceJSON_DEFAULT} instead.
486 * @property {boolean} [getHeaders={@link CB_Net.REST.getHeaders_DEFAULT}] - Belongs to the "getHeaders" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.getHeaders_DEFAULT} instead.
487 * @property {boolean} [getHeadersOneDimension={@link CB_Net.REST.getHeadersOneDimension_DEFAULT}] - Belongs to the "getHeadersOneDimension" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.getHeadersOneDimension_DEFAULT} instead.
488 * @property {boolean} [getHeadersOneDimensionValues={@link CB_Net.REST.getHeadersOneDimensionValues_DEFAULT}] - Belongs to the "getHeadersOneDimensionValues" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.getHeadersOneDimensionValues_DEFAULT} instead.
489 * @property {boolean} [transparentStatus={@link CB_Net.REST.transparentStatus_DEFAULT}] - Belongs to the "transparentStatus" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.transparentStatus_DEFAULT} instead.
490 * @property {boolean} [transparentHeaders={@link CB_Net.REST.transparentHeaders_DEFAULT}] - Belongs to the "transparentHeaders" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally and will be sent even it is null. If it is undefined, it will use the value of {@link CB_Net.REST.transparentHeaders_DEFAULT} instead.
491 */
492
493
494 /**
495 * List of [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} actions. Each property name is the name of the action and its value is a {@link CB_Net.REST.actionProcess_ACTIONS} object. Used by the {@link CB_Net.REST.actionProcess} function.
496 * @var
497 * @type {Object}
498 * @default
499 */
500 CB_Net.REST.actions = {}; //Read the documentation to know how to add new REST actions.
501
502
503
504 //Initializes all values:
505 CB_Net.REST.init = function()
506 {
507 if (CB_Net.REST.initialized) { return CB_Net.REST; }
508
509 //The object has been initialized:
510 CB_Net.REST.initialized = true;
511
512 //TODO.
513
514 return CB_Net.REST;
515 }
516
517
518 /**
519 * Processes a desired [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (which must be previously defined in the {@link CB_Net.REST.actions} object) by its name.
520 &lt;br />
521 NOTE: Edit the "CB_proxy.config.php" file to configure the default proxy (set by default in the value of the {@link CB_Configuration.CrossBase.CB_Net_XHR_PROXY_URL} property). Apart from configuring it, adding some security measures is highly recommended.
522 Have in mind that, for safety reasons, the default proxy only allows to request the URLs defined in the "$allowedURLs" array in the "CB_proxy.config.php" file. Just edit it to allow other URLs.
523 * @function
524 * @param {string} actionName - The name of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action that we want to perform. It should be the name of an index defined in the {@link CB_Net.REST.actions} object whose value should be a {@link CB_Net.REST.actionProcess_ACTIONS} object.
525 * @param {*} [additionalData] - Any additional data desired. It will be passed as a parameter when different callbacks are called internally, as their "additionalData" parameter.
526 * @param {Object} [XHR] - Used for the "XHR" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally.
527 * @param {string} [serverURL] - Used for the "serverURL" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally. If provided, the value defined in the "serverURL" parameter of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (if any) will be ignored.
528 * @param {boolean} [avoidProxy] - Used for the "avoidProxy" parameter of the {@link CB_Net.XHR.callREST} function when it is called internally. If provided, the value defined in the "avoidProxy" parameter of the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action being performed (if any) and the default one defined in {@link CB_Net.REST.avoidProxy_DEFAULT} (if any) will be both ignored.
529 * @returns {Object|null} Returns null if the {@link CB_Net.XHR.callREST} function is not called at all (because [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} is not supported or the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action object cannot be found or the route is not well defined or the "callbackBefore" returns false, etc.). Otherwise, returns the same that the {@link CB_Net.XHR.callREST} function returns (called internally).
530 */
531 CB_Net.REST.actionProcess = function(actionName, additionalData, XHR, serverURL, avoidProxy)
532 {
533 if (!CB_Net.XHR.supported()) { return null; }
534
535 if (typeof(CB_Net.REST.actions[actionName]) === "undefined" || CB_Net.REST.actions[actionName] === null) { return null; }
536 else if (typeof(CB_Net.REST.actions[actionName]["route"]) === "undefined" || CB_Net.REST.actions[actionName]["route"] === null) { return null; }
537
538 //Performs the previous callback (if any):
539 var callbackBeforeReturn = typeof(CB_Net.REST.callbackBefore_PERMANENT === "function") ? CB_Net.REST.callbackBefore_PERMANENT(actionName, additionalData) : null;
540 if (callbackBeforeReturn !== false)
541 {
542 if (typeof(CB_Net.REST.actions[actionName]["callbackBefore"]) === "function") { callbackBeforeReturn = CB_Net.REST.actions[actionName]["callbackBefore"](actionName, additionalData); }
543 else if (typeof(CB_Net.REST.actions[actionName]["callbackBefore"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.callbackBefore_DEFAULT) === "function") { callbackBeforeReturn = CB_Net.REST.callbackBefore_DEFAULT(actionName, additionalData); }
544 }
545 if (callbackBeforeReturn === false) { return null; } //If we do not want to perform the action, exists and returns NULL.
546
547 serverURL = CB_trim(serverURL);
548 if (serverURL === "" &amp;&amp; typeof(CB_Net.REST.actions[actionName]["serverURL"]) !== "undefined" &amp;&amp; CB_isString(CB_Net.REST.actions[actionName]["serverURL"]))
549 {
550 serverURL = CB_trim(CB_Net.REST.actions[actionName]["serverURL"]);
551 }
552
553 if (avoidProxy !== true &amp;&amp; avoidProxy !== false)
554 {
555 if (typeof(CB_Net.REST.actions[actionName]["avoidProxy"]) !== "undefined" &amp;&amp; (CB_Net.REST.actions[actionName]["avoidProxy"] === true || CB_Net.REST.actions[actionName]["avoidProxy"] === false)) { avoidProxy = CB_Net.REST.actions[actionName]["avoidProxy"]; }
556 else if (typeof(CB_Net.REST.avoidProxy_DEFAULT) !== "undefined" &amp;&amp; (CB_Net.REST.avoidProxy_DEFAULT === true || CB_Net.REST.avoidProxy_DEFAULT === false)) { avoidProxy = CB_Net.REST.avoidProxy_DEFAULT; }
557 }
558
559 var route = CB_Net.REST.actions[actionName]["route"];
560 var wildcardData = null;
561 if (typeof(CB_Net.REST.actions[actionName]["routeWildcardData"]) === "function")
562 {
563 wildcardData = CB_Net.REST.actions[actionName]["routeWildcardData"](actionName, additionalData);
564 }
565 else if (typeof(CB_Net.REST.actions[actionName]["routeWildcardData"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.routeWildcardData_DEFAULT) === "function")
566 {
567 wildcardData = CB_Net.REST.routeWildcardData_DEFAULT(actionName, additionalData);
568 }
569 wildcardData = CB_combineAutomatically(CB_Net.REST.routeWildcardData_PERMANENT(actionName, additionalData), wildcardData, false);
570 if (wildcardData !== null) { route = CB_renderString(CB_Net.REST.actions[actionName]["route"], wildcardData); }
571
572 //Gets the data for URL (GET):
573 var dataURL = "";
574 if (typeof(CB_Net.REST.actions[actionName]["dataURL"]) === "function")
575 {
576 dataURL = CB_Net.REST.actions[actionName]["dataURL"](actionName, additionalData);
577 }
578 else if (typeof(CB_Net.REST.actions[actionName]["dataURL"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.dataURL_DEFAULT) === "function")
579 {
580 dataURL = CB_Net.REST.dataURL_DEFAULT(actionName, additionalData);
581 }
582 dataURL = CB_trim(CB_trim(dataURL), ["?", "&amp;", " "]);
583 var dataURLPermanent = CB_Net.REST.dataURL_PERMANENT(actionName, additionalData);
584 dataURLPermanent = CB_trim(CB_trim(dataURLPermanent), ["?", "&amp;", " "]);
585 if (dataURLPermanent !== "") { dataURL = CB_combineAutomatically(dataURLPermanent, dataURL, false); }
586
587 //Defines the data:
588 var data = "";
589 if (typeof(CB_Net.REST.actions[actionName]["data"]) === "function")
590 {
591 data = CB_Net.REST.actions[actionName]["data"](actionName, additionalData);
592 }
593 else if (typeof(CB_Net.REST.actions[actionName]["data"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.data_DEFAULT) === "function")
594 {
595 data = CB_Net.REST.data_DEFAULT(actionName, additionalData);
596 }
597 data = CB_combineAutomatically(CB_Net.REST.data_PERMANENT(actionName, additionalData), data, false);
598
599 //Defines the headers:
600 var headers = null;
601 if (typeof(CB_Net.REST.actions[actionName]["headers"]) === "function")
602 {
603 headers = CB_Net.REST.actions[actionName]["headers"](actionName, additionalData);
604 }
605 else if (typeof(CB_Net.REST.actions[actionName]["headers"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.headers_DEFAULT) === "function")
606 {
607 headers = CB_Net.REST.headers_DEFAULT(actionName, additionalData);
608 }
609 headers = CB_combineAutomatically(CB_Net.REST.headers_PERMANENT(actionName, additionalData), headers, false);
610
611 //Defines the allowed statuses considered as successful:
612 var allowedSuccessStatuses = CB_Net.REST.allowedSuccessStatuses_DEFAULT;
613 if (typeof(CB_Net.REST.actions[actionName]["allowedSuccessStatuses"]) !== "undefined")
614 {
615 allowedSuccessStatuses = CB_Net.REST.actions[actionName]["allowedSuccessStatuses"];
616 }
617 allowedSuccessStatuses = CB_combineAutomatically(CB_Net.REST.allowedSuccessStatuses_PERMANENT, allowedSuccessStatuses, true);
618
619 //Defines the callback functions:
620 var callbackError =
621 function(actionName, XHRObject, additionalData)
622 {
623 if (typeof(CB_Net.REST.callbackError_PERMANENT) === "function") { CB_Net.REST.callbackError_PERMANENT(actionName, XHRObject, additionalData); }
624 if (typeof(CB_Net.REST.actions[actionName]["callbackError"]) === "function")
625 {
626 CB_Net.REST.actions[actionName]["callbackError"](actionName, XHRObject, additionalData);
627 }
628 else if (typeof(CB_Net.REST.actions[actionName]["callbackError"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.callbackError_DEFAULT) === "function")
629 {
630 CB_Net.REST.callbackError_DEFAULT(actionName, XHRObject, additionalData);
631 }
632 };
633
634 var callbackErrorWrapper =
635 function(XHRObject)
636 {
637 if (typeof(callbackError) === "function") { callbackError.call(XHRObject, actionName, XHRObject, additionalData); }
638 };
639
640 var callbackOkWrapper =
641 function(XHRObject)
642 {
643 if (CB_Net.REST.actionIsAborted(XHRObject)) { return; }
644 if (typeof(CB_Net.REST.callbackOk_PERMANENT) === "function") { CB_Net.REST.callbackOk_PERMANENT.call(XHRObject, actionName, XHRObject, callbackError, additionalData); }
645 if (typeof(CB_Net.REST.actions[actionName]["callbackOk"]) === "function")
646 {
647 CB_Net.REST.actions[actionName]["callbackOk"].call(XHRObject, actionName, XHRObject, callbackError, additionalData);
648 }
649 else if (typeof(CB_Net.REST.actions[actionName]["callbackOk"]) === "undefined" &amp;&amp; typeof(CB_Net.REST.callbackOk_DEFAULT) === "function")
650 {
651 CB_Net.REST.callbackOk_DEFAULT.call(XHRObject, actionName, XHRObject, callbackError, additionalData);
652 }
653 };
654
655 //Calls the REST server:
656 return CB_Net.XHR.callREST
657 (
658 //typeof(CB_Net.REST.actions[actionName]["serverURL"]) !== "undefined" &amp;&amp; CB_isString(CB_Net.REST.actions[actionName]["serverURL"]) &amp;&amp; CB_trim(CB_Net.REST.actions[actionName]["serverURL"]) !== "" ? CB_trim(CB_Net.REST.actions[actionName]["serverURL"]) : serverURL, //serverURL
659 serverURL, //serverURL
660 route, //route
661 dataURL, //dataURL
662 typeof(CB_Net.REST.actions[actionName]["method"]) !== "undefined" &amp;&amp; CB_isString(CB_Net.REST.actions[actionName]["method"]) &amp;&amp; CB_trim(CB_Net.REST.actions[actionName]["method"]) !== "" ? CB_trim(CB_Net.REST.actions[actionName]["method"]) : CB_Net.REST.method_DEFAULT, //method
663 data, //data
664 headers, //headers
665 typeof(CB_Net.REST.actions[actionName]["responseType"]) !== "undefined" ? CB_Net.REST.actions[actionName]["responseType"] : CB_Net.REST.responseType_DEFAULT, //responseType
666 avoidProxy, //avoidProxy
667 typeof(CB_Net.REST.actions[actionName]["forceJSON"]) !== "undefined" ? CB_Net.REST.actions[actionName]["forceJSON"] : CB_Net.REST.forceJSON_DEFAULT, //forceJSON
668 typeof(CB_Net.REST.actions[actionName]["getHeaders"]) !== "undefined" ? CB_Net.REST.actions[actionName]["getHeaders"] : CB_Net.REST.getHeaders_DEFAULT, //getHeaders
669 typeof(CB_Net.REST.actions[actionName]["getHeadersOneDimension"]) !== "undefined" ? CB_Net.REST.actions[actionName]["getHeadersOneDimension"] : CB_Net.REST.getHeadersOneDimension_DEFAULT, //headersForceOneDimension
670 typeof(CB_Net.REST.actions[actionName]["getHeadersOneDimensionValues"]) !== "undefined" ? CB_Net.REST.actions[actionName]["getHeadersOneDimensionValues"] : CB_Net.REST.getHeadersOneDimensionValues_DEFAULT, //headersForceOneDimensionValues
671 typeof(CB_Net.REST.actions[actionName]["transparentStatus"]) !== "undefined" ? CB_Net.REST.actions[actionName]["transparentStatus"] : CB_Net.REST.transparentStatus_DEFAULT, //transparentStatus
672 typeof(CB_Net.REST.actions[actionName]["transparentHeaders"]) !== "undefined" ? CB_Net.REST.actions[actionName]["transparentHeaders"] : CB_Net.REST.transparentHeaders_DEFAULT, //transparentHeaders
673 callbackOkWrapper, //callbackOk
674 callbackErrorWrapper, //callbackError
675 allowedSuccessStatuses, //allowedSuccessStatuses
676 XHR //XHR
677 );
678 }
679
680
681
682 /**
683 * Cancels a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (by its [AJAX]{@link https://en.wikipedia.org/wiki/Ajax_(programming)}/[XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} request associated) by executing the "abort" method of the given [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object (if available) and sets its "aborted" property to true if succeeds. When a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action is aborted, the callbackOk functions associated (if any) will not be called (unless they have been called already).
684 * @function
685 * @param {Object} XHR - The [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object that we want to abort.
686 * @returns {boolean} Returns true if the "abort" method of the given [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object could be called and the "aborted" property was set to true. Otherwise, returns false.
687 */
688 CB_Net.REST.actionAbort = function(XHR)
689 {
690 if (typeof(XHR) === "object" &amp;&amp; XHR !== null &amp;&amp; typeof(XHR.abort) === "function") { XHR.abort(); XHR.aborted = true; return true; }
691 return false;
692 }
693
694
695 /**
696 * Tries to revert the abortion of a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (by its [AJAX]{@link https://en.wikipedia.org/wiki/Ajax_(programming)}/[XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} request associated) by setting the "aborted" property of the given [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object to false. If this function is called before the "callbackOk" functions associated to the [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action (if any) are called, they could finally be called perhaps (depending on each case, could be different). Have in mind that, after calling {@link CB_Net.REST.actionAbort}, the "abort" method of the [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object was probably called already (if available).
697 * @function
698 * @param {Object} XHR - The [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object whose abortion we want to cancel.
699 * @returns {boolean} Returns true if the "aborted" property was set to false. Otherwise, returns false.
700 */
701 CB_Net.REST.actionAbortCancel = function(XHR)
702 {
703 if (typeof(XHR) === "object" &amp;&amp; XHR !== null) { XHR.aborted = false; return true; }
704 return false;
705 }
706
707
708 /**
709 * Returns whether a [REST]{@link https://en.wikipedia.org/wiki/Representational_state_transfer} action is aborted or not (by its [AJAX]{@link https://en.wikipedia.org/wiki/Ajax_(programming)}/[XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} request associated).
710 * @function
711 * @param {Object} XHR - The [XHR]{@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/XMLHttpRequest} object that we want to check.
712 * @returns {boolean} Returns true if the "aborted" property is set to true. Otherwise, returns false.
713 */
714 CB_Net.REST.actionIsAborted = function(XHR)
715 {
716 return (typeof(XHR) === "object" &amp;&amp; XHR !== null &amp;&amp; XHR.aborted === true);
717 }
718}</pre>
719 </article>
720</section>
721
722
723
724
725
726 </div>
727 </div>
728
729 <div class="clearfix"></div>
730
731
732
733</div>
734</div>
735
736
737 <div class="modal fade" id="searchResults">
738 <div class="modal-dialog">
739 <div class="modal-content">
740 <div class="modal-header">
741 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
742 <h4 class="modal-title">Search results</h4>
743 </div>
744 <div class="modal-body"></div>
745 <div class="modal-footer">
746 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
747 </div>
748 </div><!-- /.modal-content -->
749 </div><!-- /.modal-dialog -->
750 </div>
751
752
753<footer>
754
755
756 <span class="copyright">
757 <a href="printable/" target="_blank">See a more printer-friendly version</a><hr /><span style="color:#000000">© <address style="display:inline; font-style:normal;"><a href="https://crossbrowdy.com/" target="_blank">CrossBrowdy</a> API documentation</address> by <a href="https://joanalbamaldonado.com/" target="_blank">Joan Alba Maldonado</a> - <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International</a><br />DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.</span>
758 </span>
759
760<span class="jsdoc-message">
761 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
762
763 on Mon Feb 3rd 2020
764
765 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
766</span>
767</footer>
768
769<script src="scripts/docstrap.lib.js"></script>
770<script src="scripts/toc.js"></script>
771
772 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
773
774
775<script>
776$( function () {
777 $( "[id*='$']" ).each( function () {
778 var $this = $( this );
779
780 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
781 } );
782
783 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
784 var $this = $( this );
785
786 var example = $this.find( "code" );
787 exampleText = example.html();
788 var lang = /{@lang (.*?)}/.exec( exampleText );
789 if ( lang && lang[1] ) {
790 exampleText = exampleText.replace( lang[0], "" );
791 example.html( exampleText );
792 lang = lang[1];
793 } else {
794 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
795 lang = langClassMatch ? langClassMatch[1] : "javascript";
796 }
797
798 if ( lang ) {
799
800 $this
801 .addClass( "sunlight-highlight-" + lang )
802 .addClass( "linenums" )
803 .html( example.html() );
804
805 }
806 } );
807
808 Sunlight.highlightAll( {
809 lineNumbers : true,
810 showMenu : true,
811 enableDoclinks : true
812 } );
813
814 $.catchAnchorLinks( {
815 navbarOffset: 10
816 } );
817 $( "#toc" ).toc( {
818 anchorName : function ( i, heading, prefix ) {
819 return $( heading ).attr( "id" ) || ( prefix + i );
820 },
821 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
822 showAndHide : false,
823 smoothScrolling: true
824 } );
825
826 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
827 $( '.dropdown-toggle' ).dropdown();
828
829 $( "table" ).each( function () {
830 var $this = $( this );
831 $this.addClass('table');
832 } );
833
834} );
835</script>
836
837
838
839<!--Navigation and Symbol Display-->
840
841<script>
842 $( function () {
843 $( '#main' ).localScroll( {
844 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
845 } );
846 $( "dt.name" ).each( function () {
847 var $this = $( this ).find("h4");
848 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
849 var dt = $(this);
850 var children = dt.next( "dd" );
851
852 dt.prepend( icon ).css( {cursor : "pointer"} );
853 dt.addClass( "member-collapsed" ).addClass( "member" );
854
855
856 children.hide();
857
858 dt.children().on( "click", function () {
859 children = dt.next( "dd" );
860 children.slideToggle( "fast", function () {
861
862 if ( children.is( ":visible" ) ) {
863 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
864 dt.addClass( "member-open" ).animate( "member-collapsed" );
865 } else {
866 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
867 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
868 }
869 } );
870 } );
871
872 } );
873 } );
874</script>
875
876
877<!--Google Analytics-->
878
879
880
881 <script type="text/javascript">
882 $(document).ready(function() {
883 SearcherDisplay.init();
884 });
885 </script>
886
887
888</body>
889</html>