Permalink
Browse files

Fixed IO methods with the addition of promises

Fixed old use of node[0] in DataSource and new shape for $.ajax configuration object
  • Loading branch information...
1 parent efaa316 commit 51cbd745d5f612f4fcefb2203f816560591e7e0b @juandopazo committed Mar 22, 2012
Showing with 34 additions and 20 deletions.
  1. +12 −1 src/datasource/js/DataSource.js
  2. +8 −5 src/datasource/js/DataSourceAjax.js
  3. +4 −5 src/io/js/Request.js
  4. +10 −9 src/io/js/ajax.js
@@ -162,6 +162,11 @@ var DataSource = Base.create('datasource', $.Utility, [], {
});
});
} else {
+ /**
+ * Error while parsing data
+ * @event parserError
+ * @param {message} Error message
+ */
this.fire("parserError", { message: "Result list not found" });
}
}
@@ -185,7 +190,7 @@ var DataSource = Base.create('datasource', $.Utility, [], {
resultNode.children().each(function (node) {
var record = {};
A.each(responseSchema.fields, function (field) {
- var value = node.nodeName != field.node ? $(node).find(field.node)[0] : node;
+ var value = node.nodeName != field.node ? $(node).find(field.node).getDOMNode() : node;
var tmp;
if (value) {
if (field.attr) {
@@ -238,6 +243,12 @@ var DataSource = Base.create('datasource', $.Utility, [], {
tempData = self._parser(self.get(TEMP_DATA));
}
self.set('recordSet', tempData);
+ /**
+ * Fired when new data is available
+ * @event update
+ * @param {Object} data New data
+ * @param {Object} data request
+ */
self.fire('update', { data: tempData, request: request });
/*Hash.each(tempData, function (key, val) {
if (!recordSet[key]) {
@@ -20,12 +20,15 @@ DataSource.Ajax = Base.create('datasource-ajax', DataSource, [], {
}
}, {
handleRequest: function (request, success, failure) {
- $.ajax({
- url: this.get(URL),
+ var url = this.get(URL),
+ type = this.get(RESPONSE_TYPE);
+ $.ajax(url, {
data: request,
- dataType: this.get(RESPONSE_TYPE),
- success: success,
- error: failure
+ dataType: type,
+ on: {
+ success: success,
+ failure: failure
+ }
});
}
});
View
@@ -69,11 +69,10 @@ var TRANSACTION_METHODS = {
$Object.each(TRANSACTION_METHODS, Request.addMethod);
-$Object.each(TRANSACTION_METHODS, function (method) {
-
- $[method] = function () {
+$Object.each(TRANSACTION_METHODS, function (name, fn) {
+ $[name] = function () {
var request = new $.Request();
- return request[method].apply(request, arguments);
+ fn.apply(request, arguments);
+ return request;
};
-
});
View
@@ -136,28 +136,29 @@ var getResultByContentType = function (xhr, dataType, onError) {
* @param {Object} settings
*/
function ajax(url, settings) {
+ var self = this;
var xhr = getAjaxObject();
- var success = settings.success,
-
- result = null;
+ var result = null;
var dataType = settings.dataType;
var timeout = settings.timeout || 10000; /* Tiempo que tarda en cancelarse la transaccion */
var method = settings.method || "GET"; /* Metodo para enviar informacion al servidor */
var async = settings.async || true;
- var complete = settings.complete || function () {};
+ var on = settings.on || {};
+ var complete = on.complete || function () {};
+ var success = on.success;
var onSuccess = function () {
if (success) {
- success.apply($, arguments);
+ success.apply(self, arguments);
}
- complete.apply($, arguments);
+ complete.apply(self, arguments);
};
var onError = function (a, b, c) {
- if (settings.failure) {
- settings.failure(a, b, c);
+ if (on.failure) {
+ on.failure(a, b, c);
}
- complete.apply($, arguments);
+ complete.apply(self, arguments);
};
if (xhr) {

0 comments on commit 51cbd74

Please sign in to comment.