before i forget here some information.
editevent-view, edit.php
here we have to add a modal. ofcourse it would be nice to create a form field but for now a basic link just to test it out.
<a class="flyermodal" title="<?php echo JText::_('DELIVER NEW VENUE'); ?>" href="<?php echo JRoute::_('index.php?option=com_jem&view=editvenue&mode=ajax&tmpl=component'); ?>" rel="{handler: 'iframe', size: {x: 800, y: 500}}">
<span><?php echo JText::_('DELIVER NEW VENUE')?></span>
</a>
in the above we're pointing to the editvenue, but that view doesn't know what to do with it so let's adjust things there too.
editvenue, view.html.php
we're catching the string "mode"
$jinput = JFactory::getApplication()->input;
$this->mode = $jinput->get('mode');
editvenue, edit.php
add a hidden input field to store the mode.
<input type="hidden" name="mode" value="<?php echo $this->mode; ?>" />
and now the tricky parts, when pressing the buttons (save, cancel, save&close) we're going to point to the controller and that one also doesn't know what to do with it so you need to inform him of what to do.
controllers / editvenue.php / cancel
function cancel will be something like
public function cancel($key = 'a_id')
{
$jinput = JFactory::getApplication()->input;
$mode = $jinput->get('mode');
if ($mode == 'ajax')
{
// close the window.
$js = "window.parent.SqueezeBox.close()";
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
return;
}
parent::cancel($key);
// Redirect to the return page.
$this->setRedirect($this->getReturnPage());
}
controllers / editvenue.php / save-apply-etc.....
you have to take a look at the function "save" there are a couple of "redirects" in that function
and we need to add some code before the redirect, this as we don't want the script to redirect but to close.
for example the task "apply",
switch ($task)
{
case 'apply':
// Set the record data in the session.
$recordId = $model->getState($this->context . '.id');
$this->holdEditId($context, $recordId);
$app->setUserState($context . '.data', null);
$model->checkout($recordId);
$jinput = JFactory::getApplication()->input;
$mode = $jinput->get('mode');
$data = $model->getItem($recordId);
if ($mode == 'ajax')
{
$script[] = "window.parent.jSelectVenue_jform_locid('".$data->id."', '".$data->venue."')";
$script[] = "window.parent.SqueezeBox.close()";
// Add to document head
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
return;
}
// Redirect back to the edit screen.
$this->setRedirect(
JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $urlVar), false
)
);
break;
be aware that the code in the postSaveHook function is not being triggered as we are applying a "return" and doing so there won't be a mail sent upon creating a new venue. If you do want to receive a notice then you need to move the dispatcher code to the save function.
notes:
- won't add it myself to Github for a while
- the link in editevent-view should move to a field
- in the above is no security checking, but it would be good to apply it.