Created
June 7, 2013 13:05
-
-
Save dostanko/5729104 to your computer and use it in GitHub Desktop.
This code allows to intercept ajax requests in Sencha application. It's good base to emulate all the backend for JavaScript client, make it dynamic, add intellect to it, response with delay, and do not touch application code at all.
Just include this and relative code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.require(["Ext.data.JsonP", "Ext.Ajax", "Ext.util.DelayedTask", "Localresponse.response"], function(){ | |
Ext.merge(Ext.Ajax , { | |
request: function(params){ | |
var serviceId = params.url.match( /\/([^\/\?]+)?\?/ ).pop().split("-").join("_");; | |
if (undefined !== Localresponse.responses[serviceId]) { | |
var delay = 500; | |
if (undefined !== Localresponse.responses[serviceId + "_delay"]) { | |
delay = Localresponse.responses[serviceId + "_delay"].call(); | |
}; | |
var delayedCallback = Ext.create('Ext.util.DelayedTask', function() { | |
var response = Localresponse.responses[serviceId].apply(this,[params]); | |
Ext.callback(params.callback, params.scope || window, [response, true, {responseText: Ext.encode(response)}]); | |
}); | |
delayedCallback.delay(delay); | |
} else { | |
alert("can't process ajax responce " + serviceId); | |
}; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in app.js