Added the option to add custom tabs to the edit view of any admin view
This commit is contained in:
@ -541,6 +541,13 @@ class Get
|
||||
*/
|
||||
public $linkedAdminViews = array();
|
||||
|
||||
/**
|
||||
* The custom admin view tabs
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $customTabs = array();
|
||||
|
||||
/**
|
||||
* The Add Ajax Switch
|
||||
*
|
||||
@ -1455,13 +1462,15 @@ class Get
|
||||
'b.id',
|
||||
'c.addconditions',
|
||||
'c.id',
|
||||
'r.addrelations'
|
||||
'r.addrelations',
|
||||
't.tabs'
|
||||
), array(
|
||||
'addfields',
|
||||
'addfields_id',
|
||||
'addconditions',
|
||||
'addconditions_id',
|
||||
'addrelations'
|
||||
'addrelations',
|
||||
'customtabs'
|
||||
)
|
||||
)
|
||||
);
|
||||
@ -1469,6 +1478,7 @@ class Get
|
||||
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields', 'b') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('b.admin_view') . ')');
|
||||
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_conditions', 'c') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('c.admin_view') . ')');
|
||||
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_relations', 'r') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('r.admin_view') . ')');
|
||||
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_custom_tabs', 't') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('t.admin_view') . ')');
|
||||
$query->where($this->db->quoteName('a.id') . ' = ' . (int) $id);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
@ -1533,7 +1543,73 @@ class Get
|
||||
$view->tables = array_values($view->addtables);
|
||||
}
|
||||
unset($view->addtables);
|
||||
// add the tabs
|
||||
|
||||
// set custom tabs
|
||||
$this->customTabs[$name_single] = null;
|
||||
$view->customtabs = (isset($view->customtabs) && ComponentbuilderHelper::checkJson($view->customtabs)) ? json_decode($view->customtabs, true) : null;
|
||||
if (ComponentbuilderHelper::checkArray($view->customtabs))
|
||||
{
|
||||
// setup custom tabs to global data sets
|
||||
$this->customTabs[$name_single] = array_map( function ($tab) use($name_single) {
|
||||
// set the view name
|
||||
$tab['view'] = $name_single;
|
||||
// load the dynamic data
|
||||
$tab['html'] = $this->setDynamicValues($tab['html']);
|
||||
// set the tab name
|
||||
$tab['name'] = (isset($tab['name']) && ComponentbuilderHelper::checkString($tab['name'])) ? $tab['name'] : 'Tab';
|
||||
// set lang
|
||||
$tab['lang'] = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($tab['view'], 'U') . '_' . ComponentbuilderHelper::safeString($tab['name'], 'U');
|
||||
$this->langContent['both'][$tab['lang']] = trim($tab['name']);
|
||||
// set code name
|
||||
$tab['code'] = ComponentbuilderHelper::safeString($tab['name']);
|
||||
// check if the permissions for the tab should be added
|
||||
$_tab = '';
|
||||
if (isset($tab['permission']) && $tab['permission'] == 1)
|
||||
{
|
||||
$_tab = $this->_t(1);
|
||||
}
|
||||
// check if the php of the tab is set, if not load it now
|
||||
if (strpos($tab['html'], 'bootstrap.addTab') === false && strpos($tab['html'], 'bootstrap.endTab') === false)
|
||||
{
|
||||
// add the tab
|
||||
$tmp = PHP_EOL . $_tab . $this->_t(1) . "<?php echo JHtml::_('bootstrap.addTab', '" . $tab['view'] . "Tab', '" . $tab['code'] . "', JText::_('" . $tab['lang'] . "', true)); ?>";
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(2) . '<div class="row-fluid form-horizontal-desktop">';
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(3) . '<div class="span12">';
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(4) . implode(PHP_EOL . $_tab . $this->_t(4), (array) explode(PHP_EOL, trim($tab['html'])));
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(3) . '</div>';
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(2) . '</div>';
|
||||
$tmp .= PHP_EOL . $_tab . $this->_t(1) . "<?php echo JHtml::_('bootstrap.endTab'); ?>";
|
||||
// update html
|
||||
$tab['html'] = $tmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tab['html'] = PHP_EOL . $_tab. $this->_t(1) . implode(PHP_EOL . $_tab. $this->_t(1), (array) explode(PHP_EOL, trim($tab['html'])));
|
||||
}
|
||||
// add the permissions if needed
|
||||
if (isset($tab['permission']) && $tab['permission'] == 1)
|
||||
{
|
||||
$tmp = PHP_EOL . $this->_t(1) . "<?php if (\$this->canDo->get('" . $tab['view'] . "." . $tab['code'] . ".viewtab')) : ?>";
|
||||
$tmp .= $tab['html'];
|
||||
$tmp .= PHP_EOL . $this->_t(1) . "<?php endif; ?>";
|
||||
// update html
|
||||
$tab['html'] = $tmp;
|
||||
// set lang for permissions
|
||||
$tab['lang_permission'] = $tab['lang'] . '_TAB_PERMISSION';
|
||||
$tab['lang_permission_desc'] = $tab['lang'] . '_TAB_PERMISSION_DESC';
|
||||
$tab['lang_permission_title'] = $this->placeholders[$this->hhh . 'Views' . $this->hhh] . ' View ' . $tab['name'] . ' Tab';
|
||||
$this->langContent['both'][$tab['lang_permission']] = $tab['lang_permission_title'];
|
||||
$this->langContent['both'][$tab['lang_permission_desc']] = 'Allow the users in this group to view ' . $tab['name'] . ' Tab of ' . $this->placeholders[$this->hhh . 'views' . $this->hhh];
|
||||
// set the sort key
|
||||
$tab['sortKey'] = ComponentbuilderHelper::safeString($tab['lang_permission_title']);
|
||||
}
|
||||
// return tab
|
||||
return $tab;
|
||||
}, array_values($view->customtabs));
|
||||
}
|
||||
unset($view->customtabs);
|
||||
|
||||
// add the local tabs
|
||||
$view->addtabs = (isset($view->addtabs) && ComponentbuilderHelper::checkJson($view->addtabs)) ? json_decode($view->addtabs, true) : null;
|
||||
if (ComponentbuilderHelper::checkArray($view->addtabs))
|
||||
{
|
||||
|
@ -7259,6 +7259,8 @@ class Interpretation extends Fields
|
||||
}
|
||||
}
|
||||
}
|
||||
// custom tab searching array
|
||||
$searchTabs = array();
|
||||
// start tab set
|
||||
$bucket = array();
|
||||
$leftside = '';
|
||||
@ -7270,12 +7272,16 @@ class Interpretation extends Fields
|
||||
ksort($this->tabCounter[$viewName_single]);
|
||||
foreach ($this->tabCounter[$viewName_single] as $tabNr => $tabName)
|
||||
{
|
||||
// check if we must load a custom tab
|
||||
|
||||
$tabWidth = 12;
|
||||
$lrCounter = 0;
|
||||
// set tab lang
|
||||
$tabLangName = $langView . '_' . ComponentbuilderHelper::safeString($tabName, 'U');
|
||||
// set tab code name
|
||||
$tabCodeName = ComponentbuilderHelper::safeString($tabName);
|
||||
/// set the values to use in search latter
|
||||
$searchTabs[$tabCodeName] = $tabNr;
|
||||
// add to lang array
|
||||
if (!isset($this->langContent[$this->lang][$tabLangName]))
|
||||
{
|
||||
@ -7480,6 +7486,11 @@ class Interpretation extends Fields
|
||||
{
|
||||
$body .= PHP_EOL . PHP_EOL . $this->_t(1) . "<?php echo JHtml::_('bootstrap.startTabSet', '" . $viewName_single . "Tab', array('active' => '" . $tabCodeName . "')); ?>";
|
||||
}
|
||||
// check if custom tab must be added
|
||||
if (($_customTabHTML = $this->addCustomTabs($searchTabs[$tabCodeName], $viewName_single, 1)) !== false)
|
||||
{
|
||||
$body .= $_customTabHTML;
|
||||
}
|
||||
// if this is a linked view set permissions
|
||||
$closeIT = false;
|
||||
if (isset($linkedViewIdentifier) && ComponentbuilderHelper::checkArray($linkedViewIdentifier) && in_array($tabCodeName, $linkedViewIdentifier))
|
||||
@ -7530,10 +7541,15 @@ class Interpretation extends Fields
|
||||
{
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php endif; ?>";
|
||||
}
|
||||
// check if custom tab must be added
|
||||
if (($_customTabHTML = $this->addCustomTabs($searchTabs[$tabCodeName], $viewName_single, 2)) !== false)
|
||||
{
|
||||
$body .= $_customTabHTML;
|
||||
}
|
||||
// set counter
|
||||
$tabCounter++;
|
||||
}
|
||||
// add option to load forms loded in via plugins
|
||||
// add option to load forms loded in via plugins (TODO) we may want to move these tab locations
|
||||
$body .= PHP_EOL . PHP_EOL . $this->_t(1) . "<?php \$this->ignore_fieldsets = array('details','metadata','vdmmetadata','accesscontrol'); ?>";
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php \$this->tab_name = '" . $viewName_single . "Tab'; ?>";
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php echo JLayoutHelper::render('joomla.edit.params', \$this); ?>";
|
||||
@ -7698,6 +7714,11 @@ class Interpretation extends Fields
|
||||
$publishingPer[] = "\$this->canDo->get('" . $core_permission . "')";
|
||||
}
|
||||
}
|
||||
// check if custom tab must be added
|
||||
if (($_customTabHTML = $this->addCustomTabs(15, $viewName_single, 1)) !== false)
|
||||
{
|
||||
$body .= $_customTabHTML;
|
||||
}
|
||||
$body .= PHP_EOL . PHP_EOL . $this->_t(1) . "<?php if (" . implode(' || ', $publishingPer) . ") : ?>";
|
||||
// set the default publishing tab
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php echo JHtml::_('bootstrap.addTab', '" . $viewName_single . "Tab', '" . $tabCodeNameLeft . "', JText:" . ":_('" . $tabLangName . "', true)); ?>";
|
||||
@ -7717,6 +7738,11 @@ class Interpretation extends Fields
|
||||
$body .= PHP_EOL . $this->_t(2) . "</div>";
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php echo JHtml::_('bootstrap.endTab'); ?>";
|
||||
$body .= PHP_EOL . $this->_t(1) . "<?php endif; ?>";
|
||||
// check if custom tab must be added
|
||||
if (($_customTabHTML = $this->addCustomTabs(15, $viewName_single, 2)) !== false)
|
||||
{
|
||||
$body .= $_customTabHTML;
|
||||
}
|
||||
}
|
||||
// make sure we dont load it to a view with the name component
|
||||
if ($viewName_single != 'component')
|
||||
@ -7782,6 +7808,32 @@ class Interpretation extends Fields
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function addCustomTabs($nr, $name_single, $target)
|
||||
{
|
||||
// check if this view is having custom tabs
|
||||
if (isset($this->customTabs[$name_single]) && ComponentbuilderHelper::checkArray($this->customTabs[$name_single]))
|
||||
{
|
||||
$html = array();
|
||||
foreach ($this->customTabs[$name_single] as $customTab)
|
||||
{
|
||||
if (ComponentbuilderHelper::checkArray($customTab) && isset($customTab['html']))
|
||||
{
|
||||
if ($customTab['tab'] == $nr && $customTab['position'] == $target
|
||||
&& isset($customTab['html']) && ComponentbuilderHelper::checkString($customTab['html']))
|
||||
{
|
||||
$html[] = $customTab['html'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// return if found
|
||||
if (ComponentbuilderHelper::checkArray($html))
|
||||
{
|
||||
return PHP_EOL . implode(PHP_EOL, $html);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setFadeInEfect(&$view)
|
||||
{
|
||||
// check if we should load the fade in affect
|
||||
@ -15201,6 +15253,17 @@ function vdm_dkim() {
|
||||
// set view name
|
||||
$nameView = ComponentbuilderHelper::safeString($view['settings']->name_single);
|
||||
$nameViews = ComponentbuilderHelper::safeString($view['settings']->name_list);
|
||||
// add custom tab permissions if found
|
||||
if (isset($this->customTabs[$nameView]) && ComponentbuilderHelper::checkArray($this->customTabs[$nameView]))
|
||||
{
|
||||
foreach ($this->customTabs[$nameView] as $_customTab)
|
||||
{
|
||||
if (isset($_customTab['permission']) && $_customTab['permission'] == 1)
|
||||
{
|
||||
$this->componentGlobal[$_customTab['sortKey']] = $this->_t(2) . '<action name="' . $_customTab['view'] . '.' . $_customTab['code'] . '.viewtab" title="' . $_customTab['lang_permission'] . '" description="' . $_customTab['lang_permission_desc'] . '" />';
|
||||
}
|
||||
}
|
||||
}
|
||||
// add the custom permissions to use the buttons of this view
|
||||
$this->addCustomButtonPermissions($view['settings'], $view['settings']->name_single, $nameView);
|
||||
if ($nameView != 'component')
|
||||
|
Reference in New Issue
Block a user