Search code examples
extjs4

How to show existing window in Ext Js using Sencha designer


I am new in Ext js. I started Ext js with ext designer 1.2 now I use sencha designer 2.0, I created panel and button on it, and window. Now I want to use click event to show my window on click but I do not know how, I searched in many sites and especially in sencha.com but I could not find, I can show new window by creating it onclik function but I want to show existing one, if anyone knows could you please tell me how. I am interested in controllers in secha designer.

How to do it without controllers on directly inserting code in onclickbutton function?


Solution

  • Here is what I have done for this use case:

       /**
         * Check to see if window already open with the specified ID.
         * If window exists, bring it to front and expand if collapsed.
         * @param id
         */
        windowAlreadyOpen: function(id){
            //Check for already opened window with the same  ID
            var windowOpen = Ext.ComponentQuery.query('window[id='+id+']'); //always returns array
            if (windowOpen && windowOpen[0]){
                    try {
                        windowOpen[0].toFront();            //bring to front
                        if (windowOpen[0].collapsed){
                           windowOpen[0].toggleCollapse();  //expand window if collapsed
                        }
                    } catch (e) {
                        console.error(e);
                    }
                    return windowOpen[0];
            }
            return false;
        }