kablam 0.0.4 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/app/assets/javascripts/kablam/ajax.js +531 -0
- data/app/assets/javascripts/kablam/forms.js +167 -0
- data/app/assets/javascripts/kablam/messaging.js +95 -0
- data/app/assets/stylesheets/kablam.scss +25 -0
- data/app/channels/chat_channel.rb +12 -0
- data/app/controllers/concerns/api_settings.rb +41 -0
- data/app/controllers/data_controller.rb +133 -0
- data/app/views/data/create.js.erb +10 -0
- data/app/views/data/destroy.js.erb +12 -0
- data/app/views/data/form.html.erb +1 -0
- data/app/views/data/undo.js.erb +2 -0
- data/app/views/data/update.js.erb +9 -0
- data/app/views/kablam_forms/_form_generator.html.erb +1 -1
- data/app/views/kablam_forms/fields/_checkbox_array.html.erb +3 -3
- data/app/views/kablam_forms/fields/_checkbox_boolean.html.erb +3 -3
- data/app/views/kablam_forms/fields/_file_upload.html.erb +2 -2
- data/app/views/kablam_forms/fields/_input.html.erb +2 -2
- data/app/views/kablam_forms/fields/_multi_inputs.html.erb +2 -2
- data/app/views/kablam_forms/fields/_pretext.html.erb +1 -1
- data/app/views/kablam_forms/fields/_select.html.erb +3 -3
- data/app/views/kablam_forms/fields/_text.html.erb +3 -3
- data/kablam.gemspec +2 -1
- data/lib/generators/kablam/USAGE +5 -2
- data/lib/generators/kablam/install_generator.rb +37 -0
- data/lib/generators/kablam/messaging_generator.rb +40 -0
- data/lib/generators/kablam/templates/chat.rb +44 -0
- data/lib/generators/kablam/templates/kablam.rb +45 -0
- data/lib/generators/kablam/templates/message.rb +53 -0
- data/lib/kablam.rb +35 -0
- data/lib/kablam/forms.rb +26 -21
- data/lib/kablam/kablam_record.rb +61 -0
- metadata +32 -2
- data/lib/generators/kablam/kablam_generator.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd80585b73d2f561735a42f89a32e543e75ac639000af42a7816c07885b9ece2
|
4
|
+
data.tar.gz: 89ffc03edd6437375e6bbe16248a54b513957e1251fc3627cb4a9836b46616da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e2f1c89e5047ccf06b40ac4c95ee11fa61280139749f5662e728b870ca7dbce0e28c9660ebece8728d89edf0367794e386e1d17de6b181793ad31580690eea
|
7
|
+
data.tar.gz: 4c16ff0f5651077853d81109f20df9063981d0e29a79fc09362770fa5a8cf23a1488a87c8075131036b16939520b05436d70dbc0031723c310eaa9973ee735d6
|
data/.DS_Store
CHANGED
Binary file
|
@@ -0,0 +1,531 @@
|
|
1
|
+
// AJAX JS
|
2
|
+
function AjaxRequest() {
|
3
|
+
var req = new Object();
|
4
|
+
|
5
|
+
// -------------------
|
6
|
+
// Instance properties
|
7
|
+
// -------------------
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Timeout period (in ms) until an async request will be aborted, and
|
11
|
+
* the onTimeout function will be called
|
12
|
+
*/
|
13
|
+
req.timeout = null;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Since some browsers cache GET requests via XMLHttpRequest, an
|
17
|
+
* additional parameter called AjaxRequestUniqueId will be added to
|
18
|
+
* the request URI with a unique numeric value appended so that the requested
|
19
|
+
* URL will not be cached.
|
20
|
+
*/
|
21
|
+
req.generateUniqueUrl = true;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* The url that the request will be made to, which defaults to the current
|
25
|
+
* url of the window
|
26
|
+
*/
|
27
|
+
req.url = window.location.href;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* The method of the request, either GET (default), POST, or HEAD
|
31
|
+
*/
|
32
|
+
req.method = "GET";
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Whether or not the request will be asynchronous. In general, synchronous
|
36
|
+
* requests should not be used so this should rarely be changed from true
|
37
|
+
*/
|
38
|
+
req.async = true;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* The username used to access the URL
|
42
|
+
*/
|
43
|
+
req.username = null;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* The password used to access the URL
|
47
|
+
*/
|
48
|
+
req.password = null;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* The parameters is an object holding name/value pairs which will be
|
52
|
+
* added to the url for a GET request or the request content for a POST request
|
53
|
+
*/
|
54
|
+
req.parameters = new Object();
|
55
|
+
|
56
|
+
/**
|
57
|
+
* The sequential index number of this request, updated internally
|
58
|
+
*/
|
59
|
+
req.requestIndex = AjaxRequest.numAjaxRequests++;
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Indicates whether a response has been received yet from the server
|
63
|
+
*/
|
64
|
+
req.responseReceived = false;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* The name of the group that this request belongs to, for activity
|
68
|
+
* monitoring purposes
|
69
|
+
*/
|
70
|
+
req.groupName = null;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* The query string to be added to the end of a GET request, in proper
|
74
|
+
* URIEncoded format
|
75
|
+
*/
|
76
|
+
req.queryString = "";
|
77
|
+
|
78
|
+
/**
|
79
|
+
* After a response has been received, this will hold the text contents of
|
80
|
+
* the response - even in case of error
|
81
|
+
*/
|
82
|
+
req.responseText = null;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* After a response has been received, this will hold the XML content
|
86
|
+
*/
|
87
|
+
req.responseXML = null;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* After a response has been received, this will hold the status code of
|
91
|
+
* the response as returned by the server.
|
92
|
+
*/
|
93
|
+
req.status = null;
|
94
|
+
|
95
|
+
/**
|
96
|
+
* After a response has been received, this will hold the text description
|
97
|
+
* of the response code
|
98
|
+
*/
|
99
|
+
req.statusText = null;
|
100
|
+
|
101
|
+
/**
|
102
|
+
* An internal flag to indicate whether the request has been aborted
|
103
|
+
*/
|
104
|
+
req.aborted = false;
|
105
|
+
|
106
|
+
/**
|
107
|
+
* The XMLHttpRequest object used internally
|
108
|
+
*/
|
109
|
+
req.xmlHttpRequest = null;
|
110
|
+
|
111
|
+
// --------------
|
112
|
+
// Event handlers
|
113
|
+
// --------------
|
114
|
+
|
115
|
+
/**
|
116
|
+
* If a timeout period is set, and it is reached before a response is
|
117
|
+
* received, a function reference assigned to onTimeout will be called
|
118
|
+
*/
|
119
|
+
req.onTimeout = null;
|
120
|
+
|
121
|
+
/**
|
122
|
+
* A function reference assigned will be called when readyState=1
|
123
|
+
*/
|
124
|
+
req.onLoading = null;
|
125
|
+
|
126
|
+
/**
|
127
|
+
* A function reference assigned will be called when readyState=2
|
128
|
+
*/
|
129
|
+
req.onLoaded = null;
|
130
|
+
|
131
|
+
/**
|
132
|
+
* A function reference assigned will be called when readyState=3
|
133
|
+
*/
|
134
|
+
req.onInteractive = null;
|
135
|
+
|
136
|
+
/**
|
137
|
+
* A function reference assigned will be called when readyState=4
|
138
|
+
*/
|
139
|
+
req.onComplete = null;
|
140
|
+
|
141
|
+
/**
|
142
|
+
* A function reference assigned will be called after onComplete, if
|
143
|
+
* the statusCode=200
|
144
|
+
*/
|
145
|
+
req.onSuccess = null;
|
146
|
+
|
147
|
+
/**
|
148
|
+
* A function reference assigned will be called after onComplete, if
|
149
|
+
* the statusCode != 200
|
150
|
+
*/
|
151
|
+
req.onError = null;
|
152
|
+
|
153
|
+
/**
|
154
|
+
* If this request has a group name, this function reference will be called
|
155
|
+
* and passed the group name if this is the first request in the group to
|
156
|
+
* become active
|
157
|
+
*/
|
158
|
+
req.onGroupBegin = null;
|
159
|
+
|
160
|
+
/**
|
161
|
+
* If this request has a group name, and this request is the last request
|
162
|
+
* in the group to complete, this function reference will be called
|
163
|
+
*/
|
164
|
+
req.onGroupEnd = null;
|
165
|
+
|
166
|
+
// Get the XMLHttpRequest object itself
|
167
|
+
req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();
|
168
|
+
if (req.xmlHttpRequest==null) { return null; }
|
169
|
+
|
170
|
+
// -------------------------------------------------------
|
171
|
+
// Attach the event handlers for the XMLHttpRequest object
|
172
|
+
// -------------------------------------------------------
|
173
|
+
req.xmlHttpRequest.onreadystatechange =
|
174
|
+
function() {
|
175
|
+
if (req==null || req.xmlHttpRequest==null) { return; }
|
176
|
+
if (req.xmlHttpRequest.readyState==1) { req.onLoadingInternal(req); }
|
177
|
+
if (req.xmlHttpRequest.readyState==2) { req.onLoadedInternal(req); }
|
178
|
+
if (req.xmlHttpRequest.readyState==3) { req.onInteractiveInternal(req); }
|
179
|
+
if (req.xmlHttpRequest.readyState==4) { req.onCompleteInternal(req); }
|
180
|
+
};
|
181
|
+
|
182
|
+
// ---------------------------------------------------------------------------
|
183
|
+
// Internal event handlers that fire, and in turn fire the user event handlers
|
184
|
+
// ---------------------------------------------------------------------------
|
185
|
+
// Flags to keep track if each event has been handled, in case of
|
186
|
+
// multiple calls (some browsers may call the onreadystatechange
|
187
|
+
// multiple times for the same state)
|
188
|
+
req.onLoadingInternalHandled = false;
|
189
|
+
req.onLoadedInternalHandled = false;
|
190
|
+
req.onInteractiveInternalHandled = false;
|
191
|
+
req.onCompleteInternalHandled = false;
|
192
|
+
req.onLoadingInternal =
|
193
|
+
function() {
|
194
|
+
if (req.onLoadingInternalHandled) { return; }
|
195
|
+
AjaxRequest.numActiveAjaxRequests++;
|
196
|
+
if (AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function") {
|
197
|
+
AjaxRequestBegin();
|
198
|
+
}
|
199
|
+
if (req.groupName!=null) {
|
200
|
+
if (typeof(AjaxRequest.numActiveAjaxGroupRequests[req.groupName])=="undefined") {
|
201
|
+
AjaxRequest.numActiveAjaxGroupRequests[req.groupName] = 0;
|
202
|
+
}
|
203
|
+
AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
|
204
|
+
if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function") {
|
205
|
+
req.onGroupBegin(req.groupName);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
if (typeof(req.onLoading)=="function") {
|
209
|
+
req.onLoading(req);
|
210
|
+
}
|
211
|
+
req.onLoadingInternalHandled = true;
|
212
|
+
};
|
213
|
+
req.onLoadedInternal =
|
214
|
+
function() {
|
215
|
+
if (req.onLoadedInternalHandled) { return; }
|
216
|
+
if (typeof(req.onLoaded)=="function") {
|
217
|
+
req.onLoaded(req);
|
218
|
+
}
|
219
|
+
req.onLoadedInternalHandled = true;
|
220
|
+
};
|
221
|
+
req.onInteractiveInternal =
|
222
|
+
function() {
|
223
|
+
if (req.onInteractiveInternalHandled) { return; }
|
224
|
+
if (typeof(req.onInteractive)=="function") {
|
225
|
+
req.onInteractive(req);
|
226
|
+
}
|
227
|
+
req.onInteractiveInternalHandled = true;
|
228
|
+
};
|
229
|
+
req.onCompleteInternal =
|
230
|
+
function() {
|
231
|
+
if (req.onCompleteInternalHandled || req.aborted) { return; }
|
232
|
+
req.onCompleteInternalHandled = true;
|
233
|
+
AjaxRequest.numActiveAjaxRequests--;
|
234
|
+
if (AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function") {
|
235
|
+
AjaxRequestEnd(req.groupName);
|
236
|
+
}
|
237
|
+
if (req.groupName!=null) {
|
238
|
+
AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
|
239
|
+
if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function") {
|
240
|
+
req.onGroupEnd(req.groupName);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
req.responseReceived = true;
|
244
|
+
req.status = req.xmlHttpRequest.status;
|
245
|
+
req.statusText = req.xmlHttpRequest.statusText;
|
246
|
+
req.responseText = req.xmlHttpRequest.responseText;
|
247
|
+
req.responseXML = req.xmlHttpRequest.responseXML;
|
248
|
+
if (typeof(req.onComplete)=="function") {
|
249
|
+
req.onComplete(req);
|
250
|
+
}
|
251
|
+
if (req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function") {
|
252
|
+
req.onSuccess(req);
|
253
|
+
}
|
254
|
+
else if (typeof(req.onError)=="function") {
|
255
|
+
req.onError(req);
|
256
|
+
}
|
257
|
+
|
258
|
+
// Clean up so IE doesn't leak memory
|
259
|
+
delete req.xmlHttpRequest['onreadystatechange'];
|
260
|
+
req.xmlHttpRequest = null;
|
261
|
+
};
|
262
|
+
req.onTimeoutInternal =
|
263
|
+
function() {
|
264
|
+
if (req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled) {
|
265
|
+
req.aborted = true;
|
266
|
+
req.xmlHttpRequest.abort();
|
267
|
+
AjaxRequest.numActiveAjaxRequests--;
|
268
|
+
if (AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function") {
|
269
|
+
AjaxRequestEnd(req.groupName);
|
270
|
+
}
|
271
|
+
if (req.groupName!=null) {
|
272
|
+
AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
|
273
|
+
if (AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function") {
|
274
|
+
req.onGroupEnd(req.groupName);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
if (typeof(req.onTimeout)=="function") {
|
278
|
+
req.onTimeout(req);
|
279
|
+
}
|
280
|
+
// Opera won't fire onreadystatechange after abort, but other browsers do.
|
281
|
+
// So we can't rely on the onreadystate function getting called. Clean up here!
|
282
|
+
delete req.xmlHttpRequest['onreadystatechange'];
|
283
|
+
req.xmlHttpRequest = null;
|
284
|
+
}
|
285
|
+
};
|
286
|
+
|
287
|
+
// ----------------
|
288
|
+
// Instance methods
|
289
|
+
// ----------------
|
290
|
+
/**
|
291
|
+
* The process method is called to actually make the request. It builds the
|
292
|
+
* querystring for GET requests (the content for POST requests), sets the
|
293
|
+
* appropriate headers if necessary, and calls the
|
294
|
+
* XMLHttpRequest.send() method
|
295
|
+
*/
|
296
|
+
req.process =
|
297
|
+
function() {
|
298
|
+
if (req.xmlHttpRequest!=null) {
|
299
|
+
// Some logic to get the real request URL
|
300
|
+
if (req.generateUniqueUrl && req.method=="GET") {
|
301
|
+
req.parameters["AjaxRequestUniqueId"] = new Date().getTime() + "" + req.requestIndex;
|
302
|
+
}
|
303
|
+
var content = null; // For POST requests, to hold query string
|
304
|
+
for (var i in req.parameters) {
|
305
|
+
if (req.queryString.length>0) { req.queryString += "&"; }
|
306
|
+
req.queryString += encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);
|
307
|
+
}
|
308
|
+
if (req.method=="GET") {
|
309
|
+
if (req.queryString.length>0) {
|
310
|
+
req.url += ((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
req.xmlHttpRequest.open(req.method,req.url,req.async,req.username,req.password);
|
314
|
+
if (req.method=="POST") {
|
315
|
+
if (typeof(req.xmlHttpRequest.setRequestHeader)!="undefined") {
|
316
|
+
req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
317
|
+
}
|
318
|
+
content = req.queryString;
|
319
|
+
}
|
320
|
+
if (req.timeout>0) {
|
321
|
+
setTimeout(req.onTimeoutInternal,req.timeout);
|
322
|
+
}
|
323
|
+
req.xmlHttpRequest.send(content);
|
324
|
+
}
|
325
|
+
};
|
326
|
+
|
327
|
+
/**
|
328
|
+
* An internal function to handle an Object argument, which may contain
|
329
|
+
* either AjaxRequest field values or parameter name/values
|
330
|
+
*/
|
331
|
+
req.handleArguments =
|
332
|
+
function(args) {
|
333
|
+
for (var i in args) {
|
334
|
+
// If the AjaxRequest object doesn't have a property which was passed, treat it as a url parameter
|
335
|
+
if (typeof(req[i])=="undefined") {
|
336
|
+
req.parameters[i] = args[i];
|
337
|
+
}
|
338
|
+
else {
|
339
|
+
req[i] = args[i];
|
340
|
+
}
|
341
|
+
}
|
342
|
+
};
|
343
|
+
|
344
|
+
/**
|
345
|
+
* Returns the results of XMLHttpRequest.getAllResponseHeaders().
|
346
|
+
* Only available after a response has been returned
|
347
|
+
*/
|
348
|
+
req.getAllResponseHeaders =
|
349
|
+
function() {
|
350
|
+
if (req.xmlHttpRequest!=null) {
|
351
|
+
if (req.responseReceived) {
|
352
|
+
return req.xmlHttpRequest.getAllResponseHeaders();
|
353
|
+
}
|
354
|
+
alert("Cannot getAllResponseHeaders because a response has not yet been received");
|
355
|
+
}
|
356
|
+
};
|
357
|
+
|
358
|
+
/**
|
359
|
+
* Returns the the value of a response header as returned by
|
360
|
+
* XMLHttpRequest,getResponseHeader().
|
361
|
+
* Only available after a response has been returned
|
362
|
+
*/
|
363
|
+
req.getResponseHeader =
|
364
|
+
function(headerName) {
|
365
|
+
if (req.xmlHttpRequest!=null) {
|
366
|
+
if (req.responseReceived) {
|
367
|
+
return req.xmlHttpRequest.getResponseHeader(headerName);
|
368
|
+
}
|
369
|
+
alert("Cannot getResponseHeader because a response has not yet been received");
|
370
|
+
}
|
371
|
+
};
|
372
|
+
|
373
|
+
return req;
|
374
|
+
}
|
375
|
+
|
376
|
+
// ---------------------------------------
|
377
|
+
// Static methods of the AjaxRequest class
|
378
|
+
// ---------------------------------------
|
379
|
+
|
380
|
+
/**
|
381
|
+
* Returns an XMLHttpRequest object, either as a core object or an ActiveX
|
382
|
+
* implementation. If an object cannot be instantiated, it will return null;
|
383
|
+
*/
|
384
|
+
AjaxRequest.getXmlHttpRequest = function() {
|
385
|
+
if (window.XMLHttpRequest) {
|
386
|
+
return new XMLHttpRequest();
|
387
|
+
}
|
388
|
+
else if (window.ActiveXObject) {
|
389
|
+
// Based on http://jibbering.com/2002/4/httprequest.html
|
390
|
+
/*@cc_on @*/
|
391
|
+
/*@if (@_jscript_version >= 5)
|
392
|
+
try {
|
393
|
+
return new ActiveXObject("Msxml2.XMLHTTP");
|
394
|
+
} catch (e) {
|
395
|
+
try {
|
396
|
+
return new ActiveXObject("Microsoft.XMLHTTP");
|
397
|
+
} catch (E) {
|
398
|
+
return null;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
@end @*/
|
402
|
+
}
|
403
|
+
else {
|
404
|
+
return null;
|
405
|
+
}
|
406
|
+
};
|
407
|
+
|
408
|
+
/**
|
409
|
+
* See if any request is active in the background
|
410
|
+
*/
|
411
|
+
AjaxRequest.isActive = function() {
|
412
|
+
return (AjaxRequest.numActiveAjaxRequests>0);
|
413
|
+
};
|
414
|
+
|
415
|
+
/**
|
416
|
+
* Make a GET request. Pass an object containing parameters and arguments as
|
417
|
+
* the second argument.
|
418
|
+
* These areguments may be either AjaxRequest properties to set on the request
|
419
|
+
* object or name/values to set in the request querystring.
|
420
|
+
*/
|
421
|
+
AjaxRequest.get = function(args) {
|
422
|
+
AjaxRequest.doRequest("GET",args);
|
423
|
+
};
|
424
|
+
|
425
|
+
/**
|
426
|
+
* Make a POST request. Pass an object containing parameters and arguments as
|
427
|
+
* the second argument.
|
428
|
+
* These areguments may be either AjaxRequest properties to set on the request
|
429
|
+
* object or name/values to set in the request querystring.
|
430
|
+
*/
|
431
|
+
AjaxRequest.post = function(args) {
|
432
|
+
AjaxRequest.doRequest("POST",args);
|
433
|
+
};
|
434
|
+
|
435
|
+
/**
|
436
|
+
* The internal method used by the .get() and .post() methods
|
437
|
+
*/
|
438
|
+
AjaxRequest.doRequest = function(method,args) {
|
439
|
+
if (typeof(args)!="undefined" && args!=null) {
|
440
|
+
var myRequest = new AjaxRequest();
|
441
|
+
myRequest.method = method;
|
442
|
+
myRequest.handleArguments(args);
|
443
|
+
myRequest.process();
|
444
|
+
}
|
445
|
+
} ;
|
446
|
+
|
447
|
+
/**
|
448
|
+
* Submit a form. The requested URL will be the form's ACTION, and the request
|
449
|
+
* method will be the form's METHOD.
|
450
|
+
* Returns true if the submittal was handled successfully, else false so it
|
451
|
+
* can easily be used with an onSubmit event for a form, and fallback to
|
452
|
+
* submitting the form normally.
|
453
|
+
*/
|
454
|
+
AjaxRequest.submit = function(theform, args) {
|
455
|
+
var myRequest = new AjaxRequest();
|
456
|
+
if (myRequest==null) { return false; }
|
457
|
+
var serializedForm = AjaxRequest.serializeForm(theform);
|
458
|
+
myRequest.method = theform.method.toUpperCase();
|
459
|
+
myRequest.url = theform.action;
|
460
|
+
myRequest.handleArguments(args);
|
461
|
+
myRequest.queryString = serializedForm;
|
462
|
+
myRequest.process();
|
463
|
+
return true;
|
464
|
+
};
|
465
|
+
|
466
|
+
/**
|
467
|
+
* Serialize a form into a format which can be sent as a GET string or a POST
|
468
|
+
* content.It correctly ignores disabled fields, maintains order of the fields
|
469
|
+
* as in the elements[] array. The 'file' input type is not supported, as
|
470
|
+
* its content is not available to javascript. This method is used internally
|
471
|
+
* by the submit class method.
|
472
|
+
*/
|
473
|
+
AjaxRequest.serializeForm = function(theform) {
|
474
|
+
var els = theform.elements;
|
475
|
+
var len = els.length;
|
476
|
+
var queryString = "";
|
477
|
+
this.addField =
|
478
|
+
function(name,value) {
|
479
|
+
if (queryString.length>0) {
|
480
|
+
queryString += "&";
|
481
|
+
}
|
482
|
+
queryString += encodeURIComponent(name) + "=" + encodeURIComponent(value);
|
483
|
+
};
|
484
|
+
for (var i=0; i<len; i++) {
|
485
|
+
var el = els[i];
|
486
|
+
if (!el.disabled) {
|
487
|
+
switch(el.type) {
|
488
|
+
case 'text': case 'password': case 'hidden': case 'textarea':
|
489
|
+
this.addField(el.name,el.value);
|
490
|
+
break;
|
491
|
+
case 'select-one':
|
492
|
+
if (el.selectedIndex>=0) {
|
493
|
+
this.addField(el.name,el.options[el.selectedIndex].value);
|
494
|
+
}
|
495
|
+
break;
|
496
|
+
case 'select-multiple':
|
497
|
+
for (var j=0; j<el.options.length; j++) {
|
498
|
+
if (el.options[j].selected) {
|
499
|
+
this.addField(el.name,el.options[j].value);
|
500
|
+
}
|
501
|
+
}
|
502
|
+
break;
|
503
|
+
case 'checkbox': case 'radio':
|
504
|
+
if (el.checked) {
|
505
|
+
this.addField(el.name,el.value);
|
506
|
+
}
|
507
|
+
break;
|
508
|
+
}
|
509
|
+
}
|
510
|
+
}
|
511
|
+
return queryString;
|
512
|
+
};
|
513
|
+
|
514
|
+
// -----------------------
|
515
|
+
// Static Class variables
|
516
|
+
// -----------------------
|
517
|
+
|
518
|
+
/**
|
519
|
+
* The number of total AjaxRequest objects currently active and running
|
520
|
+
*/
|
521
|
+
AjaxRequest.numActiveAjaxRequests = 0;
|
522
|
+
|
523
|
+
/**
|
524
|
+
* An object holding the number of active requests for each group
|
525
|
+
*/
|
526
|
+
AjaxRequest.numActiveAjaxGroupRequests = new Object();
|
527
|
+
|
528
|
+
/**
|
529
|
+
* The total number of AjaxRequest objects instantiated
|
530
|
+
*/
|
531
|
+
AjaxRequest.numAjaxRequests = 0;
|