summaryrefslogtreecommitdiffstats
path: root/funcweb
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-06-18 13:57:23 +0300
committermakkalot <makkalot@gmail.com>2008-06-18 13:57:23 +0300
commiteaf715c340bf9a3cd032e607e21905426380b45f (patch)
tree672a0d0da56270f9d1fe7ef11bf7962445e2b52c /funcweb
parentf58d369ffd61587c8af3c65d30812e4209bfe3df (diff)
downloadthird_party-func-eaf715c340bf9a3cd032e607e21905426380b45f.tar.gz
third_party-func-eaf715c340bf9a3cd032e607e21905426380b45f.tar.xz
third_party-func-eaf715c340bf9a3cd032e607e21905426380b45f.zip
adding resources for remote form that file fixes the ajaxian problem we had
Diffstat (limited to 'funcweb')
-rw-r--r--funcweb/funcweb/static/javascript/ajax.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/funcweb/funcweb/static/javascript/ajax.js b/funcweb/funcweb/static/javascript/ajax.js
new file mode 100644
index 0000000..7df4749
--- /dev/null
+++ b/funcweb/funcweb/static/javascript/ajax.js
@@ -0,0 +1,83 @@
+function remoteFormRequest(form, target, options) {
+ var query = Array();
+ var contents = formContents(form);
+ for (var j=0; j<contents[0].length; j++)
+ query[contents[0][j]] = contents[1][j];
+ query["tg_random"] = new Date().getTime();
+ //makePOSTRequest(form.action, target, queryString(query));
+ remoteRequest(form, form.action, target, query, options);
+ return true;
+}
+
+function remoteRequest(source, target_url, target_dom, data, options) {
+ //before
+ if (options['before']) {
+ eval(options['before']);
+ }
+ if ((!options['confirm']) || confirm(options['confirm'])) {
+ makePOSTRequest(source, target_url, getElement(target_dom), queryString(data), options);
+ //after
+ if (options['after']) {
+ eval(options['after']);
+ }
+ }
+ return true;
+}
+
+function makePOSTRequest(source, url, target, parameters, options) {
+ var http_request = false;
+ if (window.XMLHttpRequest) { // Mozilla, Safari,...
+ http_request = new XMLHttpRequest();
+ if (http_request.overrideMimeType) {
+ http_request.overrideMimeType('text/xml');
+ }
+ } else if (window.ActiveXObject) { // IE
+ try {
+ http_request = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ http_request = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {}
+ }
+ }
+ if (!http_request) {
+ alert('Cannot create XMLHTTP instance');
+ return false;
+ }
+
+ var insertContents = function () {
+ if (http_request.readyState == 4) {
+ // loaded
+ if (options['loaded']) {
+ eval(options['loaded']);
+ }
+ if (http_request.status == 200) {
+ if(target) {
+ target.innerHTML = http_request.responseText;
+ }
+ //success
+ if (options['on_success']) {
+ eval(options['on_success']);
+ }
+ } else {
+ //failure
+ if (options['on_failure']) {
+ eval(options['on_failure']);
+ } else {
+ alert('There was a problem with the request. Status('+http_request.status+')');
+ }
+ }
+ //complete
+ if (options['on_complete']) {
+ eval(options['on_complete']);
+ }
+ }
+ }
+
+ http_request.onreadystatechange = insertContents;
+ http_request.open('POST', url, true);
+ http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http_request.setRequestHeader("Content-length", parameters.length);
+ http_request.setRequestHeader("Connection", "close");
+ http_request.send(parameters);
+}