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

    is it possible to transfer the selected docid of a page in the manager to a CMP?

    Tried it with "action=".$_REQUEST['id']." but code gets filtered. Is there another way of getting this id variable get attached to the CMP call?? Would be great for my plugin, as an additional gui element won't be need (the doctree).

    Greetings
      • 33968
      • 863 Posts
      That's php code there, are you using it in a CMP?

      You can access request variables using the following:
      MODx.request.id

      That will give you the same as $_REQUEST['id'] for use in your ExtJs code.

      Have a look here to see other variables available within the MODx object:
      http://rtfm.modx.com/display/revolution20/MODExt+MODx+Object
        • 19486
        • 14 Posts
        Hi,

        yep, I tried php in the form for the actions. Not in the actual php file. In the manager the id of doc is visible as long as you have selected a resource in the tree.

        For my CMP it would be nice to get this id as parameter on the action call. So I wouldn't need to include the tree Panel in the CMP. Which I do now.

        Would be great to be able to pass this variable (like the 'a') in future versions on to the action. Very specific but also very usable.
          • 33968
          • 863 Posts
          To be honest I'm not exactly sure how you want to obtain the id and what you want to do with it.

          Do you want to be able to click a resource in the tree and pick up it's id, in the same way that you can select a parent when editing a resource? If that's the case, here's how it's been done in that instance (you'll obviously need to adapt it for your requirements):

          //from manager/assets/modext/widgets/core/modx.com.js
          MODx.ChangeParentField = function(config) {
              config = config || {};
              Ext.applyIf(config,{
                  triggerAction: 'all'
                  ,editable: false
                  ,readOnly: false
                  ,formpanel: 'modx-panel-resource'
              });    
              MODx.ChangeParentField.superclass.constructor.call(this,config);
              this.config = config;
              this.on('click',this.onTriggerClick,this);
              this.addEvents({ end: true });
              this.on('end',this.end,this);
          };
          Ext.extend(MODx.ChangeParentField,Ext.form.TriggerField,{
              oldValue: false
              ,oldDisplayValue: false
              ,end: function(p) {
                  var t = Ext.getCmp('modx-resource-tree');
                  if (!t) return;
                  p.d = p.d || p.v;
                  
                  t.removeListener('click',this.handleChangeParent,this);
                  t.on('click',t._handleClick,t);
                  t.disableHref = false;
          
                  MODx.debug('Setting parent to: '+p.v);
                  
                  Ext.getCmp('modx-resource-parent-hidden').setValue(p.v);
                  
                  this.setValue(p.d);
                  this.oldValue = false;
                  
                  Ext.getCmp(this.config.formpanel).fireEvent('fieldChange');
              }
              ,onTriggerClick: function() {
                  if (this.disabled) { return false; }
                  if (this.oldValue) {
                      this.fireEvent('end',{
                          v: this.oldValue
                          ,d: this.oldDisplayValue
                      });
                      return false;
                  }
                  MODx.debug('onTriggerClick');
          
                  var t = Ext.getCmp('modx-resource-tree');
                  if (!t) {
                      MODx.debug('no tree found, trying to activate');
                      var tp = Ext.getCmp('modx-leftbar-tabpanel');
                      if (tp) {
                          tp.on('tabchange',function(tbp,tab) {
                              if (tab.id == 'modx-resource-tree-ct') {
                                  this.disableTreeClick();
                              }
                          },this);
                          tp.activate('modx-resource-tree-ct');
                      } else {
                          MODx.debug('no tabpanel');
                      }
                      return false;
                  }
          
                  this.disableTreeClick();
              }
          
              ,disableTreeClick: function() {
                  MODx.debug('Disabling tree click');
                  t = Ext.getCmp('modx-resource-tree');
                  if (!t) {
                      MODx.debug('No tree found in disableTreeClick!');
                      return false;
                  }
                  this.oldDisplayValue = this.getValue();
                  this.oldValue = Ext.getCmp('modx-resource-parent-hidden').getValue();
          
                  this.setValue(_('resource_parent_select_node'));
          
                  t.expand();
                  t.removeListener('click',t._handleClick);
                  t.on('click',this.handleChangeParent,this);
                  t.disableHref = true;
          
                  return true;}
                  
              ,handleChangeParent: function(node,e) {
                  var t = Ext.getCmp('modx-resource-tree');
                  if (!t) { return false; }
                  t.disableHref = true;
          
                  var id = node.id.split('_'); id = id[1];
                  if (id == MODx.request.id) {
                      MODx.msg.alert('',_('resource_err_own_parent'));            
                      return false;
                  }
          
                  var ctxf = Ext.getCmp('modx-resource-context-key');
                  if (ctxf) {
                      var ctxv = ctxf.getValue();
                      if (node.attributes && node.attributes.ctx != ctxv) {
                          ctxf.setValue(node.attributes.ctx);
                      }
                  }
                  this.fireEvent('end',{
                      v: node.attributes.type != 'modContext' ? id : node.attributes.pk
                      ,d: Ext.util.Format.stripTags(node.text)
                  });
                  e.preventDefault();
                  e.stopEvent();
                  return true;
              }
          });
          Ext.reg('modx-field-parent-change',MODx.ChangeParentField);
          


          And in your CMP:
          //from manager/assets/modext/widgets/resource/modx.panel.resource.js
          {
              xtype: 'modx-field-parent-change'
              ,fieldLabel: _('resource_parent')
              ,name: 'parent-cmb'
              ,id: 'modx-resource-parent'
              ,value: config.record.parent || 0
          }
          
            • 19486
            • 14 Posts
            Hi,

            thanks, will take a look at it.

            Usage would be to pick up the id of the current doc selected in the manager and start the CMP. Giving the id to the CMP action as the action works document related. TV's are not usable in this very specific case...
              • 33968
              • 863 Posts
              If you're already viewing the resource you want to pass the id of, you can simply add this to the handler field when creating your action:
              location.href = 'index.php'+'?a='+MODx.action['youraction']+'&id='+MODx.request.id;
              return false;
              

              Where 'youraction' is the name of the controller you have set up. You could also just hardcode in your action ID but it's not very portable.
                • 19486
                • 14 Posts
                Great solution!!

                This solved it and it's upgradesafe! Thanks for your efforts.