Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Back/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Back/TfViewToolbarTrait.php

<?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\Router\Route;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;

trait TfViewToolbarTrait
{
    // Button Types: Basic, Confirm, Dropdown, Help, Link, Popup, Separator, Standard
    /*
        core buttons
            divider, preview, jooa11y, help, inlinehelp, back, link, mediaManager, makeDefault
            assign, addNew, publish, unpublish, archive, unarchive, edit, editHtml, editCss, delete, trash
            apply, save, save2new, save2copy, checkin, cancel, preferences, versions, customHtml

        $this->toolbar->basicButton('name', 'text')
            ->icon('icon-home')
            ->buttonClass('btn btn-danger')
            ->listCheck(false)
            ->task('controller.method')
            ->attributes(array('name' => 'value'));

        // confirm button ->message()

        // link ->url($url); ->attributes(['target' => '_blank'])

        // popup ->url($url); ->iframeWidth(640); ->iframeHeight(480); ->title('Popup Title'); ->footer('Footer')
                ->bodyHeight(65); ->modalWidth(80)
    */

    // name, parent, layout, options (array)

    public $icon = 'icon-generic';

    public $title;

    public $toolbar_buttons = [];

    public $toolbar;

    public $dropdown;
    
    public $childbar;

    public $save_group = [];

    // Add the page title and toolbar
    protected function addToolbar()
    {
        $this->toolbar = $this->getDocument()->getToolbar();

        // 01. Title and Icon
        if (!$this->title)
        {
            $this->title = $this->title_prefix . Text::_(strtoupper($this->option) . '_' . strtoupper($this->view_name));
        }
        ToolbarHelper::title($this->title, $this->icon);
        
        // Toolbar Buttons before Actions Dropdown or Save Group
        foreach ($this->toolbar_buttons as $k => $toolbar_button)
        {
            $function = 'add_' . $toolbar_button;
            
            switch($toolbar_button)
            {
                case 'dashboard' :
                case 'back' :
                case 'new' :
                case 'select' :
                case 'batch' :
                case 'apply' :
                case 'save' :
                case 'save2new' :
                case 'save2copy' :
                    $this->$function();
                    unset($this->toolbar_buttons[$k]);
                    break;
            }
        }

         $this->dropdown = $this->toolbar->dropdownButton('status-group')
            ->text('JTOOLBAR_CHANGE_STATUS')
            ->toggleSplit(false)
            ->icon('icon-ellipsis-h')
            ->buttonClass('btn btn-action')
            ->listCheck(false);

        $this->childbar = $this->dropdown->getChildToolbar();

        ToolbarHelper::saveGroup($this->save_group, 'btn-success');

        // Toolbar Buttons Childbar / After Dropdown
        foreach ($this->toolbar_buttons as $k => $toolbar_button)
        {
            $function = 'add_' . $toolbar_button;
            
            switch($toolbar_button)
            {
                case 'publish' :
                case 'trash' :
                case 'delete' :
                case 'empty' :
                case 'truncate' :
                case 'import' :
                case 'export' :
                case 'query' :
                case 'cancel' :
                case 'preview' :
                case 'process' :
                case 'media' :
                case 'default' :
                    $this->$function();
                    unset($this->toolbar_buttons[$k]);
                    break;
            }
        }

        // Child classes to implement for adding more toolbar buttons
        $this->custom_toolbar_buttons();

        // Component Options - Show Only on List View and Dashboard
        if ($this->juser->authorise('core.admin', $this->option) || $this->juser->authorise('core.options', $this->option))
        {
            if ($this->view_type == 'list' || $this->view_type == 'dashboard')
            {
                $this->toolbar->preferences($this->option);
            }
        }

        // Help
        if ($this->help_url)
        {
            // help($ref, $useComponent = false, $url = null, $component = null): HelpButton
            $this->toolbar->help('', false, 'https://joomlafry.com/' . $this->help_url);
        }
    }

    public function add_dashboard()
    {
        $this->toolbar->linkButton('dashboard')
            ->text('COM_TF_DASHBOARD')
            ->url('index.php?option=' . $this->option . '&view=dashboard')
            ->icon('fas fa-th');
    }

    public function add_new()
    {
        $this->toolbar->addNew($this->form_view . '.add');
    }

    public function add_select()
    {
        $this->toolbar->linkButton('select', 'JTOOLBAR_NEW')
            ->url('index.php?option=' . $this->option . '&view=select&layout=default&select_type=' . $this->form_view)
            ->buttonClass('btn btn-success')
            ->icon('icon-new');
    }

    public function add_publish()
    {
        $this->childbar->publish($this->view_name . '.publish')->listCheck(true);

        $this->childbar->unpublish($this->view_name . '.unpublish')->listCheck(true);

        $this->childbar->archive($this->view_name . '.archive')->listCheck(true);
    }

    public function add_trash()
    {
        // Only show if state selected is not trash
        if ($this->filterForm && $this->state->get('filter.published') != -2)
        {
            $this->childbar->trash($this->view_name . '.trash')->listCheck(true);
        }

        // Empty Trash
        if (!$this->isEmptyState && $this->filterForm && $this->state->get('filter.published') == -2)
        {
            $this->toolbar->delete($this->view_name . '.delete', 'JTOOLBAR_DELETE_FROM_TRASH')
                ->message('JGLOBAL_CONFIRM_DELETE')
                ->listCheck(true);
        }
    }

    // Directly delete without trashing
    public function add_delete()
    {
        $this->childbar->delete($this->view_name . '.delete')
            ->text('JTOOLBAR_DELETE')
            ->message('JGLOBAL_CONFIRM_DELETE')
            ->icon('fas fa-trash-alt')
            ->listCheck(true);
    }

    // Truncate table (Checks for records in table before truncate)
    public function add_empty()
    {
        $this->childbar->standardButton('empty')
            ->text('COM_TF_TRUNCATE_TABLE')
            ->task($this->view_name . '.deleteTable')
            ->icon('icon-trash')
            ->listCheck(false);
    }

    // Truncate table without checking
    public function add_truncate()
    {
        $this->childbar->standardButton('truncate')
            ->text('COM_TF_TRUNCATE_TABLE')
            ->task($this->view_name . '.truncateTable')
            ->icon('icon-trash')
            ->listCheck(false);
    }
    
    public function add_import()
    {
        $this->childbar->linkButton('import')
            ->url(Route::_('index.php?option=' . $this->option . '&view=import&type=' . substr($this->option, 4) . '.' . $this->form_view))
            ->text('COM_TF_TOOLBAR_IMPORT')
            ->icon('icon-upload')
            ->listCheck(false);
    }

    public function add_export()
    {
        $this->childbar->linkButton('export')
            ->url(Route::_('index.php?option=' . $this->option . '&view=export&type=' . $this->table_name))
            ->text('COM_TF_TOOLBAR_EXPORT')
            ->icon('icon-download')
            ->listCheck(false);
    }

    public function add_query()
    {
        $this->childbar->linkButton('query')
            ->url(Route::_('index.php?option=' . $this->option . '&view=query&type=' . $this->table_name))
            ->text('COM_TF_TOOLBAR_QUERY')
            ->icon('icon-database')
            ->listCheck(false);
    }

    public function add_back()
    {
        //$this->toolbar->back();
        ToolbarHelper::back();
    }

    public function add_batch()
    {
        /*
        $this->toolbar->popupButton('batch', 'JTOOLBAR_BATCH')
            ->selector('collapseModal')
            ->listCheck(true);
        */

        $this->toolbar->popupButton('batch', 'JTOOLBAR_BATCH')
            ->popupType('inline')
            ->textHeader(Text::_('COM_TF_BATCH_PROCESS'))
            ->url('#joomla-dialog-batch')
            ->modalWidth('800px')
            ->modalHeight('fit-content')
            ->listCheck(true);
    }

    public function add_apply()
    {
        if ($this->layout == 'edit')
        {
            $this->toolbar->apply($this->view_name . '.apply');
        }
    }

    public function add_save()
    {
        if ($this->layout == 'edit')
        {
            if (in_array('save2new', $this->toolbar_buttons) || in_array('save2copy', $this->toolbar_buttons))
            {
                $this->save_group[] = ['save', $this->view_name . '.save'];
            }
            else
            {
                $this->toolbar->save($this->view_name . '.save');
            }
        }
    }

    public function add_save2new()
    {
        if ($this->layout == 'edit')
        {
            //$this->toolbar->save2new($this->view_name . '.save2new');
            $this->save_group[] = ['save2new', $this->view_name . '.save2new'];  
        }
    }

    public function add_save2copy()
    {
        if ($this->layout == 'edit')
        {
            //$this->toolbar->save2copy($this->view_name . '.save2copy');
            $this->save_group[] = ['save2copy', $this->view_name . '.save2copy'];
        }
    }

    public function add_cancel()
    {
        $this->toolbar->cancel($this->view_name . '.cancel', $this->is_new ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
    }

    public function add_preview()
    {
        $url = Route::_('index.php?option=' . $this->option . '&view=' . $this->view_name . '&layout=preview');
        
        $this->toolbar->preview($url);
    }

    public function add_media()
    {
        $input_dir = Factory::getApplication()->input->get('directory', '', 'RAW');
        
        $directory = $input_dir ? $input_dir : 'images';
        
        $this->toolbar->mediaManager($directory)
            ->modalWidth(80)
            ->icon('icon-upload');
    }

    public function add_default()
    {
        $this->toolbar->makeDefault($this->view_name . '.default');
    }

    public function add_process()
    {
        $id = Factory::getApplication()->input->get('id', '');

        $url = 'index.php?option=' . $this->option . '&task=' . $this->view_name . '.process';
        if ($id)
        {
            $url .= '&id=' . $id;
        }
        
        $this->toolbar->linkButton('process')
            ->url(Route::_($url))
            ->text('COM_TF_TOOLBAR_PROCESS')
            ->icon('icon-refresh')
            ->listCheck(false);
    }

    // Placeholder function to add additional toolbar buttons in view file
    public function custom_toolbar_buttons()
    {
        /*
        $this->toolbar->standardButton('download', 'COM_EXAMPLE_DOWNLOAD', 'controller.method')
            ->icon('icon-download')
            ->listCheck(true);

        $this->toolbar->basicButton('name', 'text')
            ->icon('icon-home')
            ->buttonClass('btn btn-danger')
            ->listCheck(false)
            ->task('controller.method')
            ->attributes(array('name' => 'value'));

        $this->toolbar->linkButton('download', 'COM_ADMIN_DOWNLOAD_SYSTEM_INFORMATION_TEXT')
            ->url(Route::_('index.php?option=com_admin&view=sysinfo&format=text&' . Session::getFormToken() . '=1'));
        */
    }
}