We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25663 MODX Staff
    • 12,272 Posts
    All are bits of code in progress. Nothing to get excited about yet.
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 26903
      • 1,336 Posts
      OK javascript/ajax guys, have a look at the attached pic, its the change template screen of the doc manager, the combo box allows template selection, this is connected to a processor and works OK, the static text field allows the input of doc id’s a la the evo design, with supporting text.

      Question, how do I put a ’submit’ button on this to send the selected template and the text string to a back end processor to actually do the change?

      I’ve had a look through modext and ext2 and have become thoroughly confused, is there an API doc for any of this?

      Can I even do it like this?
        Use MODx, or the cat gets it!
        • 28215
        • 4,149 Posts
        Quote from: shamblett at Jan 23, 2009, 08:23 AM

        OK javascript/ajax guys, have a look at the attached pic, its the change template screen of the doc manager, the combo box allows template selection, this is connected to a processor and works OK, the static text field allows the input of doc id’s a la the evo design, with supporting text.

        Question, how do I put a ’submit’ button on this to send the selected template and the text string to a back end processor to actually do the change?
        That depends on how you’re doing it. There’s a couple of ways:

        1. The page is built out of a MODx.FormPanel and has a ’save’ button at the bottom.
        2. The page uses MODx.ActionButtons and utilizes the MODExt form processing functions.  (preferred)

        Here’s some code for #2, assuming you’re using Smarty, and the page is a modAction hooked to a custom DocManager context. Your file paths, of course, might be different.

        HTML:
        <div id="dm-panel-docmanager"></div>
        
        <script type="text/javascript" src="{$_config.context_url}assets/js/widgets/dm.panel.docmanager.js"></script>
        


        dm.panel.docmanager.js:
        Ext.namespace('DM','DM.config','DM.panel','DM.page');
        DM.config = {
            /* obviously change this to your connector */
        	connector_url: MODx.config.base_url+'assets/components/docmanager/core/processors/connector.php'
        };
        
        Ext.onReady(function() {
            MODx.load({ xtype: 'dm-page-docmanager'}); /* renders panel on domready */
        });
        
        
        /* the _() loads a lexicon string, if you aren't using i18n support
           then simply the 'Text Here' is fine
        */
        
        /* this class loads the stuff into a MODx page, which includes the action buttons (top right fixed CSS buttons) */
        DM.page.DocManager = function(config) {
        	config = config || {};
        	Ext.applyIf(config,{
                formpanel: 'dm-panel-docmanager' /* point to the ID of the FormPanel, so that the action buttons know what form to save */
                ,buttons: [{
                    process: 'save' /* specifies 'action' POST param for processor */
                    ,text: _('save')
                    ,method: 'remote'
                    ,keys: [{ /* allows you to press alt+ctrl+s to save */
                        key: 's'
                        ,alt: true
                        ,ctrl: true
                    }]
                }]
        		,components: [{
                    xtype: 'dm-panel-docmanager' /* xtype specified by Ext.reg */
                    ,renderTo: 'dm-panel-docmanager' /* render the panel into the HTML div */
                }]
        	});	
        	DM.page.DocManager.superclass.constructor.call(this,config);
        };
        Ext.extend(DM.page.DocManager,MODx.Component);
        Ext.reg('dm-page-docmanager',DM.page.DocManager);
        
        
        
        
        DM.panel.DocManager = function(config) {
            config = config || {};
            Ext.applyIf(config,{
                id: 'dm-panel-docmanager'
                ,url: DM.config.connector_url
                ,baseParams: {
                    action: 'save'
                }
                ,defaults: { collapsible: false ,autoHeight: true }
                ,items: [{
                    html: '<h2>'+_('change_template')+'</h2>'
                    ,id: 'dm-panel-header'
                    ,cls: 'modx-page-header' /* gets you the nice header formatting */
                    ,border: false
                },{
                    layout: 'form'
                    ,bodyStyle: 'padding: 1.5em;'
                    ,items: [{
                    	name: 'template'
                    	,fieldLabel: _('template')
                    	,xtype: 'combo-template' /* there's a modx-built combo for templates already */
                    	,id: 'dm-template'
                    },{
                        name: 'resource_ids'
                        ,fieldLable: _('specify_range_resource_ids')
                        ,xtype: 'textfield'
                        ,id: 'dm-resource-ids'
                    },{
                    	html: '<p>'+_('resource_ids_key')+'</p>'
                    	,border: false
                    }]
                }]
                ,listeners: {
                    'setup': {fn:this.setup,scope:this}
                    ,'success': {fn:this.success,scope:this}
                    ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
                }
            });
            DM.panel.DocManager.superclass.constructor.call(this,config);  
        };
        Ext.extend(DM.panel.DocManager,MODx.FormPanel,{
            initialized: false
            ,setup: function() {
                /* do any post-render actions here */
                this.initialized = true;
                this.fireEvent('ready');
            }
            ,beforeSubmit: function(o) {
                /* do any pre-submit actions here */
                Ext.apply(o.form.baseParams,{
                    
                });
            }
            ,success: function(o) {
                /* do any post-success actions here */
            }
        });
        Ext.reg('dm-panel-docmanager',DM.panel.DocManager);
        


        Feel free to ask any questions on that you might have.


        I’ve had a look through modext and ext2 and have become thoroughly confused, is there an API doc for any of this?
        Unfortunately, not yet - the code changes significantly, often. As soon as it’s stable I’ll get something up. For now your best bet is to look at how it’s done on the different manager pages.

        There are Ext docs, however, at:
        http://extjs.com/deploy/dev/docs/
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 26903
          • 1,336 Posts
          Ok thanks, yes it is a smarty template and the page is a modAction hooked to a docmanager context. I’ll try this code, this looks more like what I need, just one more question, the combo-template box presumably needs a URL on it to connect it to its processor to get a list of templates? Is this correct?.
            Use MODx, or the cat gets it!
            • 28215
            • 4,149 Posts
            Quote from: shamblett at Jan 23, 2009, 09:24 AM

            Ok thanks, yes it is a smarty template and the page is a modAction hooked to a docmanager context. I’ll try this code, this looks more like what I need, just one more question, the combo-template box presumably needs a URL on it to connect it to its processor to get a list of templates? Is this correct?.

            Only if you want a custom list - otherwise it will hook into the MODx-provided connector/processor for grabbing the list of templates.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 26903
              • 1,336 Posts
              Of course, I don’t actually want a customised list, just a list of templates so I’m OK here without one. This is gelling quite well now.

              I thought the frontend would be much harder than this as I’ve never written any javascript before, but using the available components greatly simplifies this, it allows you to think at a structural level without worrying to much about the js detail. It just boils down to finding out what’s there and using it. No doubt I’ll still get stuck again at some point!!
                Use MODx, or the cat gets it!
                • 28215
                • 4,149 Posts
                Quote from: shamblett at Jan 23, 2009, 09:33 AM

                I thought the frontend would be much harder than this as I’ve never written any javascript before, but using the available components greatly simplifies this, it allows you to think at a structural level without worrying to much about the js detail. It just boils down to finding out what’s there and using it. No doubt I’ll still get stuck again at some point!!

                Yeah, that was the idea - to provide enough MODExt components that people wouldn’t necessarily have to create their own - but they could if they wanted to. All components, as well, have overwritable config parameters, so you can easily customize or extend each component.

                For example, extending the template combo to point to your connector with the action ’getTemplates’:

                Ext.namespace('DM','DM.combo');
                
                DM.combo.Template = function(config) {
                	config = config || {};
                	Ext.applyIf(config,{
                		url: DM.config.connector_url
                		,baseParams: {
                			action: 'getTemplates'
                		}
                	});
                	DM.combo.Template.superclass.constructor.call(this,config);
                };
                Ext.extend(DM.combo.Template,MODx.combo.Template);
                Ext.reg('dm-combo-template',DM.combo.Template);
                


                And then you could use the xtype ’dm-combo-template’ to use this custom template combo anywhere in your code.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 34127
                  • 135 Posts
                  I just updated to the latest revision and I wanted to say that the new manager looks awesome! I’m definitely liking the non-frames (yay!) and the dashboard definitely seems a little less squished now. tongue Nice work guys!

                  Quote from: shamblett at Jan 23, 2009, 03:29 AM


                  What I have found is that in my original controller code I was doing this :-
                  $modx->smarty->display('changetemplate.tpl')
                  (from the docs and this did work)

                  What I have to do now is :-
                  return $modx->smarty->fetch('changetemplate.tpl');


                  and all is well again.

                  Like the new welcome screen format as well.
                  You’re a lifesaver - my manager pages stopped working too after upgrading and I was afraid I broke something. Thanks for posting that. laugh
                    • 28215
                    • 4,149 Posts
                    Quote from: Ricjustsaid at Jan 23, 2009, 10:17 AM

                    I just updated to the latest revision and I wanted to say that the new manager looks awesome! I’m definitely liking the non-frames (yay!) and the dashboard definitely seems a little less squished now. tongue Nice work guys!

                    Great. Still workin on it, but no-frames is far better and allows us a lot more options.


                    You’re a lifesaver - my manager pages stopped working too after upgrading and I was afraid I broke something. Thanks for posting that. laugh
                    Yeah, the manager actually properly requires returns of code instead of echoes, which is optimal since that completely separates logic from content display. My bad on the lack of notification for it. tongue
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 26903
                      • 1,336 Posts
                      No probs, the SVN log does say the iframes have gone, its just a matter of connecting this to the code, and IMHO this way is better, also I’ve seen no perceptible change in load/display timing for the manager.
                        Use MODx, or the cat gets it!