We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36360
    • 7 Posts
    Hi,

    I’m working on a Customer Manager Page that basically displays the details of a person object(first name, last name...) using display fields without any editing, my view widget is as follows:

    Players.panel.View = function(config) {
        config = config || {};
        Ext.apply(config,{
            border: false
            ,baseCls: 'modx-formpanel'
            ,url: Players.config.connectorUrl
            ,baseParams: { action: 'mgr/player/get' }
            ,items: [{
                html: '<h2>'+_('players.view.title')+'</h2>'
                ,border: false
                ,cls: 'modx-page-header'
            },{
                xtype: 'modx-tabs'
                ,bodyStyle: 'padding: 10px'
                ,defaults: { border: false ,autoHeight: true }
                ,border: true
                ,items: [{
                    title: _('players.view.tab-header')
                    ,defaults: { autoHeight: true }
                    ,items: [{
                        html: '<p>'+_('players.view.panel-desc')+'</p><br />'
                        ,border: false
                    } ,{
                        xtype: 'compositefield',
                        labelWidth: 120,
                        items: [{
                                    xtype     : 'displayfield',
                                    value: 'First Name:',
                                    width     : 120
                                },
                                {
                                    xtype     : 'displayfield',
                                    value: 'Yehia A.Salam'
                                }
                        ]
                    }]
                }]
            }]
        });
        Players.panel.View.superclass.constructor.call(this,config);
    };
    Ext.extend(Players.panel.View,MODx.Panel);
    Ext.reg('players-panel-view',Players.panel.View);


    However, the ’mgr/player/get’ never gets called, i’m sure the connector is working fine since am already using it in another grid widget, am i missing something here, how do i initiate and the ajax call and populate the displayFields.

    Appreciate the Help,
    And WOW, never thought the learning curve would be so steep for Modx Revolution.

    --
    Regards.
    Yehia A.Salam
      • 28215
      • 4,149 Posts
      1. Your panel should extend MODx.FormPanel, not MODx.Panel
      2. Give the panel an ID
      3. Ext.getCmp(’id-of-panel’).setValues({ ’key’: ’value’, ’etc’: 123});
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 36360
        • 7 Posts
        thanks, I’m know facing another problem when posting using ajax, I do the ajax call using Mox.Ajax.Request and everything goes fine and i get the json file(check attached), but for some reason the success event listener is not fired and i get a very weird empty Error Dialog:

        Players.panel.View = function(config) {
            config = config || {};
            Ext.apply(config,{
                id: 'players-panel-view'
                ,border: false
                ,baseCls: 'modx-formpanel'
                ,url: Players.config.connectorUrl
                ,baseParams: { action: 'mgr/player/get' }
                ,fields: [{
                    xtype: 'textfield'
                    ,fieldLabel: _('players.first_name')
                    ,name: 'first_name'
                    ,width: 300
                }]
                ,items: [{
                    html: '<h2>'+_('players.view.title')+'</h2>'
                    ,border: false
                    ,cls: 'modx-page-header'
                },{
                    xtype: 'modx-tabs'
                    ,bodyStyle: 'padding: 10px'
                    ,defaults: { border: false ,autoHeight: true }
                    ,border: true
                    ,items: [{
                        title: _('players.view.tab-header')
                        ,defaults: { autoHeight: true }
                        ,items: [{
                            html: '<p>'+_('players.view.panel-desc')+'</p><br />'
                            ,border: false
                        } ,{
                            xtype: 'compositefield',
                            labelWidth: 120,
                            items: [{   
                                        xtype     : 'displayfield',
                                        value: 'First Name:',
                                        width     : 120
                                    },
                                    {   name: 'lblFirstName',
                                        xtype     : 'displayfield',
                                        value: ''
                                    }
                            ]
                        }]
                    }]
                }]
                ,listeners: {
                    render: function(p) {
        
                        MODx.Ajax.request({
                                        url: Players.config.connectorUrl 
                                        ,params: {
                                            action: 'mgr/player/get',
                                            id: '14' 
                                        },listeners: {
                                            'success': {fn:function(r) {
                                                alert(r.results);
                                                //p.getForm().setValues({ 'lblFirstName': r.results.first_name});
                                            }, scope:this}
                                        }
                        });
        
                    }
                }
            });
            Players.panel.View.superclass.constructor.call(this,config);
        };
        
        
        Ext.extend(Players.panel.View,MODx.FormPanel);
        Ext.reg('players-panel-view',Players.panel.View);
        
          • 36360
          • 7 Posts
          okay, i got it working but with using the native Ext.Ajax call:

                          Ext.Ajax.request({
                             url: Players.config.connectorUrl ,
                             success: function(t){ 
                                  var jsonData = Ext.util.JSON.decode(t.responseText);
                                  p.getForm().setValues({ 'lblFirstName': jsonData.results.first_name});
                             },
                             params: { action: 'mgr/player/get', id: '14' }
                          });
          
                          /*MODx.Ajax.request({
                                          url: Players.config.connectorUrl 
                                          ,params: {
                                              action: 'mgr/player/get',
                                              id: '14' 
                                          },listeners: {
                                              'success':{fn:function(r) {
                                                  alert(r);
                                                  //p.getForm().setValues({ 'lblFirstName': r.results.first_name});
                                              }, scope:this}
                                          }
                          });*/
          


          But still, I just needed to know what does MODX.Ajax includes that cause the error, I looked up the extended class in modx.js, but found nothing suspicious:
          /**
           * An override class for Ext.Ajax, which adds success/failure events.
           *
           * @class MODx.Ajax
           * @extends Ext.Component
           * @param {Object} config An object of config properties
           * @xtype modx-ajax
           */
          MODx.Ajax = function(config) {
              config = config || {};
              MODx.Ajax.superclass.constructor.call(this,config);
              this.addEvents({
                  'success': true
                  ,'failure': true
              });
          };
          Ext.extend(MODx.Ajax,Ext.Component,{
              request: function(config) {
                  this.purgeListeners();
                  if (config.listeners) {
                      for (var i in config.listeners) {
                        if (config.listeners.hasOwnProperty(i)) {
                          var l = config.listeners[i];
                          this.on(i,l.fn,l.scope || this,l.options || {});
                        }
                      }
                  }
          
                  Ext.apply(config,{
                      success: function(r,o) {
                          r = Ext.decode(r.responseText);
                          if (!r) { return false; }
                          r.options = o;
                          if (r.success) {
                              this.fireEvent('success',r);
                          } else if (this.fireEvent('failure',r)) {
                              MODx.form.Handler.errorJSON(r);
                          }
                          return true;
                      }
                      ,failure: function(r,o) {
                      	r = Ext.decode(r.responseText);
                          if (!r) { return false; }
                      	r.options = o;
                      	if (this.fireEvent('failure',r)) {
                              MODx.form.Handler.errorJSON(r);
                      	}
                          return true;
                      }
                      ,scope: this
                      ,headers: {
                          'Powered-By': 'MODx'
                          ,'modAuth': config.auth
                      }
                  });
                  Ext.Ajax.request(config);
              }
          });
          Ext.reg('modx-ajax',MODx.Ajax);
          
            • 36360
            • 7 Posts
            the Modx.Ajax expects a ’success’ key value return in the json, so you have to return it in the processor

            return $modx->error->success('',$ar_player);


            how come that stuff like this is not documented anywhere?
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              Feel free to help with the documentation and save others the trouble you had.. Or at least help by filing that and any other things you’re missing in the docs here: http://bugs.modx.com/projects/docs/issues

              I learned stuff like that by going through other code (Quip is a popular "doc") mainly but there definitely needs to be more documentation on the whole ExtJS implementation and how to really use it. The Digital Butter guys promised to get a series on ExtJS out soon on their blog: http://www.butter.com.hk/blog/
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 37286
                • 160 Posts
                Ext.Ajax.request vs MODx.Ajax.request, you just saved me a ton of time. I've been working on this same type of scenario since yesterday. I had already looked over http://rtfm.modx.com/display/revolution20/MODx.Console and saw nothing on Ext.Ajax.request yesterday ( I posted a comment at the end of the page on this subject for anyone else who decides to read the docs before going to the forum ). I don't think I would have ever figured this out if I hadn't stumbled across this page.

                Thanks for posting your solution.
                  • 12066
                  • 48 Posts
                  Thanks @yeahiasalam,

                  your post saved me a lot of headache & time!
                  It guided me into the right direction regarding concurrent MODx.Ajax.request, which seems to be still an issue.

                  There was a bug filed by splittingred...
                  http://tracker.modx.com/issues/4478 [ed. note: herooutoftime last edited this post 13 years, 3 months ago.]