Hybrid View
-
19 Oct 2011 3:54 AM #1
Answered: Ext.application and Ext.override in launch function does not work?
Answered: Ext.application and Ext.override in launch function does not work?
I'm moving towards the ExtJS 4.0 MVC architecture and I had an override in my old init method which worked:
Old code that worked:
New code that doesn'tCode:APP.app = function() { ... return { init: function() { Ext.QuickTips.init(); Ext.override(Ext.Ajax.request, { extraParams: { param_1: Ext.get('my_id').getValue(), param_2: Ext.get('my_id_2').getValue(), param_3: Ext.get('my_id_3').getValue() } }); } } } Ext.onReady(APP.app.init, APP.app);
As you can see, I've moved this override to the launch function. You will also realize that I am retrieving my values from elements in the page after it has been loaded which is the reason for applying the override in the launch function.Code:Ext.application({ name: 'APP', autoCreateViewport: true, launch: function() { Ext.override(Ext.Ajax.request, { extraParams: { param_1: Ext.get('my_id').getValue(), param_2: Ext.get('my_id_2').getValue(), param_3: Ext.get('my_id_3').getValue() } }); } });
Any help would be much appreciated.
-
Best Answer Posted by remeis
I got it working: I've moved the above code with the Ext.override directive to the launch function of the application, like you did:
First, it did not work either. Then I switched the ExtJS library from ext.js to ext-debug.js in the HTML header:Code:Ext.application({ ... launch: function() { Ext.data.proxy.Server.override({ ... }); ... } });
And it magically worked!Code:<script src="extjs/ext-debug.js" type="text/javascript"></script>
So I guess, in order to use ext.js again (for the final apllication version), there is something missing, maybe one has to require a specific class, which I'm not aware of?
-
20 Oct 2011 6:30 AM #2
My other thought would be to add a listener for when the page is loaded, but I don't see any events specific Ext.app.application. Are there any?
-
20 Oct 2011 7:13 AM #3
Hi,
basically, I've the same problem: I'd like to override Ext.data.proxy.Server such that it will react on a failed request:
This works if I put this code directly above the store definition in the corresponding store file (app/store/myStore.js). Because I'd like to apply this to every store (in app/store) it would make sense to override the class in the main application file (app.js). But above the application definition doesn't work:Code:Ext.data.proxy.Server.override({ constructor: function() { console.log('overriden data.proxy.Server constructed'); return this.callOverridden(arguments); }, afterRequest: function(request, success) { if (! request.operation.success) { console.log('request failed'); } } });
I will continue working on this problem.Code:<-put the code above here does not work-> Ext.application({ name: 'myApp', appFolder: 'app', ... )};
-
20 Oct 2011 11:50 AM #4
I got it working: I've moved the above code with the Ext.override directive to the launch function of the application, like you did:
First, it did not work either. Then I switched the ExtJS library from ext.js to ext-debug.js in the HTML header:Code:Ext.application({ ... launch: function() { Ext.data.proxy.Server.override({ ... }); ... } });
And it magically worked!Code:<script src="extjs/ext-debug.js" type="text/javascript"></script>
So I guess, in order to use ext.js again (for the final apllication version), there is something missing, maybe one has to require a specific class, which I'm not aware of?Last edited by remeis; 21 Oct 2011 at 12:07 AM. Reason: typos in code section
-
21 Oct 2011 12:30 AM #5
Thanks a lot remeis, that worked for me as well! I will do some further testing and if I figure out what is missing then will post the solution using ext-all.js.
-
21 Oct 2011 12:38 AM #6
I think the most widely used technique for applying overrides in ExtJS 4 is:
This would be placed before the call to Ext.application().Code:Ext.require('classname', function() { // Callback for when the class has been loaded. Apply the overrides here. });
I'm a bit confused by the use of Ext.override() to set extraParams on Ext.Ajax.request. I don't really understand how that ever worked. As far as I can tell it'll be setting the extraParams on the prototype of the request function. Unless you're doing something really odd like new Ext.Ajax.request({...}) I can't see why they'd get picked up. Wouldn't this be a little more straightforward?
I also wonder whether you'd be better off using a cookie instead.Code:Ext.apply(Ext.Ajax.extraParams, { param_1: Ext.get('my_id').getValue(), param_2: Ext.get('my_id_2').getValue(), param_3: Ext.get('my_id_3').getValue() });
-
21 Oct 2011 1:05 AM #7


Reply With Quote
