Skip to content

Commit

Permalink
[4] Empty State for Banner clients and tracks (#33381)
Browse files Browse the repository at this point in the history
* Empty State for Banner clients and tracks

* Remove formURL

Co-authored-by: Quy <quy@fluxbb.org>
  • Loading branch information
Phil E. Taylor and Quy authored Apr 30, 2021
1 parent 30aa741 commit 4e930a7
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Banners\Administrator\Model\ClientsModel;

/**
* View class for a list of clients.
Expand Down Expand Up @@ -69,6 +70,14 @@ class HtmlView extends BaseHtmlView
*/
protected $state;

/**
* Is this view an Empty State
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
private $isEmptyState = false;

/**
* Display the view
*
Expand All @@ -90,6 +99,11 @@ public function display($tpl = null): void
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

if (!count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}

// Check for errors.
if (count($errors = $this->get('Errors')))
{
Expand Down Expand Up @@ -122,7 +136,7 @@ protected function addToolbar(): void
$toolbar->addNew('client.add');
}

if ($canDo->get('core.edit.state') || $canDo->get('core.admin'))
if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $canDo->get('core.admin')))
{
$dropdown = $toolbar->dropdownButton('status-group')
->text('JTOOLBAR_CHANGE_STATUS')
Expand Down
47 changes: 31 additions & 16 deletions administrator/components/com_banners/src/View/Tracks/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Joomla\CMS\Form\Form;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Object\CMSObject;
Expand Down Expand Up @@ -72,6 +71,14 @@ class HtmlView extends BaseHtmlView
*/
protected $state;

/**
* Is this view an Empty State
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
private $isEmptyState = false;

/**
* Display the view
*
Expand All @@ -92,8 +99,13 @@ public function display($tpl = null): void
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}

// Check for errors.
if (count($errors = $this->get('Errors')))
if (\count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
Expand All @@ -118,20 +130,23 @@ protected function addToolbar(): void

$bar = Toolbar::getInstance('toolbar');

$bar->popupButton()
->url(Route::_('index.php?option=com_banners&view=download&tmpl=component'))
->text('JTOOLBAR_EXPORT')
->selector('downloadModal')
->icon('icon-download')
->footer('<button class="btn btn-secondary" data-bs-dismiss="modal" type="button"'
. ' onclick="window.parent.Joomla.Modal.getCurrent().close();">'
. Text::_('COM_BANNERS_CANCEL') . '</button>'
. '<button class="btn btn-success" type="button"'
. ' onclick="Joomla.iframeButtonClick({iframeSelector: \'#downloadModal\', buttonSelector: \'#exportBtn\'})">'
. Text::_('COM_BANNERS_TRACKS_EXPORT') . '</button>'
);

if ($canDo->get('core.delete'))
if (!$this->isEmptyState)
{
$bar->popupButton()
->url(Route::_('index.php?option=com_banners&view=download&tmpl=component'))
->text('JTOOLBAR_EXPORT')
->selector('downloadModal')
->icon('icon-download')
->footer('<button class="btn btn-secondary" data-bs-dismiss="modal" type="button"'
. ' onclick="window.parent.Joomla.Modal.getCurrent().close();">'
. Text::_('COM_BANNERS_CANCEL') . '</button>'
. '<button class="btn btn-success" type="button"'
. ' onclick="Joomla.iframeButtonClick({iframeSelector: \'#downloadModal\', buttonSelector: \'#exportBtn\'})">'
. Text::_('COM_BANNERS_TRACKS_EXPORT') . '</button>'
);
}

if (!$this->isEmptyState && $canDo->get('core.delete'))
{
$bar->appendButton('Confirm', 'COM_BANNERS_DELETE_MSG', 'delete', 'COM_BANNERS_TRACKS_DELETE', 'tracks.delete', false);
}
Expand Down
27 changes: 27 additions & 0 deletions administrator/components/com_banners/tmpl/clients/emptystate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_banners
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Layout\LayoutHelper;

$displayData = [
'textPrefix' => 'COM_BANNERS_CLIENT',
'formURL' => 'index.php?option=com_banners&view=clients',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help40:Banners:_Clients',
'icon' => 'icon-bookmark banners',
];

if (count(Factory::getApplication()->getIdentity()->getAuthorisedCategories('com_banners', 'core.create')) > 0)
{
$displayData['createURL'] = 'index.php?option=com_banners&task=client.add';
}

echo LayoutHelper::render('joomla.content.emptystate', $displayData);
20 changes: 20 additions & 0 deletions administrator/components/com_banners/tmpl/tracks/emptystate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_banners
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Layout\LayoutHelper;

$displayData = [
'textPrefix' => 'COM_BANNERS_TRACKS',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Help40:Banners:_Tracks',
'icon' => 'icon-bookmark banners',
];

echo LayoutHelper::render('joomla.content.emptystate', $displayData);
5 changes: 5 additions & 0 deletions administrator/language/en-GB/com_banners.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ COM_BANNERS_BEGIN_LABEL="Begin Date"
COM_BANNERS_CANCEL="Cancel"
COM_BANNERS_CLICK="Click"
COM_BANNERS_CLIENT_EDIT="Edit Client"
COM_BANNERS_CLIENT_EMPTYSTATE_BUTTON_ADD="Add your first client"
COM_BANNERS_CLIENT_EMPTYSTATE_CONTENT="A Banner Client contains contact details and further information such as tracking preferences."
COM_BANNERS_CLIENT_EMPTYSTATE_TITLE="No Clients have been created yet."
COM_BANNERS_CLIENT_NEW="New Client"
COM_BANNERS_CLIENT_SAVE_SUCCESS="Client saved."
COM_BANNERS_CLIENTS_FILTER_SEARCH_DESC="Search in client name. Prefix with ID: to search for a client ID."
Expand Down Expand Up @@ -183,6 +186,8 @@ COM_BANNERS_SUBMENU_CLIENTS="Clients"
COM_BANNERS_SUBMENU_TRACKS="Tracks"
COM_BANNERS_TRACKS_DELETE="Delete Tracks"
COM_BANNERS_TRACKS_DOWNLOAD="Download tracks"
COM_BANNERS_TRACKS_EMPTYSTATE_CONTENT="Here you can see and export tracking information for your banners if tracking has been enabled for that banner."
COM_BANNERS_TRACKS_EMPTYSTATE_TITLE="No Tracks exist yet."
COM_BANNERS_TRACKS_EXPORT="Export"
COM_BANNERS_TRACKS_FILTER_SEARCH_DESC="Search in track name and track client name."
COM_BANNERS_TRACKS_FILTER_SEARCH_LABEL="Search Tracks"
Expand Down

0 comments on commit 4e930a7

Please sign in to comment.