mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2024-12-26 01:57:30 +00:00
Use J4 Toolbar
This commit is contained in:
parent
31a4a595c1
commit
b7fe535a17
@ -11,6 +11,7 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblink;
|
|||||||
|
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
use Joomla\CMS\Component\ComponentHelper;
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Helper\ContentHelper;
|
use Joomla\CMS\Helper\ContentHelper;
|
||||||
use Joomla\CMS\Language\Text;
|
use Joomla\CMS\Language\Text;
|
||||||
@ -93,9 +94,10 @@ class HtmlView extends BaseHtmlView
|
|||||||
*/
|
*/
|
||||||
protected function addToolbar()
|
protected function addToolbar()
|
||||||
{
|
{
|
||||||
Factory::getApplication()->input->set('hidemainmenu', true);
|
$app = Factory::getApplication();
|
||||||
|
$app->input->set('hidemainmenu', true);
|
||||||
|
|
||||||
$user = Factory::getUser();
|
$user = $app->getIdentity();
|
||||||
$isNew = ($this->item->id == 0);
|
$isNew = ($this->item->id == 0);
|
||||||
$checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
|
$checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
|
||||||
|
|
||||||
@ -104,36 +106,63 @@ class HtmlView extends BaseHtmlView
|
|||||||
|
|
||||||
ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
|
ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks');
|
||||||
|
|
||||||
// If not checked out, can save the item.
|
// Build the actions for new and existing records.
|
||||||
if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create')))))
|
if ($isNew)
|
||||||
|
{
|
||||||
|
// For new records, check the create permission.
|
||||||
|
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
|
||||||
{
|
{
|
||||||
ToolbarHelper::apply('weblink.apply');
|
ToolbarHelper::apply('weblink.apply');
|
||||||
ToolbarHelper::save('weblink.save');
|
|
||||||
|
ToolbarHelper::saveGroup(
|
||||||
|
[
|
||||||
|
['save', 'weblink.save'],
|
||||||
|
['save2new', 'weblink.save2new']
|
||||||
|
],
|
||||||
|
'btn-success'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))
|
|
||||||
{
|
|
||||||
ToolbarHelper::save2new('weblink.save2new');
|
|
||||||
}
|
|
||||||
// If an existing item, can save to a copy.
|
|
||||||
if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0))
|
|
||||||
{
|
|
||||||
ToolbarHelper::save2copy('weblink.save2copy');
|
|
||||||
}
|
|
||||||
if (empty($this->item->id))
|
|
||||||
{
|
|
||||||
ToolbarHelper::cancel('weblink.cancel');
|
ToolbarHelper::cancel('weblink.cancel');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit'))
|
// Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
|
||||||
|
$itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $user->id);
|
||||||
|
|
||||||
|
$toolbarButtons = [];
|
||||||
|
|
||||||
|
// Can't save the record if it's checked out and editable
|
||||||
|
if (!$checkedOut && $itemEditable)
|
||||||
|
{
|
||||||
|
ToolbarHelper::apply('weblink.apply');
|
||||||
|
|
||||||
|
$toolbarButtons[] = ['save', 'weblink.save'];
|
||||||
|
|
||||||
|
// We can save this record, but check the create permission to see if we can return to make a new one.
|
||||||
|
if ($canDo->get('core.create'))
|
||||||
|
{
|
||||||
|
$toolbarButtons[] = ['save2new', 'weblink.save2new'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If checked out, we can still save
|
||||||
|
if ($canDo->get('core.create'))
|
||||||
|
{
|
||||||
|
$toolbarButtons[] = ['save2copy', 'weblink.save2copy'];
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolbarHelper::saveGroup(
|
||||||
|
$toolbarButtons,
|
||||||
|
'btn-success'
|
||||||
|
);
|
||||||
|
|
||||||
|
ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
|
||||||
|
|
||||||
|
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable)
|
||||||
{
|
{
|
||||||
ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
|
ToolbarHelper::versions('com_weblinks.weblink', $this->item->id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolbarHelper::divider();
|
|
||||||
ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,6 @@ defined('_JEXEC') or die;
|
|||||||
|
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Helper\ContentHelper;
|
use Joomla\CMS\Helper\ContentHelper;
|
||||||
use Joomla\CMS\HTML\HTMLHelper;
|
|
||||||
use Joomla\CMS\Language\Text;
|
|
||||||
use Joomla\CMS\Layout\FileLayout;
|
|
||||||
use Joomla\CMS\MVC\View\GenericDataException;
|
use Joomla\CMS\MVC\View\GenericDataException;
|
||||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||||
use Joomla\CMS\Toolbar\Toolbar;
|
use Joomla\CMS\Toolbar\Toolbar;
|
||||||
@ -121,55 +118,64 @@ class HtmlView extends BaseHtmlView
|
|||||||
*/
|
*/
|
||||||
protected function addToolbar()
|
protected function addToolbar()
|
||||||
{
|
{
|
||||||
$state = $this->get('State');
|
$canDo = ContentHelper::getActions('com_weblinks', 'category', $this->state->get('filter.category_id'));
|
||||||
$canDo = ContentHelper::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
|
$user = Factory::getApplication()->getIdentity();
|
||||||
$user = Factory::getUser();
|
|
||||||
|
|
||||||
// Get the toolbar object instance
|
// Get the toolbar object instance
|
||||||
$bar = Toolbar::getInstance('toolbar');
|
$toolbar = Toolbar::getInstance('toolbar');
|
||||||
|
|
||||||
ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
|
ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
|
||||||
|
|
||||||
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
|
if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
|
||||||
{
|
{
|
||||||
ToolbarHelper::addNew('weblink.add');
|
ToolbarHelper::addNew('weblink.add');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($canDo->get('core.edit') || $canDo->get('core.edit.own'))
|
|
||||||
{
|
|
||||||
ToolbarHelper::editList('weblink.edit');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($canDo->get('core.edit.state'))
|
if ($canDo->get('core.edit.state'))
|
||||||
{
|
{
|
||||||
ToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
|
$dropdown = $toolbar->dropdownButton('status-group')
|
||||||
ToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
|
->text('JTOOLBAR_CHANGE_STATUS')
|
||||||
|
->toggleSplit(false)
|
||||||
|
->icon('icon-ellipsis-h')
|
||||||
|
->buttonClass('btn btn-action')
|
||||||
|
->listCheck(true);
|
||||||
|
|
||||||
ToolbarHelper::archiveList('weblinks.archive');
|
$childBar = $dropdown->getChildToolbar();
|
||||||
ToolbarHelper::checkin('weblinks.checkin');
|
|
||||||
|
$childBar->publish('weblinks.publish')->listCheck(true);
|
||||||
|
|
||||||
|
$childBar->unpublish('weblinks.unpublish')->listCheck(true);
|
||||||
|
|
||||||
|
$childBar->archive('weblinks.archive')->listCheck(true);
|
||||||
|
|
||||||
|
if ($user->authorise('core.admin'))
|
||||||
|
{
|
||||||
|
$childBar->checkin('weblinks.checkin')->listCheck(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($state->get('filter.published') == -2 && $canDo->get('core.delete'))
|
if ($this->state->get('filter.published') != -2)
|
||||||
{
|
{
|
||||||
ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
|
$childBar->trash('weblinks.trash')->listCheck(true);
|
||||||
}
|
|
||||||
elseif ($canDo->get('core.edit.state'))
|
|
||||||
{
|
|
||||||
ToolbarHelper::trash('weblinks.trash');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a batch button
|
// Add a batch button
|
||||||
if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
|
if ($user->authorise('core.create', 'com_weblinks')
|
||||||
|
&& $user->authorise('core.edit', 'com_weblinks')
|
||||||
&& $user->authorise('core.edit.state', 'com_weblinks'))
|
&& $user->authorise('core.edit.state', 'com_weblinks'))
|
||||||
{
|
{
|
||||||
HTMLHelper::_('bootstrap.renderModal', 'collapseModal');
|
$childBar->popupButton('batch')
|
||||||
$title = Text::_('JTOOLBAR_BATCH');
|
->text('JTOOLBAR_BATCH')
|
||||||
|
->selector('collapseModal')
|
||||||
|
->listCheck(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Instantiate a new JLayoutFile instance and render the batch button
|
if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete'))
|
||||||
$layout = new FileLayout('joomla.toolbar.batch');
|
{
|
||||||
|
$toolbar->delete('contacts.delete')
|
||||||
$dhtml = $layout->render(array('title' => $title));
|
->text('JTOOLBAR_EMPTY_TRASH')
|
||||||
$bar->appendButton('Custom', $dhtml, 'batch');
|
->message('JGLOBAL_CONFIRM_DELETE')
|
||||||
|
->listCheck(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
|
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
|
||||||
|
Loading…
Reference in New Issue
Block a user