Results 1 to 5 of 5

Thread: Show a Window once (ignore other tries to show it)

  1. #1
    Sencha User olivierpons's Avatar
    Join Date
    Dec 2009
    Location
    Aix en Provence,France
    Posts
    125

    Default Show a Window once (ignore other tries to show it)

    Hi!

    Suppose I have a class that defines a new Panel.

    Suppose I do one Ajax call and it returns an error.
    As soon as the error is triggered I show an error Panel (code follow) this way:

    Code:
    new WindowErrorPanel( 'error message' ).show();
    Now, suppose I do three Ajax calls and they all return the same error.
    As soon as the error is triggered I show an error Panel (code follow) the same way:
    Code:
    new WindowErrorPanel( 'error message' ).show();
    This means there will be 3 Panels and the user has to click three times.
    I just want to show this error panel once i.e. if it's already showing I do nothing.

    NB: I code everything in classes. This implies I do not want to create a "global" WindowErrorPanel and in my classes code I don't want something like:

    Code:
    myGlobalWindowErrorPanel.setMessage( 'error message' );
    myGlobalWindowErrorPanel.show();
    (Which could be a solution actually but I don't want it, this is not clean code to me).
    I want it to be clean and re-usable code.

    Any idea/advice how I should do?

    Here's my simple WindowPanelError class:

    Code:
    WindowErrorPanel = function(errorString,specialCaption) {
        WindowErrorPanel.superclass.constructor.call(this, {
            layout:'fit',
            width:300,
            height:150,
            closable: false,
            resizable: false,
            plain: true,
            modal: true,
            border: false,
            frame:true,
            title:'Erreur',
            items: [{
                html:errorString,
                readonly: true,
                frame:true,
                width:'99%',
                height:'99%'
            } ],
            destroyTask: new Ext.util.DelayedTask(function(){
                this.destroy();
            },this),
            buttons:[{
                text:'Ok',
                scope: this,
                handler:function(btn){
                    btn.disable();
                    this.destroyTask.delay(50);
                }
            }]
        });
        if(typeof specialCaption=='string') {
          this.title=specialCaption;
        }
    };
    Ext.extend(WindowErrorPanel, Ext.Window, {
        initComponent: function(){
            WindowErrorPanel.superclass.initComponent.call(this);
        }
    });

  2. #2

  3. #3
    Sencha User olivierpons's Avatar
    Join Date
    Dec 2009
    Location
    Aix en Provence,France
    Posts
    125

    Default

    Thank you very much indeed! That's a really good starting point, I'm just looking now for the way to get it by "class", not by "id".

    Instead of this code (which works):

    Code:
    var e=Ext.WindowMgr.get('id_window_error_panel');
    if (typeof(e)=='undefined') {
        new WindowLoginPanel().show();
    }

    I'd like to do something like:

    Code:
    var e=Ext.WindowMgr.get('class_windows_error_panel');
    if (typeof(e)=='undefined') {
        new WindowLoginPanel().show();
    }
    And this would be perfect (to me )

    Any other good suggestion?

  4. #4
    Sencha User Eugen_'s Avatar
    Join Date
    Feb 2010
    Posts
    106

    Default

    Let me think, I try to reply later...
    Why you don't want to use a singleton (myGlobalWindowErrorPanel)? Ext.WindowMgr is a singleton too.

  5. #5
    Sencha User olivierpons's Avatar
    Join Date
    Dec 2009
    Location
    Aix en Provence,France
    Posts
    125

    Default

    Hi!

    I don't want to use a singleton because I have to declare it as a global variable (= before the onReady function), whereas all the other variables are declared in the onReady function (which is very clean code from my p.o.v).

    Code:
    Ext.onReady(function(){
    
        Ext.QuickTips.init();
    
        var l_tree = new LabyzTree();
        var mainPanel = new MainPanel();
    
    ..
    }
    I want all the variables to be declared in the onReady function, and do everything else (which has been possible until now) in classes.

    A global variable here, this would mean the beginning of the bad code (if one here why not another one there? And so on). It's my own project, I do it on my spare time, I just want it to be perfect, because I have the time to make it perfect (FYI, see why here (read the 1st answer it explains why we have projects and why we want them to be clean)).
    Last edited by olivierpons; 12 Feb 2010 at 3:24 AM. Reason: typo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •