Results 1 to 6 of 6

Thread: Using ViewControllers with floating components attached by the view

  1. #1
    Ext JS Premium Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    181
    Answers
    3

    Default Answered: Using ViewControllers with floating components attached by the view

    Hi,


    We have scenarios where screen (view) specific popups(windows/dialogues), context menus, and other components which may be floating or invoke not added as descendents of the screen. As I understand it, using view controllers only allows referencing a component which has been added directly to the bound view or children. Currently, I have code which handles cleaning up and unregistering controller code from the eventbus, but I'd rather use the features of view controllers to handle removing and added events to the popups and context menus. Is it possible to do this without using an application level controller or creating view controllers for each popup / menu? Is it possible to associate these components to the view whichout doing something like view.add()?


    Here is a link to a fiddle which contains an example:


    https://fiddle.sencha.com/#fiddle/11gv


    Test 1:
    - Click the "Show Popup", a window should open with a button labeled "Close".
    - Click the "Close" button, nothing will happen.


    Test 2:
    - Right click the "Show Popup", a context menu will open.
    - Click any of the item in the context menu, nothing will happen

    I am also aware of this post. I just want to make sure it still holds true.

    https://www.sencha.com/forum/showthr...d-context-menu


    Thanks,


    Bryan

  2. Code:
    openPopup: function() {
       var me = this;
       var win = Ext.create('Ext.window.Window', {
           title: 'My Popup',
           width: 300,
           height: 300,
           items: [{
               xtype: 'button',
               text: 'close',
               listeners: {
                  click: function(b) {
                      b.ownerCt.fireEvent('close', b.ownerCt);
                  }
               }
           }],
           modal: true,
           listeners: {
               close: me.closePopup
           }
       });
       win.show();
    },
    closePopup: function(cmp) {
        cmp.close();
    }

  3. #2
    Sencha User alex.volfson's Avatar
    Join Date
    Jan 2016
    Posts
    462
    Answers
    60

    Default

    You could use the technique in the previous post if it works in your situation. Based on your code sample, I wouldn't use a controller listener to close a popup. Alternatively, you can use the button handler method and call -- this.up('window').close();

  4. #3
    Ext JS Premium Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    181
    Answers
    3

    Default

    Your answer completely violates the robust MVC built into ext. You would want to attach the close / handler in the controller because in large applications it is easier to manage events from a controller rather than an individual component level.

  5. #4
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249
    Answers
    7

    Default

    Code:
    openPopup: function() {
       var me = this;
       var win = Ext.create('Ext.window.Window', {
           title: 'My Popup',
           width: 300,
           height: 300,
           items: [{
               xtype: 'button',
               text: 'close',
               listeners: {
                  click: function(b) {
                      b.ownerCt.fireEvent('close', b.ownerCt);
                  }
               }
           }],
           modal: true,
           listeners: {
               close: me.closePopup
           }
       });
       win.show();
    },
    closePopup: function(cmp) {
        cmp.close();
    }

  6. #5
    Ext JS Premium Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    181
    Answers
    3

    Default

    That actually wouldn't work in a view controller... you have to add the popup to the view containing the controller.

  7. #6
    Sencha Premium User jvandemerwe's Avatar
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    249
    Answers
    7

    Default

    Quote Originally Posted by bmacdon1 View Post
    That actually wouldn't work in a view controller... you have to add the popup to the view containing the controller.
    I don't think that this is true. The "var me = this" in my sample is the view or the viewController. And the close event on the window listener is calling "me.onClosePopup", that would be a function in your viewController.

Similar Threads

  1. [INFOREQ] Grid column references incorrectly get attached to parent view
    By andersonjf in forum Ext 5: Bugs
    Replies: 5
    Last Post: 9 Jun 2015, 12:25 AM
  2. Replies: 4
    Last Post: 19 Sep 2014, 11:19 AM
  3. Replies: 7
    Last Post: 4 Mar 2013, 7:34 AM
  4. View pushed onto navigation view only works once (project attached)
    By CarClub in forum Sencha Architect 2.x: Bugs
    Replies: 0
    Last Post: 19 May 2012, 3:35 PM
  5. Replies: 3
    Last Post: 1 Aug 2011, 3:11 AM

Posting Permissions

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