Fixed gh-338 to insure that the custom buttons work on the site view page

This commit is contained in:
Llewellyn van der Merwe 2018-09-11 22:08:58 +02:00
parent 7fcc93aa5b
commit 5962b557c8
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
9 changed files with 65 additions and 24 deletions

View File

@ -39,7 +39,7 @@ class ###Component###View###SViews### extends JViewLegacy
protected function _prepareDocument()
{###SITE_LIBRARIES_LOADER### ###SITE_UIKIT_LOADER### ###SITE_GOOGLECHART_LOADER### ###SITE_FOOTABLE_LOADER### ###SITE_DOCUMENT_METADATA### ###SITE_DOCUMENT_CUSTOM_PHP###
// add the document default css file
$this->document->addStyleSheet(JURI::root(true) .'/components/com_###component###/assets/css/###sview###.css', (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css');###SITE_DOCUMENT_CUSTOM_CSS### ###SITE_DOCUMENT_CUSTOM_JS###
$this->document->addStyleSheet(JURI::root(true) .'/components/com_###component###/assets/css/###sview###.css', (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css');###SITE_DOCUMENT_CUSTOM_CSS### ###SITE_DOCUMENT_CUSTOM_JS### ###SITE_JAVASCRIPT_FOR_BUTTONS###
}
/**

View File

@ -39,7 +39,7 @@ class ###Component###View###SView### extends JViewLegacy
protected function _prepareDocument()
{###SITE_LIBRARIES_LOADER### ###SITE_UIKIT_LOADER### ###SITE_GOOGLECHART_LOADER### ###SITE_FOOTABLE_LOADER### ###SITE_DOCUMENT_METADATA### ###SITE_DOCUMENT_CUSTOM_PHP###
// add the document default css file
$this->document->addStyleSheet(JURI::root(true) .'/components/com_###component###/assets/css/###sview###.css', (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css');###SITE_DOCUMENT_CUSTOM_CSS### ###SITE_DOCUMENT_CUSTOM_JS###
$this->document->addStyleSheet(JURI::root(true) .'/components/com_###component###/assets/css/###sview###.css', (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css');###SITE_DOCUMENT_CUSTOM_CSS### ###SITE_DOCUMENT_CUSTOM_JS### ###SITE_JAVASCRIPT_FOR_BUTTONS###
}
/**

View File

@ -18,4 +18,4 @@ defined('_JEXEC') or die('Restricted access');
defined('_JEXEC') or die('Restricted access');###LICENSE_LOCKED_DEFINED### ###SITE_CODE_BODY###
?>
###SITE_TOP_BUTTON### ###SITE_BODY### ###SITE_BOTTOM_BUTTON###
###SITE_TOP_FORM### ###SITE_TOP_BUTTON### ###SITE_BODY### ###SITE_BOTTOM_BUTTON### ###SITE_BOTTOM_FORM###

View File

@ -18,4 +18,4 @@ defined('_JEXEC') or die('Restricted access');
defined('_JEXEC') or die('Restricted access');###LICENSE_LOCKED_DEFINED### ###SITE_CODE_BODY###
?>
###SITE_TOP_BUTTON### ###SITE_BODY### ###SITE_BOTTOM_BUTTON###
###SITE_TOP_FORM### ###SITE_TOP_BUTTON### ###SITE_BODY### ###SITE_BOTTOM_BUTTON### ###SITE_BOTTOM_FORM###

View File

@ -144,6 +144,13 @@ class Interpretation extends Fields
*/
public $customAdminAdded = array();
/**
* Switch to add form to site views
*
* @var array
*/
public $addSiteForm = array();
/**
* The extensions params
*
@ -3307,16 +3314,12 @@ class Interpretation extends Fields
// set custom css file VIEWCSS
$this->fileContentDynamic[$view['settings']->code][$this->hhh . $TARGET . '_VIEWCSS' . $this->hhh] = $this->setCustomCSS($view);
// incase no buttons are found
$this->fileContentDynamic[$view['settings']->code][$this->hhh . 'SITE_JAVASCRIPT_FOR_BUTTONS' . $this->hhh] = '';
// set the custom buttons CUSTOM_BUTTONS
$this->fileContentDynamic[$view['settings']->code][$this->hhh . $TARGET . '_CUSTOM_BUTTONS' . $this->hhh] = $this->setCustomButtons($view);
// only set the custom get form method if site target
if ('site' === $this->target)
{
// set the custom get form method SITE_CUSTOM_GET_FORM_METHOD
$this->fileContentDynamic[$view['settings']->code][$this->hhh . 'SITE_CUSTOM_GET_FORM_METHOD' . $this->hhh] = $this->setCustomGetForm($view);
}
// see if we should add get modules to the view.html
$this->fileContentDynamic[$view['settings']->code][$this->hhh . $TARGET . '_GET_MODULE' . $this->hhh] = $this->setGetModules($view, $TARGET);
@ -3400,11 +3403,6 @@ class Interpretation extends Fields
return '';
}
public function setCustomGetForm(&$view)
{
return '';
}
public function setDocumentCustomPHP(&$view)
{
if ($view['settings']->add_php_document == 1)
@ -3498,9 +3496,9 @@ class Interpretation extends Fields
if (3 !== $type && ($custom_button['target'] != 2 || $this->target === 'site'))
{
// add cpanel button TODO does not work well on site with permissions
if ($custom_button['target'] == 2)
if ($custom_button['target'] == 2 || $this->target === 'site')
{
$buttons[] = $this->_t(1) . $tab . $this->_t(1) . "if (\$this->user->authorise('" . $viewName . "." . $keyCode . "'))";
$buttons[] = $this->_t(1) . $tab . $this->_t(1) . "if (\$this->user->authorise('" . $viewName . "." . $keyCode . "', 'com_" . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . "'))";
}
else
{
@ -3580,12 +3578,32 @@ class Interpretation extends Fields
// return buttons if they were build
if (ComponentbuilderHelper::checkArray($buttons))
{
// only for site views
if ('site' === $this->target)
{
// set the custom get form method SITE_JAVASCRIPT_FOR_BUTTONS
$this->fileContentDynamic[$view['settings']->code][$this->hhh . 'SITE_JAVASCRIPT_FOR_BUTTONS' . $this->hhh] = $this->setJavaScriptForButtons();
// insure the form is added
$this->addSiteForm[$view['settings']->code] = true;
}
return PHP_EOL . implode(PHP_EOL, $buttons);
}
}
return '';
}
public function setJavaScriptForButtons()
{
// add behavior.framework to insure Joomla function is on the page
$script = array();
$script[] = $this->_t(2) . "//" . $this->setLine(__LINE__) . " Add the needed Javascript to insure that the buttons work.";
$script[] = $this->_t(2) . "JHtml::_('behavior.framework', true);";
$script[] = $this->_t(2) . "\$this->document->addScriptDeclaration(\"Joomla.submitbutton = function(task){if (task == ''){ return false; } else { Joomla.submitform(task); return true; }}\");";
// return the script
return PHP_EOL . implode(PHP_EOL, $script);
}
public function setFunctionOnlyButtons($viewName_list)
{
// return buttons if they were build
@ -4216,7 +4234,6 @@ class Interpretation extends Fields
}
$body[] = $this->setPlaceholders($view['settings']->default, $this->placeholders);
$body[] = PHP_EOL . '<?php if (isset($this->items) && isset($this->pagination) && isset($this->pagination->pagesTotal) && $this->pagination->pagesTotal > 1): ?>';
$body[] = '<form name="adminForm" method="post">';
$body[] = $this->_t(1) . '<div class="pagination">';
$body[] = $this->_t(2) . '<?php if ($this->params->def(\'show_pagination_results\', 1)) : ?>';
@ -4231,9 +4248,10 @@ class Interpretation extends Fields
$body[] = $this->_t(2) . '<?php endif; ?>';
$body[] = $this->_t(2) . '<?php echo $this->pagination->getPagesLinks(); ?>';
$body[] = $this->_t(1) . '</div>';
$body[] = '</form>';
$body[] = '<?php endif; ?>';
// insure the form is added
$this->addSiteForm[$view['settings']->code] = true;
// return the body
return implode(PHP_EOL, $body);
}
else
@ -4244,6 +4262,25 @@ class Interpretation extends Fields
return '';
}
public function setCustomViewForm(&$view, $type)
{
if (isset($this->addSiteForm[$view]) && $this->addSiteForm[$view])
{
switch($type)
{
case 1:
// top
return '<form action="<?php echo JRoute::_(\'index.php?option=com_' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '\'); ?>" method="post" name="adminForm" id="adminForm">' . PHP_EOL;
break;
case 2:
// bottom
return PHP_EOL . '<input type="hidden" name="task" value="" />' . PHP_EOL . "<?php echo JHtml::_('form.token'); ?>" . PHP_EOL . '</form>';
break;
}
}
return '';
}
public function setCustomViewSubmitButtonScript(&$view)
{
if (ComponentbuilderHelper::checkString($view['settings']->default))

View File

@ -901,6 +901,10 @@ class Infusion extends Interpretation
// setup the templates
$this->setCustomViewTemplateBody($view);
// set the site form if needed
$this->fileContentDynamic[$view['settings']->code][$this->hhh . 'SITE_TOP_FORM' . $this->hhh] = $this->setCustomViewForm($view['settings']->code, 1);
$this->fileContentDynamic[$view['settings']->code][$this->hhh . 'SITE_BOTTOM_FORM' . $this->hhh] = $this->setCustomViewForm($view['settings']->code, 2);
}
// setup the layouts
$this->setCustomViewLayouts();

View File

@ -222,5 +222,5 @@ class ComponentbuilderModelApi extends JModelItem
// set that the component was not found
$this->messages[] = JText::_('COM_COMPONENTBUILDER_COMPONENT_WAS_NOT_FOUND');
return false;
}
} ###SITE_CUSTOM_GET_FORM_METHOD###
}