I am trying work out how I can pop up a modal or open a new window or tab when selecting a button on a form that processes the form and passes to another extension? I can't seem to find any examples of where I could or should implement the trigger to the new window.
My currently working process gets data from a form on the press of a button that calls a subcontroller to prepare the data and then passes to a printing component that handles direct printing to label printers all within the same window. Because multiple components are calling this direct print component I rely on a Back button to take them back to the original component view.
It all works as expected however the end users are getting annoyed as the browser sometimes prompts them to reload the original page. So my thinking, open to alternatives, is to give them a new window/tab that they close and not have to use the Back key.
The button on my form page looks like this;
<button type="button"
class="btn refresh hasTooltip "
title="<?php echo Text::_('COM_INVENTORY_BUTTON_POTLABELS_TITLE'); ?>"
onclick="Joomla.submitbutton('consignments.labelsPots');">
<span class="icon-print" aria-hidden="true"></span>
<?php echo 'Pot Labels'; ?>
</button>
In my subcontroller I have this code to get the data from the Form and prepare it for the printing component and then trigger a plugin to invoke the direct printing extension. The final redirect line never gets executed unless the plugin is removed or disabled.
public function labelsPots()
{
....prepare $data .....
//Invoke plugin to redirect to webPrint extension
$this->dispatcher->trigger('onContentWebprint', array('com_inventory.consignment.potlabels', $data));
$this->setRedirect(Route::_('index.php?option=com_inventory&view=' . $this->view));
}
In the plugin it is fairly straightforward
public function onContentWebprint($context, $payload)
{
$this->app->setUserState("webprint.data.context", $context);
$this->app->setUserState("webprint.data.payload", $payload);
$this->app->redirect(Route::_('index.php?option=com_webprint&task=simple.array'));
}
And from there the webprint component, which I want to display in a new window/tab, is a simple page which allows them to select from a list of printer that are connect and online and chage quantity of labels.
Most of what I have read involves either adding target attribute to the link, e.g.<a href= .... target="_blank">
which I don't have, or putting some JS on the button to open a modal which I don't think allows me to get my data from the current page and process it in the subcontroller first.
I could be approaching this the wrong way but I seem to have a blockage on how to do it the way I think it should be possible.