PDA

View Full Version : Need to modify app Ext.Loader path, but It gets overwritten by AppFolder. config :(



thesilentman
28 May 2012, 9:34 PM
Hello,

I'd appreciate if anyone from the Forum Gurus could lend me a helping hand with this. :)

I need to set the Ext.Loader-Path for my app files so that the classes can be loaded like so:


index.php?file=/app/MyClass.js
or
index.php?file=/store/MyStore.js

A posible path config could be like so :

MyApp.app : index.php?file=/app/
or
MyApp.store: index.php?file=/store/

The reason for this is, that the files should not be loaded directly from a server path and also, it could be possible that some could be loaded from a database server or constructed from another php file.

They should be loaded through a "getter script" which loads the files and passes them through. The back-end parts are fine, but I can't get the Ext.Loader to do the magic....

I have also tried with Ext.Loader.setConfig ({paths:{:}}), but also no joy....

Any ideas anybody?

Thank you :)

vadimv
28 May 2012, 10:55 PM
you should not forget that dynamic loading is supposed to be used only during developing, in production you should have only one js file, of course depends, if there's a app with subapps/modules then each subapp will have its js file, or the js file is getting to big....

thesilentman
29 May 2012, 2:12 AM
Hi,
Thanks for your answer.

Yes, I am aware of that fact, it's just that it's a good tool to have in the toolbox. And one can have a bit of both worlds.
However, after a quick nap and a clearer head, I think I'll override Ext.app.Application and change the line where the appFolder config is assigned to the app path of Ext.Loader.
I'll do some tests and see how it goes. Maybe I can answer my own question later on :))

thesilentman
29 May 2012, 6:37 AM
So after a bit of head scratching, here is my solution to my problem, in case someone should have a need for it .

I implemented my solution inside the 'getPath' method of the Ext.Loader.

The thing wth Ext.Loader is, that it's a simple object not a class, and it can't be overridden using Ext.override, because the override is on the prototype and there's no scope. (Please correct me if there is some other way to override the object's method and keep the scope)

So my quick and dirty solution was to just copy 'Loader.js' from the source (src/core/src/class/) into my overrides directory, make the needed changes and include it before 'app.js'.

BTW, this is on ExtJS 4.1.

So, here the modified getPath ,method (Explanation below):


getPath: function(className) {
//console.log('overridden getpath');
var path = '',
paths = Loader.config.paths,
prefix = Loader.getPrefix(className);

if (prefix.length > 0) {
if (prefix === className) {
return paths[prefix];
}

path = paths[prefix];
className = className.substring(prefix.length + 1);
}

if (path.length > 0) {
path += '/';
}
if(this.config.customAppPrefix){
// custom path
path=this.config.customAppPrefix;
return path+className.replace(dotRe, "/") + '.js';
}else{
// normal path
return path.replace(slashDotSlashRe, '/') + className.replace(dotRe, "/") + '.js';
}


},


The method has been modified to accept a custom app prefix (Ext.Loader.config.customAppPrefix).
If it finds a value in that property, it applies that value as the app prefix, instead of whatever would be the appFolder (Ext.app.Application.appFolder) prefix.

If the customAppPrefix config of Ext.Loader is changed later on, the method will use the changed prefix.

To the Extjs-DevTeam. Maybe something like this could make it into the Loader class, as it gives us more freedom without this dirty patch?? :D

I'm marking this as answered, as I think this is a viable solution. But please don't hesitate to post a better one ;)

jpolvora
26 Apr 2014, 1:13 AM
Today I needed to change the filename extension of javascript files in order to get server side manipulation/processing in ASP.NET.

Anyway, the better approach for "patching" javascript methods/functions of existing objects is the following:





//original implementation
var getPath = Ext.Loader.getPath;


//custom impl
var customGetPath = function (klassName) {
var result = getPath(klassName); //calls the original
var newResult = result.replace('.js', '.cshtml'); //my 'patch'
return newResult;
};


Ext.Loader.getPath = customGetPath;


Hope it helps.