We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    I have a some questions re the MODx.Panel class:

    1. Am I correct to understand that this is an HTML canvas, e.g. has some form of an innerHtml attribute?

    2. Would it be possible to set its contents from a variable stored in the session, that variable holding a chunk of HTML? If so, are there any conventions within MODx to write/read the session?

    3. Can I use the "html" config attribute of MODx.Panel to set the contents to a HTML chunk stored in the session? If so, what would be the proper syntax?

    I’ve been wrestling with this for a couple of days now without much result...

    Thanks!
      MODx Revolution / MAMP / OS X
      • 28215
      • 4,149 Posts
      Quote from: skndn60 at Oct 10, 2010, 07:57 PM

      1. Am I correct to understand that this is an HTML canvas, e.g. has some form of an innerHtml attribute?
      It extends Ext.Panel: http://dev.sencha.com/deploy/dev/docs/?class=Ext.Panel

      All it adds is a ’modx-panel’ CSS class to the Ext Panel.

      MODx.FormPanel does a bit more than Ext.FormPanel, but you asked about MODx.Panel, so we’ll stay there.


      2. Would it be possible to set its contents from a variable stored in the session, that variable holding a chunk of HTML? If so, are there any conventions within MODx to write/read the session?
      Sure - do you mean PHP session, or JS session?
      - If JS Session, look into Ext.state.Manager: http://dev.sencha.com/deploy/dev/docs/?class=Ext.state.Manager
      - If PHP Session, use $_SESSION array to store and fetch from. Then assign it to a JS variable before registering your JS scripts.


      3. Can I use the "html" config attribute of MODx.Panel to set the contents to a HTML chunk stored in the session? If so, what would be the proper syntax?
      Sure, I wouldn’t see why not. I think Ext.Panel takes either a string of HTML or an Ext.DomHelper spec in the html config attr.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 27519
        • 275 Posts
        Thanks!


        Sure - do you mean PHP session, or JS session?
        - If JS Session, look into Ext.state.Manager: http://dev.sencha.com/deploy/dev/docs/?class=Ext.state.Manager
        - If PHP Session, use $_SESSION array to store and fetch from.

        I meant PHP session. If I understand correctly the Ext JS session is there for keeping track of the state of UI elements like trees etc. whether they’re expanded, collapsed etc.


        Then assign it to a JS variable before registering your JS scripts.

        That’s the bit I’m struggling with. How do I get the contents of a PHP session variable in the config param of an ExtJs widget. To be more specific. Let’s say I have a variable called $content in the PHP session and have a MODx.Panel. What do I specify at the html config property of the MODx.Panel so that the contents of $content are displayed in that panel?

        I tried about everything I can think of, but it won’t work for me... huh

          MODx Revolution / MAMP / OS X
          • 26903
          • 1,336 Posts
          Have a look at /core/model/modx/processors/system/config.js.php or /connectors/lang.js.php for some ideas.
            Use MODx, or the cat gets it!
            • 28215
            • 4,149 Posts

            That’s the bit I’m struggling with. How do I get the contents of a PHP session variable in the config param of an ExtJs widget. To be more specific. Let’s say I have a variable called $content in the PHP session and have a MODx.Panel. What do I specify at the html config property of the MODx.Panel so that the contents of $content are displayed in that panel?

            Well, it depends on how you’re creating your MODx.Panel...I’d need to see the code to help you with it.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 1778
              • 659 Posts
              I’ll probably be needing that soon as well... You’d be kind to keep me informed on how you achieve this...
              Thanks in advance
              Cheers

                • 27519
                • 275 Posts

                Well, it depends on how you’re creating your MODx.Panel...I’d need to see the code to help you with it.

                Here’s the code for the panel. The idea is that the sub-panels ("month1", "month2" etc) will each display an HTML chunk (a month from a calendar). My plan is that these four chunks will be posted in the $_SESSION array by a PHP snippet and picked up via the html config property of the sub-panels. The PHP snippet should be triggered when a selection is made from the combo "tariffs-combo-cottages".

                Hope this makes sense...

                Tariffs.panel.Calendar = function(config) {
                    config = config || {};
                    Ext.applyIf(config,{
                        id: 'tariffs-panel-calendar'
                        ,url: Tariffs.config.connector_url
                        ,height: 400
                		,layout:'table'
                		,defaults: {
                			// applied to each contained panel
                			bodyStyle:'padding:20px'
                		}
                		,layoutConfig: {
                			// The total column count must be specified here
                			columns: 4
                		},
                		items: [{
                			colspan: 4
                			,border: false
                			,items: [{
                				xtype: 'tariffs-combo-cottages'
                				,fieldLabel: 'Cottage'
                				,emptyText: 'Select a cottage to view calendar...'
                				,allowBlank: true
                				,name: 'cottage'
                			}]
                		},{
                			border: false
                			,items: [{
                				xtype: 'tariffs-panel-month'
                				,name: 'month1'
                				,id: 'month1'
                				,title: 'month1'
                				,width:200
                				,height: 200
                			}]
                		},{
                			border: false
                			,items: [{
                				xtype: 'tariffs-panel-month'
                				,name: 'month2'
                				,id: 'month2'
                				,width:200
                				,height: 200
                			}]
                		},{
                			border: false
                			,items: [{
                				xtype: 'tariffs-panel-month'
                				,name: 'month3'
                				,id: 'month3'
                				,width:200
                				,height: 200
                			}]
                		},{
                			border: false
                			,items: [{
                				xtype: 'tariffs-panel-month'
                				,name: 'month4'
                				,id: 'month4'
                				,width:200
                				,height: 200
                			}]
                		}]
                        ,tbar: [{
                            text: 'Next Month'
                            ,handler: this.refresh
                            ,scope: this
                        },'-',{
                            text: 'Previous Month'
                            ,handler: this.refresh
                            ,scope: this
                		},'->',{
                            xtype: 'numberfield'
                            ,name: 'year'
                            ,id: 'calendar-year'
                            ,emptyText: 'Enter year...'
                        },{
                            xtype: 'button'
                            ,id: 'calendar-create-year'
                            ,text: _('tariffs.calendar_create_year')
                            ,listeners: {
                                'click': {fn: this.createCalendarYear, scope: this}
                            }
                        },{
                            xtype: 'button'
                            ,id: 'tariffs-cleanup-year'
                            ,text: _('tariffs.calendar_cleanup')
                            ,listeners: {
                                'click': {fn: this.cleanupCalendar, scope: this}
                            }
                        }]
                    });
                    Tariffs.panel.Calendar.superclass.constructor.call(this,config);
                    this.config = config;
                };
                


                Thanks to all for your help & suggestions.

                @Anso: I’ll let you know once this nut is cracked... grin
                  MODx Revolution / MAMP / OS X
                  • 28215
                  • 4,149 Posts
                  What does Tariffs.panel.Calendar extend? Does it extend MODx.Panel? If so, I don’t see the extend statement there. It should be after your Tariffs.panel.Calendar method definition:

                  Ext.extend(Tariffs.panel.Calendar,MODx.Panel);
                  Ext.reg('tarriffs-panel-calendar',Tariffs.panel.Calendar);
                  


                  Also, if it extends MODx.Panel, the line "this.config = config" after the constructor call is unnecessary.

                  Furthermore, how are you instantiating this Panel?
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 27519
                    • 275 Posts
                    There’s a second part which implements the functions that are referred by the buttons in the toolbar:

                    Ext.extend(Tariffs.panel.Calendar,MODx.Panel,{
                    	windows: {}
                    
                    	,validateYear: function() {
                    		var field = Ext.getCmp('calendar-year');
                    		var eYear = field.getValue();
                    		var cDate = new Date();
                    		var cYear = cDate.getFullYear();
                    		if (eYear < cYear) {
                    			// error: cannot enter year smaller than current
                    			return false;
                    		}
                    		if (eYear > cYear + 2) {
                    			// error: cannot enter year past 3 years in future
                    			return false;
                    		}
                    		return true;
                    	}
                    
                    	,createCalendarYear: function(id) {
                    		var field = Ext.getCmp('calendar-year');
                    		var year = field.getValue();
                    		if (this.validateYear() ) {
                    			MODx.msg.confirm({
                    				title: _('tariffs.calendar_create_confirm')
                    				,text: _('tariffs.calendar_create_confirm_message')
                    				,url: this.config.url
                    				,params: {
                    					action: 'mgr/calendar/createyear'
                    					,id: year
                    				}
                    				,listeners: {
                    					'success': {fn:function() { 
                    						this.refresh();
                    						field.setValue("");},scope:this}
                    				}
                    			});
                    		} else {
                    			Ext.Msg.alert(_('tariffs.invalid_calendar_year'), _('tariffs.invalid_calendar_year_message'));
                    			field.setValue("");
                    		}
                    		alert(this.config.url);
                    	}
                    	
                    	,cleanupCalendar: function(id) {
                              //todo
                    	}
                    
                    });
                    
                    Ext.reg('tariffs-panel-calendar',Tariffs.panel.Calendar);
                    


                    I did not post that as I thought you would only need the first part. But that’s the complete panel definition.

                    Instantiation is done on the (home) panel from which this panel is called (a tabbed panel):
                    {
                       title: 'Calendar'
                         ,items: [{
                         html: '<p>'+'Browse availability calendar for your properties. Select a property from the dropdown list and browse the months using the buttons in the toolbar.'+'</p><br />'
                         ,border: false
                       },{
                          xtype: 'tariffs-panel-calendar'
                          ,preventRender: true
                     }
                    

                      MODx Revolution / MAMP / OS X
                      • 28215
                      • 4,149 Posts
                      So whatever you pass into this:

                      {
                            xtype: 'tariffs-panel-calendar'
                            ,preventRender: true
                       }
                      


                      Is subsequently passed into the "config" object parameter in the Tarriffs.panel.Calendar constructor. For example:

                      {
                            xtype: 'tariffs-panel-calendar'
                            ,preventRender: true
                            ,job: 123
                      }
                      


                      Would have "config.job" set to a value of 123. This means in your panel you can use that value.
                        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com