Results 1 to 5 of 5

Thread: Prevent opening same window twice

  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    3

    Default Prevent opening same window twice

    Hi folks,

    First post (please be gentle!)

    I have subclassed the standard Ext Window class to show details of a contact in a system I am developing. Noting fancy - usual stuff:

    Code:
    MyApp.ContactWindow=Ext.extend(Ext.Window, {
      initComponent=function() {
        <snip>
      }
    });
    An example of creating an instance of a contact Window as follows:

    Code:
      var win=new MyApp.ContactWindow({
        contactId: 1234
    }).show();
    This could be called for example in the row click handler of a search grid.

    What I want to do though is to include some code in either the overridden initComponent method (or possibly the constructor method) of MyApp.ContactWindow which checks if I already have a window open for contactId 1234 if not, instantiate a window as normal, but if so simply return the pre existing window.

    I have no difficulty setting the id of the new window to something like
    Code:
    contact_window_1234
    and I am able to test for the existence of a component with this id in the constructor.

    How though would I abandon the object creation and return this existing window?

    (I hope this makes sense!)

  2. #2
    Ext JS Premium Member Nigel's Avatar
    Join Date
    Nov 2008
    Location
    Hampshire, England
    Posts
    57

    Default

    I've done something similar in my application, using a desktop-like environment with multiple windows. My advice would be to do the test for the existing window before instantiating the object, then either instantiate or bring-to-top/restore the existing window. Looking ahead, you'd be best off making this a generic method of your application as you're going to need it for just about every window you produce.
    I expect there are other ways as well, and I'd be interested as well to see if anyone else has taken a different approach.
    Good Luck!

  3. #3
    Sencha Premium User
    Join Date
    Nov 2007
    Location
    Madrid, Spain
    Posts
    20

    Default

    I solve it doing that each time i want to show a window module:

    Code:
                        if (Ext.myApp.myModule == null) {
                            Ext.myApp.myModule = new cls_myModule();
                        }
                        Ext.myApp.myModule.init(initParameters);
    -------------------------------------
    SQL Server expert consultant.
    ExtJS developer from ExtJS 1.0 version to now.
    Java developer.


    Working as freelance and in my own company from 1.999
    https://www.linkedin.com/in/cesarzea/
    www.jaunesistemas.com

  4. #4
    Sencha User
    Join Date
    Jan 2011
    Posts
    3

    Default

    If I understand you correctly cesarzea, Ext.myApp.myModule is a singleton factory class for generating windows, and will contain a method something along the lines of:

    Code:
    init: function(config) {
      if (Ext.getCmp(config.id)) {
        return Ext.getCmp(config.id);
      } else {
        return new MyApp.ContactWindow(config)
      }
    }
    Is that correct?

  5. #5
    Ext User
    Join Date
    Sep 2010
    Location
    Baltimore, MD
    Posts
    66

    Default

    Hello,

    Thats not the way I interpret the code cesarzea posted. I believe it to be:

    Ext.myApp.myModule is the actual variable (the window you are trying to create), and this sees if its already created or not:
    Code:
    if (Ext.myApp.myModule == null ) {
    if it's not created already, this variable would be null, so it enters the if statement and executes the function cls_myModule, therefore cls_myModule() is the factory function you are mentioning.. I believe it would return the object you are trying to create:
    Code:
    Ext.myApp.myModule = new cls_myModule();
    Then at the last part, it's the either been created if it didnt already exist, or it already existed so we skipped over the create and are good to go, so we call init ( set the parameters, make the window visible, etc )
    Code:
    Ext.myApp.myModule.init(initParameters);

Similar Threads

  1. How to prevent users from opening ExtJS apps in multiple tabs
    By Perceptive in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 2 Dec 2010, 9:14 AM
  2. Replies: 13
    Last Post: 23 Jun 2010, 6:59 AM
  3. browser window crashing in IE while opening FCK editor in window.
    By rockys in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 19 Jun 2009, 2:17 AM
  4. Replies: 1
    Last Post: 31 Jan 2008, 9:17 AM
  5. Prevent duplicate tab from opening
    By Ephicient in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 9 Dec 2007, 7:22 PM

Tags for this Thread

Posting Permissions

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