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

    I have been playing with the idea of adding an extra tab to MODx.panel.Resource when creating/editing a document. Everything I have tried (and seen from code repos) has achieved this by adding to the existing methods used by MODx.panel.Resource. The issue I have with that is it requires that the existing MODx items be re-added meaning it can only work once and would break or not include additional code trying to do the same thing.

    I still haven't gotten around to spending much time with ExtJS so my approach is warped smiley. It feels hacky so I would appreciate any suggestions on how to add items to existing panels created by MODx.

    Here is my hacky code that will probably make more sense then me:
    Ext.extend(MODx.panel.ExtraTab, MODx.panel.Resource, {
    	initComponent: function() {
    		extraTabExt = this.getExtraFields();
    		existingPanelItems = this.items;
    		
    		/**
    		 * There must be a better way of doing this! Hacky
    		 */
    		tabSize = 0;
    		extraEntry = 2; // Enter after settings/second tab
    		newPanelItems = existingPanelItems;
    		
    		for (i in existingPanelItems[1]['items']) {
    			if(existingPanelItems.hasOwnProperty(i)) {
    				if (i < extraEntry) {
    					newPanelItems[1]['items'][tabSize] = existingPanelItems[1]['items'][tabSize];
    				}
    				else {
    					newPanelItems[1]['items'][(tabSize + 1)] = existingPanelItems[1]['items'][tabSize];
    				}
    				tabSize++;
    			}
    		}
    		
    		// Add extra tab
    		newPanelItems[1]['items'][extraEntry] = extraTabExt;
    		this.items = [newPanelItems];
    		
    		MODx.panel.ExtraTab.superclass.initComponent.call(this);
    	},
    	
    	...
      • 33976 ☆ A M B ☆
      • 571 Posts
      Hey,

      I guess versionx is doing that, you might want to give a look on how Mark did on VersionX repository.

      I guess the tab panel is targeted (Ext.getCmp) then tab.add or tab.insert is used.

      Hope that will lead you a little bit ;-)
        • 3749
        • 24,544 Posts
        FYI, you can also create a new tab and put fields and TVs on it in Form Customization, though I've never tried it.


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 34926
          • 87 Posts
          Cheers Romain, that helped a lot! I can add pretty much anything now in a more efficient way smiley