1. #1
    Sencha User
    Join Date
    Aug 2012
    Location
    Fabrègues, France
    Posts
    48
    Vote Rating
    0
    gostbuster is an unknown quantity at this point

      0  

    Default Loading classes on the fly from server ( widgets style)

    Loading classes on the fly from server ( widgets style)


    Hi there,

    I'm quite a new French user of sencha touch 2 and really appreciate this tool.

    I need to develop an application which works with widgets (lets all it MyApp). Let me explain :

    My application has a list of services. Each service is actually a little application (like a widget).

    Services are on the web server, but I wan't my app to be stand alone.

    I can't have written my services classes (models, views, controllers) in my application folders because services have to be developped and managed separately (that's mean I would like to be able to add or remove services whenever I wan't)

    I imagined a solution like that :

    Code:
    MyApp/
                view/
                      Widget.js
                controller/
                      Widget.js
    When I initialize my Widget js, I launch an Ajax request (CORS), like that :

    Code:
     Ext.Ajax.request({
                url: 'http://myserver/myscript.php',
            useDefaultXhrHeader: false,
               
                  success: function(response) {
                  //myscript.php only contains javascript so I simply eval it
                   eval(response.responseText);
                  
                    // I create a page with A class 'ScriptPage' written in myscript.php and evaluated in ajax success
                     var page=Ext.create('Test.view.ScriptPage');
                   //I had it on my viewport,
                    Ext.getCmp('viewPort').add(page);
                
                }  
            });
    The aim is to load new classes from ajax request and then work with theses new classes.
    Now let's have a look on what is myscript.php on server side.


    myscript.php only contains javascript. I use smarty to generate the all code with fetching files like this :
    Code:
    {* ------ MODELS -------- *}
    {fetch file='templates/mobile/model/Widget.js'}
    
    
    {* ------ CONTROLLERS -------- *}
    {fetch file='templates/mobile/controller/Widget.js'}
    
    
    {* ------ VIEW -------- *}
    {fetch file='templates/mobile/view/ScriptPage.js'}
    As a result of this, this is only javascript with classes code displayed.
    I wan't to keep my code well organized so I used the same folder organisation.

    Unfortunately, when I try to create a Test.view.ScriptPage instance, there is an error :

    Uncaught Error: [Ext.Loader] Failed loading 'app/view/ScriptPage.js',


    That is for use, this file doesn't exists on the application side, it's on the server side, but the class Test.view.ScriptPage should exists cause I got it with my ajax request and evaluated it....

    Well that was just to illustrate what I'm trying to do.

    What experts suggest ? My need is to be able to load classes with ajax request and use them.

    Thanks in advance.
    Please don't hesitate to ask for more precision if needed.

    Regards

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,677
    Vote Rating
    749
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So you return this:

    Code:
    {fetch file='templates/mobile/view/ScriptPage.js'}
    or is it actually the JavaScript for that class?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Location
    Fabrègues, France
    Posts
    48
    Vote Rating
    0
    gostbuster is an unknown quantity at this point

      0  

    Default


    Thank you for replying,

    Actually, myscript.php on server side includes my classes written on server side. The result of this all the code of my classes like this :

    Code:
    Ext.define('Myapp.controller.widgetController',{
    [.......]
    });
    
    Ext.define('Myapp.view.widgetPanel',{
    [.......]
    });
    Then, my app receive with ajax response all this javascript and simply do an

    Code:
    eval(response.responseText);
    Then I would just like to create an instance of 'Myapp.view.WidgetPanel' and display it,

    Unfortunately, the new classes just got from ajax are unknow by the app which try to get the js files on the app side instead of using the classes just evaluated.

    Do you understand better of shall I maybe make a schematic of this ?

  4. #4
    Sencha User
    Join Date
    Aug 2012
    Location
    Fabrègues, France
    Posts
    48
    Vote Rating
    0
    gostbuster is an unknown quantity at this point

      0  

    Default


    Hello,

    I'm still workin on it, and maybe it would need more explanation as I assume this is maybe not a normal behaviour.

    Well you certainly all know netvibes or iGoogle, they are portals with widgets. Let's consider each widget as a standalone application. (This is actually the true, each widget is independant from the "portal").

    Well I would like to do the same with my sencha app.
    You'll find the schematic of what I'm wishing to do.

    I have on the first side my Sencha App loaded on my device (It could be a phonegap app, so all the app files are on the phone).

    On the second side, I have an Apache server with folders, each folder is a widget. In fact, I'm able to add futures widgets without loading a new version of my sencha device app.

    What I would like to do is to load widgets classes (this is js code), from an ajax request, and after evaluating this, be able to use it.
    I organized my widgets with view/controller/model to keep the MVC organization.

    The result of my ajax request would be :

    Code:
    Ext.define('Widget1.controller.MyWidget1Controller'),{
    /** here all my class***/
    })
    //then the views, and the models, 
    Ext.define('Widget1.model.MyWidget1Model'),{
    /** here all my class***/
    })
    Ext.define('Widget1.view.MyWidget1View'),{
    /** here all my class***/
    })
    etc....
    I eval this code, so then I can create a MyWidget1View view, add it to my viewport and display it....and also be able to trigger events written in MyWidget1Controller.....

    What do Sencha Experts think of this ? Thank you in advance !



    schemasencha.png

  5. #5
    Sencha User
    Join Date
    Aug 2012
    Location
    Fabrègues, France
    Posts
    48
    Vote Rating
    0
    gostbuster is an unknown quantity at this point

      0  

    Default


    Any ideas ? This does not seem to inspirate you....
    Don't hesitate to ask me if there is something you don't understand

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar