Reputation: 8675
I'm trying to implement a 'Save, close and print' button on my component toolbar which will save and close the edit form as usual but will also open a printing version of the form in a new tab. Is this possible?
Currently I have a print button on the list view but I want to streamline the user experience and make it more convenient.
Upvotes: 0
Views: 1146
Reputation: 1566
You can do it before the form submit in the edit.php view file
<script type="text/javascript">
Joomla.submitbutton = function(task)
{
if (task == 'object.saveprint' || document.formvalidator.isValid(document.id('attendee-form'))) {
window.open(your_print_url,'_blank');
Joomla.submitform(task, document.getElementById('attendee-form'));
}
else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
}
}
</script>
The only solution I can think off to do it after the save in the controller is to set something in the session of the user. In the list view you can read the value from the session and add a javascript code which opens the view.
In the controller do:
public function save() {
$return = parent::save();
JFactory:getSession()->set('printUrl', JRoute::_('your print url'));
return $return;
}
in the default.php (better to get the url var in the view.html.php) do
$url = JFactory::getSession()->get('printUrl', null);
if ($url !== null) {
JFactory::getDocument()->addScriptDeclaration("window.open(".$url.",'_blank')");
JFactory::getSession()->set('printUrl', null);
}
Hope that helps.
Upvotes: 1