New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Jeff Miranda Reply #1, 3 years ago
    MODX 2.4

    I've built a CMP that contains a form panel with some fields. The behaviour I'm looking for is similar to how MODX handles new resources or chunks, etc. namely that once the new element is saved, the page loads the update version of the form with the newly created element loaded.

    Here is my page code:

    Ext.onReady(function() {
        MODx.load({ xtype: 'pop-page-events-create-manifest' });
    });
    Pop.page.EventsCreateManifest = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            formpanel: 'pop-panel-events-create-manifest'
            ,buttons: [{
                reload: true
                ,text: _('pop.save')
                ,id: 'pop-manifest-btn-save'
                ,cls: 'primary-button'
                ,process: 'mgr/events/popmanifestcreate'
                ,params: {
                    namespace: 'popupstudio'
                }
                ,method: 'remote'
                ,keys: [{
                    key: MODx.config.keymap_save || 's'
                    ,ctrl: true
                }]
            },{
                text: _('pop.cancel')
                ,handler: function() {
    	        	location.href = '?a=events/home&namespace=popupstudio&activeTab=2';
    	        }
    	        ,scope:this
            }]
            ,components: [{
                xtype: 'pop-panel-events-create-manifest'
                ,renderTo: 'pop-panel-events-create-manifest-div'
            }]
        });
        Pop.page.EventsCreateManifest.superclass.constructor.call(this,config);
    };
    Ext.extend(Pop.page.EventsCreateManifest,MODx.Component);
    Ext.reg('pop-page-events-create-manifest',Pop.page.EventsCreateManifest);


    I have the whole thing working except for the redirect. The page I keep getting redirected to is

    http://mydomain:8080/manager/?a=mgr/events/popmanifestupdate&namespace=popupstudio&id=48

    The page I want to get to is

    http://mydomain:8080/manager/?a=events/updatemanifest&namespace=popupstudio&id=48

    I looked at the code for modx.component.js and it seems that when reload is true, it's taking the process value, replacing "create" with "update" and the result is being used as the first parameter in a MODx.loadPage() call. Here are lines 322 to 330 of modx.component.js:

                var action;
                if (o.actions && o.actions.edit) {
                    // If an edit action is given, use it (BC)
                    action = o.actions.edit;
                } else {
                    // Else assume we want the 'update' controller
                    action = itm.process.replace('create', 'update');
                }
                MODx.loadPage(action, url);
    


    Correct me if I'm wrong but what was once my processor call is now becoming my action call for my controller? Am I understanding this correctly? It's driving me crazy because the two aren't interchangeable. I mean, it works for elements like resources and the like but it doesn't really work for CMP namely because the processor calls usually have the "mgr/" prefix.

    I guess I'm wondering if I'm going about this the right way. Should I continue to try and use the "reload" parameter or should I ditch that, and redirect on the form panel's success event and load the update form "manually"? Some guidance would be appreciated. I want to take advantage of the "MODX way" of doing things but it seems like this reload parameter is more trouble than it's worth.
    • I wonder if adding an action:"edit" member to your reload JS would work.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • Jeff Miranda Reply #3, 3 years ago
        Thanks for the reply Bob but no good. Additionally, I still haven't been able to figure out where or how that "o.actions" variable gets populated. When I inspect it it's always null. I mean, I can work things out fine enough using the method I spoke of earlier, but I wonder if there is another way someone knows about that makes use of the existing framework a bit more.
        • Hey Jeff,
          did you found a solution for this issue?