We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hello

    I got a panel ’Cispeo.home.Panel’, in this panel I have a grid ’Cispeo.grid.Companies’.

    From this grid, via a context menu I call the handler ’manageCompany’ with this code
    manageCompany: function(btn,e){
    	location.href = '?a='+MODx.request.a+'&action=company&id='+this.menu.record.id;
    }
    


    This code send me to another panel ’Cispeo.company.panel’. The URL displayed in my browser is then :
    "localhost/Master/manager/?a=76&action=company&id=1" (where ’&id=1’ is the company’s ID.) This works fine.

    In my panel ’Cispeo.company.panel’ , I display
    • in a layout ’form’ : some static text fields with some company infos,
    • a tabpanel with 4 tabs

    In the first tab of the tabpanel I display a grid ’Cispeo.grid.CompanyProject’ with all the projects for this particular company.
    This works fine too...

    Now I want to create a new project for this particular company.
    For that, I use button in the tbar, calling a window ( ’Cispeo.window.createCompanyProject’), which presents an empty form with the Project fields as usual.

    I would like to "prefill" the owner field with the company’s ID (or at least hide the field but set its value with the company ID),
    but if I know how to display the company ID in the first part of my page I cannot arrive to pass its value in the window, and then to set the field ’owner’...

    I need some help here, and some explanations to understand what I do...

    Thanks in advance
      • 27519
      • 275 Posts
      I’ll be needing that soon as well.

      Found this: http://www.sencha.com/forum/showthread.php?47634&mode=linear

      Otherwise: maybe put the values in JSON format in the request and then use ExtJs.getCmp to access the components you want to prefill with something like:

      xtype: myField
      value = function() {
      var cmp = ExtJs.getCmp(’myField’);
      cmp.setValue(...access JSON...);
      }

      Don’t know yet whether that’ll work...
      No clue how to access that JSON either but maybe worth exploring.

      Good luck!
        MODx Revolution / MAMP / OS X
        • 1778
        • 659 Posts
        Hello

        I’ve read it too wink and tried different ways but can’t find the good one yet (set the value in the ’create.php’, playing with the grid or the window itself, nothing to do I can’t pass the value to the window...)
        Sencha forums, and Sencha sites are not very helpful, and the ModExt part of the doc is not ready yet...

        Hope Shaun or someone else will have an idea on how to achieve this...

        Cheers
          • 7976
          • 36 Posts
          Actual I think I can help although it would be more helpful if you posted your entire JS code. Dunno if you get the variable through a store or that you get it through an AJAXrequest. For now I just post the basics to adjust values:

          With a (dynamic) form
          tbar:[{
          	xtype: "tbbutton",
          	text: "New Article",
          	tooltip: "Blabla tooltip",
          	handler	: function() { 
          		container.findById('your-form-id').getForm().setValues([
          			{id:'content', value:'<p></p>'},
          		]);
          	});
          }]
          

          var container = new MODx.Window({
              items:{
                  id: 'your-form-id',
                  xtype: 'form',
                  items: [{xtype:'textfield',id:'someId'}]
              }
          });
          


          Within the Grid Panel:
          You can use the renderer property in your ColumnModel to output a different value, example:
          {
          		xtype: 'combo',
          		valueField: 'id',
          		displayField: 'title',
          		renderer: function(value, metaData, record, rowIndex, colIndex, store) {
          			//Do your Javscript thing
          			return YOURVALUE; //YOURVALUE will be displayed
          		},
          }
          


          Read more about this property on http://dev.sencha.com/deploy/dev/docs/output/Ext.grid.Column.html#Ext.grid.Column-renderer
            Jack of all Trades and Proud Honda Zoomer owner. Also available on twitter.
            • 1778
            • 659 Posts
            Hello

            @TheWebScientist : thanks for your infos, but that was not my problem... I know how to render properly something in a grid,
            or in a combo-box.

            My problem was to "prefill" a field in window accessed via a context menu on an item in a grid and...

            @skndn60 : I FOUND IT !

            Based on my first post I have this URL


            From this grid, via a context menu I call the handler ’manageCompany’ with this code
            manageCompany: function(btn,e){
            	location.href = '?a='+MODx.request.a+'&action=company&id='+this.menu.record.id;
            }
            


            This code send me to another panel ’Cispeo.company.panel’. The URL displayed in my browser is then :
            "localhost/Master/manager/?a=76&action=company&id=1" (where ’&id=1’ is the company’s ID.) This works fine.

            What I wanted was to "prefill the owner field with the company’s ID (or at least hide the field but set its value with the company ID)."
            So I have not (yet) find a way to display it, but I set and save the good company’s ID (the good owner), so I can create a project from the ’CompanyProjects’ grid (with the projects for this particular company), and no need to choose the owner again... Exactly what I wanted...

            How I did it ? First I extracted the company ID from the URL, then I ’assign’ it as baseParam in my window... I don’t show it, but its value is sent to the processor (create.php), and treated in the $_POST as the other fields...
            I suppose we can do the same or equivalent with datas extracted from other tables if needed...

            To illustrate I post my window code. The create.php is based on the one provided in modExtra...
            Cispeo.window.createCompanyProject = function(config){
            	config = config || {};
                    <!-- extraction of id -->
            	var t = location.search.substring(1).split('&');
            	var f = [];
            	for (var i=0; i<t.length; i++) {
            		var x = t[i].split('=');
            		f[x[0]]=f[1];
            	}
            	
            	var myOwner = x[1];
            	this.owner = myOwner;
            	this.ident = config.ident || 'cpocproject'+Ext.id();
            	
            	Ext.applyIf(config,{
            		title: _('cispeo.project_create'),
            		id: this.ident,
            		owner: this.owner,
            		width: 600,
            		url: Cispeo.config.connector_url,
                            // send owner as param for creation
            		baseParams: {
            			owner:this.owner,
            			action: 'mgr/project/create'
            		},
            		fields: [{
            			name: 'owner',
            			fieldLabel: myOwner // this one was just to be sure... 
            			
            		},{
            			xtype: 'textfield',
            			name: 'name',
            			fieldLabel: _('name')
            		}]
            	});
            	
            	Cispeo.window.createCompanyProject.superclass.constructor.call(this,config);
            };
            Ext.extend(Cispeo.window.createCompanyProject,MODx.Window);
            Ext.reg('cispeo-window-companyproject-create',Cispeo.window.createCompanyProject);
            


            Hope this is of use...
            Cheers
              • 28215
              • 4,149 Posts
              FYI, all $_GET variables are accessible via MODx.request.* in MODExt...so you could use MODx.request.id there.
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 27519
                • 275 Posts
                Ah! Excellent work! I’m right behind you...

                @splittingred: Using request variables or $scriptProperties... same result, different approach?
                  MODx Revolution / MAMP / OS X
                  • 28215
                  • 4,149 Posts
                  It would totally depend on your situation. I would recommend only passing primary keys through request params (such as ID), and then getting the field values through the controller and $scriptProperties, then assigning them to the JS:

                  $obj = $modx->getObject('myObject',$_REQUEST['id']);
                  if (!$obj) return $modx->error->failure('My obj not found!');
                  
                  $modx->regClientStartupHTMLBlock('<script type="text/javascript">
                  Ext.onReady(function() {
                     MODx.load({
                         xtype: 'my-panel-xtype'
                         ,record: '.$modx->toJSON($obj->toArray()).'
                     });
                  }</script>');
                  


                  This passes the fields and values of the obj into the JSON config for the panel. Then you can use ’config.record.fieldName’ to get the values.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 1778
                    • 659 Posts
                    Hello

                    I simplified my window code to use MODx.request.id instead of my extraction script.
                    It works fine.
                    Only thing to note : if the field owner is xtype:’hidden’, then the owner value is not sent to the processor. I use a "style: ’display:none’ " on a statictextfield and it make the trick...

                    I post my new code in hope is of use for someone
                    Cispeo.window.createCompanyProject = function(config){
                    	config = config || {};
                    	this.owner = MODx.request.id;
                    	this.ident = config.ident || 'cpocproject'+Ext.id();
                    	
                    	Ext.applyIf(config,{
                    		title: _('cispeo.project_create'),
                    		id: this.ident,
                    		width: 600,
                    		url: Cispeo.config.connector_url,
                    		baseParams: {
                    			owner:this.owner,
                    			action: 'mgr/project/create'
                    		},
                    		fields: [{
                    			xtype: 'statictextfield', // if I put 'hidden' instead, the owner value is not sent anymore
                    			style: 'display: none;', // I don't want to show an empty line so I set display to none
                    			name: 'owner'
                    		},{
                    			xtype: 'textfield',
                    			name: 'name',
                    			fieldLabel: _('name')
                    		}]
                    	});
                    	
                    	Cispeo.window.createCompanyProject.superclass.constructor.call(this,config);
                    };
                    Ext.extend(Cispeo.window.createCompanyProject,MODx.Window);
                    Ext.reg('cispeo-window-companyproject-create',Cispeo.window.createCompanyProject);
                    


                    Cheers