[javascript] move Deferred implementation to cubicweb.ajax.js
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 09 Jun 2010 12:39:55 +0200
changeset 5698 5c8fa1650299
parent 5697 ec1ce7198ef4
child 5699 f4f6ee3af50b
[javascript] move Deferred implementation to cubicweb.ajax.js
web/data/cubicweb.ajax.js
web/data/cubicweb.compat.js
--- a/web/data/cubicweb.ajax.js	Wed Jun 09 12:32:54 2010 +0200
+++ b/web/data/cubicweb.ajax.js	Wed Jun 09 12:39:55 2010 +0200
@@ -17,8 +17,76 @@
  * with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-CubicWeb.require('python.js');
-CubicWeb.require('htmlhelpers.js');
+/**
+ * .. function:: Deferred
+ *
+ * dummy ultra minimalist implementation on deferred for jQuery
+ */
+function Deferred() {
+    this.__init__(this);
+}
+
+jQuery.extend(Deferred.prototype, {
+    __init__: function() {
+        this._onSuccess = [];
+        this._onFailure = [];
+        this._req = null;
+        this._result = null;
+        this._error = null;
+    },
+
+    addCallback: function(callback) {
+        if (this._req.readyState == 4) {
+            if (this._result) {
+                var args = [this._result, this._req];
+                jQuery.merge(args, cw.utils.sliceList(arguments, 1));
+                callback.apply(null, args);
+            }
+        }
+        else {
+            this._onSuccess.push([callback, cw.utils.sliceList(arguments, 1)]);
+        }
+        return this;
+    },
+
+    addErrback: function(callback) {
+        if (this._req.readyState == 4) {
+            if (this._error) {
+                callback.apply(null, [this._error, this._req]);
+            }
+        }
+        else {
+            this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]);
+        }
+        return this;
+    },
+
+    success: function(result) {
+        this._result = result;
+        try {
+            for (var i = 0; i < this._onSuccess.length; i++) {
+                var callback = this._onSuccess[i][0];
+                var args = [result, this._req];
+                jQuery.merge(args, this._onSuccess[i][1]);
+                callback.apply(null, args);
+            }
+        } catch(error) {
+            this.error(this.xhr, null, error);
+        }
+    },
+
+    error: function(xhr, status, error) {
+        this._error = error;
+        for (var i = 0; i < this._onFailure.length; i++) {
+            var callback = this._onFailure[i][0];
+            var args = [error, this._req];
+            jQuery.merge(args, this._onFailure[i][1]);
+            callback.apply(null, args);
+        }
+    }
+
+});
+
 
 var JSON_BASE_URL = baseuri() + 'json?';
 
--- a/web/data/cubicweb.compat.js	Wed Jun 09 12:32:54 2010 +0200
+++ b/web/data/cubicweb.compat.js	Wed Jun 09 12:39:55 2010 +0200
@@ -104,76 +104,6 @@
 );
 
 /**
- * .. function:: Deferred
- *
- * dummy ultra minimalist implementation on deferred for jQuery
- */
-function Deferred() {
-    this.__init__(this);
-}
-
-jQuery.extend(Deferred.prototype, {
-    __init__: function() {
-        this._onSuccess = [];
-        this._onFailure = [];
-        this._req = null;
-        this._result = null;
-        this._error = null;
-    },
-
-    addCallback: function(callback) {
-        if (this._req.readyState == 4) {
-            if (this._result) {
-                var args = [this._result, this._req];
-                jQuery.merge(args, cw.utils.sliceList(arguments, 1));
-                callback.apply(null, args);
-            }
-        }
-        else {
-            this._onSuccess.push([callback, cw.utils.sliceList(arguments, 1)]);
-        }
-        return this;
-    },
-
-    addErrback: function(callback) {
-        if (this._req.readyState == 4) {
-            if (this._error) {
-                callback.apply(null, [this._error, this._req]);
-            }
-        }
-        else {
-            this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]);
-        }
-        return this;
-    },
-
-    success: function(result) {
-        this._result = result;
-        try {
-            for (var i = 0; i < this._onSuccess.length; i++) {
-                var callback = this._onSuccess[i][0];
-                var args = [result, this._req];
-                jQuery.merge(args, this._onSuccess[i][1]);
-                callback.apply(null, args);
-            }
-        } catch(error) {
-            this.error(this.xhr, null, error);
-        }
-    },
-
-    error: function(xhr, status, error) {
-        this._error = error;
-        for (var i = 0; i < this._onFailure.length; i++) {
-            var callback = this._onFailure[i][0];
-            var args = [error, this._req];
-            jQuery.merge(args, this._onFailure[i][1]);
-            callback.apply(null, args);
-        }
-    }
-
-});
-
-/**
  * The only known usage of KEYS is in the tag cube. Once cubicweb-tag 1.7.0 is out,
  * this current definition can be removed.
  */