]> dev.renevier.net Git - syj.git/blobdiff - public/js/ajaxize.js
assemble all utils scripts in a utils.js file
[syj.git] / public / js / ajaxize.js
diff --git a/public/js/ajaxize.js b/public/js/ajaxize.js
deleted file mode 100644 (file)
index 6680110..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
-    and is published under the AGPL license. */
-
-// wrapper around Form.request that sets up the submit listener, stops the
-// submit event, calls presubmit function, calls Form.request and calls a
-// postsubmit function
-Element.addMethods('form', {ajaxize : function(form, options) {
-    var reqoptions, timeout;
-
-    options = Object.clone(options);
-    reqoptions = Object.clone(options);
-    timeout = null;
-
-    function onSuccess(transport, json) {
-        if (timeout) {
-            window.clearTimeout(timeout);
-            timeout = null;
-        }
-        if (transport.getStatus() === 0) {
-            options.onFailure(transport, json);
-        } else {
-            options.onSuccess(transport, json);
-        }
-    }
-
-    function onFailure(transport, json) {
-        if (timeout) {
-            window.clearTimeout(timeout);
-            timeout = null;
-        }
-        options.onFailure(transport, json);
-    }
-
-    delete(reqoptions.presubmit);
-    delete(reqoptions.postsubmit);
-
-    $(form).observe('submit', function(evt) {
-        var req;
-
-        evt.stop(); // cancel form submission
-        if (Object.isFunction(options.presubmit)) {
-            if (options.presubmit(this) === false) {
-                return;
-            }
-        }
-        req = this.request(Object.extend(reqoptions, {
-            onSuccess: onSuccess,
-            onFailure: onFailure
-        }));
-        timeout = (function() {
-            options.onFailure(null);
-            req.abort();
-        }).delay(options.timeout || 20);
-        if (Object.isFunction(options.postsubmit)) {
-            options.postsubmit(this);
-        }
-    });
-}});