Stuart Steedman
Stuart Steedman

Reputation: 146

How do I implement a custom toolbar button in Joomla 2.5?

I have a Joomla 2.5 Component I'm building.

I'd like, in the Edit (single) View of the Component (called "Article"), to have a new custom JToolbar button, "Add New Menu Item".

When clicked, this should open up a lightbox of the Edit view of another View in the same component (called "Menu Item"), allowing the user to add a menu item without leaving the form he's currently in.

As it stands, I have put in

JToolBarHelper::custom('ussdarticle.addussdmenu', '', '', 'Add Menu Item', false);

And attempted to put the addussdmenu function in the controller, but when the button is clicked, it just directs to the List View without the function being called.

Really appreciate the assistance, I'm still coming to terms with Joomla's MVC (and MVC in general to be honest.)

Upvotes: 0

Views: 1292

Answers (1)

Irfan
Irfan

Reputation: 7059

Your task ussdarticle.addussdmenu will call addussdmenu method of ussdarticle controller.

Also check - How to send the task variable in Joomla

If you want to open popup using custom button.You can use this code in your layout-

<?php JHTML::_('behavior.modal');?>
<script type="text/javascript">
    Joomla.submitbutton = function(task)
    {
        if((task == 'ussdarticle.addussdmenu')){        
            var url = "<?php echo JURI::base()?>index.php?option=com_mycomponent&task="+task;
            SqueezeBox.loadModal(url,"iframe",820,400);
        } else {
            Joomla.submitform(task, document.getElementById('adminForm'));
        }
    }
    SqueezeBox.loadModal = function(modalUrl,handler,x,y) {
        this.presets.size.x = 1024;
        this.initialize();      
        var options = {handler: 'iframe', size: {x: 1000, y: 550}, onClose: function() {}};      
        this.setOptions(this.presets, options);
        this.assignOptions();
        this.setContent(handler,modalUrl);
    };
</script>

Upvotes: 2

Related Questions