Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Back;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
class TfViewForm extends TfView
{
public $view_type = 'form';
// View class for backend forms
protected $form;
protected $item;
protected $state;
// Define in view
public $main_fields = array('title', 'alias');
public $loadData = true;
public $fileUpload = false;
public $fieldsets;
public $first_fieldset;
public $is_new;
public $icon = 'fas fa-edit';
public $action;
public $layout;
public $tmpl;
public $item_id;
public function display($tpl = null)
{
$this->initiate_form();
// Add Toolbar
if ($this->getLayout() !== 'modal')
{
//$this->addToolbar();
}
else
{
$this->addModalToolbar();
}
// Display the template
parent::display($tpl);
}
public function initiate_form()
{
parent::initiate_view();
$this->addTemplatePath(JPATH_LIBRARIES . '/techfry/html/backform');
// Get data from model
$this->form = $this->get('Form');
if ($this->loadData)
{
$this->item = $this->get('Item');
$this->state = $this->get('State');
}
if ($this->getLayout() === 'modalreturn')
{
parent::display($tpl);
return;
}
$this->fieldsets = $this->form->getFieldsets();
$this->first_fieldset = array_keys($this->fieldsets)[0];
}
protected function addToolbar()
{
Factory::getApplication()->getInput()->set('hidemainmenu', true);
$this->is_new = ($this->loadData) ? ($this->item->id == 0) : 0;
parent::addToolbar();
//$this->toolbar->inlinehelp();
}
protected function addModalToolbar()
{
$toolbar = $this->getDocument()->getToolbar();
$toolbar->apply($this->view_name . '.apply');
$toolbar->save($this->view_name . '.save');
$toolbar->cancel($this->view_name . '.cancel');
}
// Fucntion to start displaying list layout
public function start_form_layout()
{
$wa = $this->document->getWebAssetManager();
$wa->useScript('keepalive')
->useScript('form.validate');
$input = Factory::getApplication()->getInput();
// In case of modal
$isModal = $input->get('layout') == 'modal';
$this->layout = $isModal ? 'modal' : 'edit';
$tmpl = $input->get('tmpl');
$this->tmpl = $tmpl ? '&tmpl=' . $tmpl : '';
$this->item_id = $this->loadData ? (int) $this->item->id : 0;
$this->get_action();
echo '<form action="' . Route::_($this->action) . '" method="post"';
if ($this->fileUpload)
{
echo ' enctype="multipart/form-data"';
}
echo ' name="adminForm" id="item-form" class="form-validate">';
// Title and Alias
if (!empty($this->main_fields))
{
echo '<div class="row title-alias form-vertical mb-3">';
foreach ($this->main_fields as $main_field)
{
echo '<div class="col-12 col-md-6">';
echo $this->form->renderField($main_field);
echo '</div>';
}
echo '</div>';
}
echo '<div class="main-card">';
echo HTMLHelper::_('uitab.startTabSet', 'myTab', array('active' => $this->first_fieldset));
}
// Function to finisy displaying list layout
public function end_form_layout()
{
echo HTMLHelper::_('uitab.endTabSet');
echo '<input type="hidden" name="task" value="' . $this->view_name . '.edit" />';
echo HTMLHelper::_('form.token');
echo '</div>';
echo '</form>';
}
// Add tab in edit layout with form fieldset
public function add_tab_form($name)
{
// $name - fieldset name
echo HTMLHelper::_('uitab.addTab', 'myTab', $name, Text::_($this->fieldsets[$name]->label));
$this->render_fieldset($this->fieldsets[$name]);
echo HTMLHelper::_('uitab.endTab');
}
// Add tab in edit layout with sub template file
public function add_tab_tmpl($name, $text)
{
echo HTMLHelper::_('uitab.addTab', 'myTab', $name, Text::_($text));
echo $this->loadTemplate($name);
echo HTMLHelper::_('uitab.endTab');
}
// Add tab in edit layout with two fieldsets
public function add_tab_forms($names, $text, $cols = array(9, 3))
{
echo HTMLHelper::_('uitab.addTab', 'myTab', $names[0], Text::_($text));
echo '<div class="row">';
foreach ($names as $key => $name)
{
echo '<div class="col-lg-' . $cols[$key] . '">';
$this->render_fieldset($this->fieldsets[$name]);
echo '</div>';
}
echo '</div>';
echo HTMLHelper::_('uitab.endTab');
}
// Function to add all form fieldsets
public function add_fieldsets()
{
foreach ($this->fieldsets as $name => $fieldSet)
{
echo HTMLHelper::_('uitab.addTab', 'myTab', $name, Text::_($fieldSet->label));
$this->render_fieldset($fieldSet);
echo HTMLHelper::_('uitab.endTab');
}
}
// Renders fieldset legend (label), description and all fields
public function render_fieldset($fieldset)
{
if (isset($fieldset->label) && !empty($fieldset->label))
{
echo '<fieldset class="options-form">';
echo '<legend>' . Text::_($fieldset->label) . '</legend>';
}
if (isset($fieldset->description) && !empty($fieldset->description))
{
echo '<div class="alert alert-info">';
echo '<span class="icon-info-circle" aria-hidden="true"></span> ' . Text::_($fieldset->description);
echo '</div>';
}
echo '<div class="form-horizontal">';
echo $this->form->renderFieldset($fieldset->name);
echo '</div>';
if (isset($fieldset->label) && !empty($fieldset->label))
{
echo '</fieldset>';
}
}
public function get_action()
{
$this->action = 'index.php?option=' . $this->option . '&layout=' . $this->layout . $this->tmpl . '&id=' . $this->item_id;
}
}