1. #1
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default select item in a view when object is hold in memory

    select item in a view when object is hold in memory


    Hi,

    i hope the title tells what i try to do.

    If !dialog, i got the selection with view.on("load",...)
    but when i hide the dialog and reopen with anotherlink (and another id) i don't know how to reference it right.

    Here is my code (i marked red what i look for):

    Code:
    var FriendsPanel = function(){
        // everything in this space is private and only accessible in the HelloWorld block
        
        // define some private variables
        var dialog, showBtn,id;
        
        
        // return a public interface
        return {
            init : function(){
                                      
            },
           
            showDialog : function(id){
                if(!dialog){ // lazy initialize the dialog and only create it once
                    dialog = new Ext.LayoutDialog("friends-dlg", { 
                            modal:true,
                            width:600,
                            height:400,
                            shadow:true,
                            minWidth:300,
                            minHeight:300,
                            proxyDrag: true,
                            west: {
    	                        split:true,
    	                        initialSize: 150,
    	                        minSize: 100,
    	                        maxSize: 250,
    	                        titlebar: true,
    	                        collapsible: true,
    	                        animate: true,
                                autoScroll:true
    	                    },
    	                    center: {
    	                        autoScroll:true,
    	                        tabPosition: 'top',
    	                        closeOnTab: true,
    	                        alwaysShowTabs: true,
                                animate: true
    	                    }
                    });
                    dialog.addKeyListener(27, dialog.hide, dialog);
                    dialog.addButton('Schliessen', dialog.hide, dialog);
                      
                    var layout = dialog.getLayout();
                     
                    layout.beginUpdate();
                    var wl=layout.add('west', new Ext.ContentPanel('west', {title: 'Freunde'}));
    	            var cl=layout.add('center', new Ext.ContentPanel('center', {title: 'Details'}));
                    
                    
    	            layout.endUpdate();
                    
                    var reader = new Ext.data.JsonReader({
                            totalProperty: 'results',
    		                root:'items'
                    }, [{name: 'uid'}, {name: 'name'}]);
                    var reader2 = new Ext.data.JsonReader({
                            totalProperty: 'results',
    		                root:'items'
                    }, [{name: 'uid'}, {name: 'name'}, {name: 'image'}]);
                    
                    ds = new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: 'index.php?id=1&type=1001&data=friends'
                        }),
                        reader : reader
                    });
                    ds2 = new Ext.data.Store({
                        proxy: new Ext.data.HttpProxy({
                            url: 'index.php?id=1&type=1001&data=cities&bl='
                        }),
                        reader : reader2
                    });
                    
                    ds.on('load', this.onLoad, this);
                    ds2.on('load', this.onLoad, this);
                
                    var tpl = new Ext.Template(
                      '<div class="friend-item" id="fi_{uid}">' +     
                      '<a href="#" id="f_{uid}">{name}</a>' +
                      '</div>'
                    );
                    tpl.compile();
                    var tpl2 = new Ext.Template(
                      '<div class="friend-detail">' +
                      '<h2>{name}</h2>' +
                      '<p><img src="{image}" /></p>' +
                      '<p>{userpage}</p>' +
                      
                      '</div>'
                    );
                    tpl2.compile();
                    
                    var view = new Ext.JsonView(Ext.get('west'), tpl, {
                       jsonRoot: ds,
                       selectedClass: 'selfriend',
                       singleSelect: true
                    });
                    var detail = new Ext.JsonView(Ext.get('center'), tpl2, {
                       jsonRoot: ds2
                    });
                    
                    view.prepareData = function(data){
                        return {
                            uid: data.uid,
                            name: data.name.replace(/<\/?[^>]+>/gi, '').ellipse(350)
                        
                        };
                    };
                    view.on("click", function(vw, index, node, e){
                        //alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
                        detail.load('index.php?id=1&type=1001&data=friends&bl='+node.firstChild.id);
                    });
                    
                    view.load('index.php?id=1&type=1001&data=friends');
                    
                    view.on("load",function() {view.select('fi_'+id.substring(2));});   
                    detail.load('index.php?id=1&type=1001&data=friends&bl='+id); 
                         
                }  else {
                    //select the right user here
                     view.on("load",function() {view.select('fi_'+id.substring(2));}); //doesn't work
                }
                ext9=Ext.get('ext-gen9');
                dialog.show(ext9.dom);
            }
        };
    }();

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Code:
                     view.on("load",function() {
                         view.select('fi_'+id.substring(2));
                      }); //doesn't work
    Format it like that, set a breakpoint in that function, and debug it like a programmer!

  3. #3
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    wow, very fast

    i did, but the error is "view has no properties" i don't know why.

    thx

  4. #4
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    when i debug at this point, no object of the dialog is defined, so i don't know how to reference it the right way or how to make view public outside dialog.

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You have "var view" in one side of your if...else. That's a local variable. Obviously on the other side of your else there is no variable called "view".

    Think about it. Where should that declaration go? Have you programmed C? (Or almost any other language) Same principle.

  6. #6
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    Hi Animal,

    i tried to do it that way:

    PHP Code:
    var FriendsPanel = function(){
        
        
    // define some private variables
        
    var dialogview;
        ... 
    But it doesn't help. Because i'm inside FriendsPanel view should be known, why not ?

    ps i come from php, C is a very long time ago. In phpclass it's the same, i can reach this vars with this.var - in this case it doesn't work. So i would very glad if you could help me, thx.


    //edit
    ok, i got it public, i changed inside all view to this.view - but now the select doesn't work (view is known outside now!)
    Is that wrong syntax ?

    PHP Code:
    //snip
    this.view = new Ext.JsonView(Ext.get('west'), tpl, {
                       
    jsonRootds,
                       
    selectedClass'selfriend',
                       
    singleSelecttrue
                    
    });
                    var 
    detail = new Ext.JsonView(Ext.get('center'), tpl2, {
                       
    jsonRootds2
                    
    });
                    
                    
    this.view.prepareData = function(data){
                        return {
                            
    uiddata.uid,
                            
    namedata.name.replace(/<\/?[^>]+>/gi'').ellipse(350)
                        
                        };
                    };
                    
    this.view.on("click", function(vwindexnodee){
                        
    detail.load('index.php?id=1&type=1001&data=friends&bl='+node.firstChild.id);
                    });
                    
                    
    this.view.load('index.php?id=1&type=1001&data=friends');
                    
    //alert('fi_'+id.substring(2));
                    
    this.view.on("load",function() {
                       
    this.view.select('fi_'+id.substring(2)); //now there is no selection
                    
    }); 

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Why doesn't it work?

  8. #8
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    good question - i don't understand - error is "this.view has no properties"

    I made this snippet on a extra page so you can see this script live:
    http://www.sk-typo3.de/ExtJS-Dialog.338.0.html

    It worked with the local var, so i have no idea why it doesn't now.

  9. #9
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,656
    Vote Rating
    6
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    got it - in this case it has to be in this way:

    PHP Code:
    this.view.on("load",function() {
       
    this.select('fi_'+id.substring(2)); //now there is no selection
    }); 
    and outside only

    PHP Code:
       this.view.select('fi_'+id.substring(2)); 

Thread Participants: 1