Skip to content

Commit

Permalink
Display always the toolbar and adjust its functions
Browse files Browse the repository at this point in the history
Since the selectboxes now always have a value, the buttons Delete associations and delete orphans of the toolbar are now always displayed.

The "delete associations"-button now only deletes associations in which the user is currently located.
- In addition, the button was adapted to a Confirm button, so that the associated js file and the associated message text could be removed.
- The context is now also included as info in the message text.
  • Loading branch information
lavipr committed May 27, 2019
1 parent cec6bd5 commit 57c3a12
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
Expand Up @@ -49,15 +49,16 @@ public function getModel($name = 'Associations', $prefix = 'Administrator', $con
}

/**
* Method to purge the associations table.
* Method to purge the associations table by context.
*
* @return void
*
* @since 3.7.0
*/
public function purge()
{
$this->getModel('associations')->purge();
$context = $this->input->getString('itemtype');
$this->getModel('associations')->purge($context);
$this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list, false));
}

Expand Down
Expand Up @@ -474,7 +474,26 @@ public function purge($context = '', $key = '')
// Filter by associations context.
if ($context)
{
$query->where($db->quoteName('context') . ' = ' . $db->quote($context));
list($extensionName, $typeName) = explode('.', $context, 2);

// The associations of the type category may only be deleted with the appropriate context,
// therefore with the appropriate extension. Not all categories.
if ($typeName === 'category')
{
// Subquery: Search for category-items with the given context
$subQuery = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__categories'))
->where($db->quoteName('extension') . ' = ' . $db->quote($extensionName));

// Delete associations of categories with the given context by comparing id of both tables
$query->where($db->quoteName('id') . ' IN (' . $subQuery . ')')
->where($db->quoteName('context') . ' = ' . $db->quote('com_categories.item'));
}
else
{
$query->where($db->quoteName('context') . ' = ' . $db->quote($extensionName . '.item'));
}
}

// Filter by key.
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;

Expand Down Expand Up @@ -225,6 +226,7 @@ public function display($tpl = null)
protected function addToolbar()
{
$user = Factory::getUser();
$toolbar = Toolbar::getInstance('toolbar');

if (isset($this->typeName) && isset($this->extensionName))
{
Expand All @@ -251,12 +253,11 @@ protected function addToolbar()

if ($user->authorise('core.admin', 'com_associations') || $user->authorise('core.options', 'com_associations'))
{
if (!isset($this->typeName))
{
ToolbarHelper::custom('associations.purge', 'purge', 'purge', 'COM_ASSOCIATIONS_PURGE', false, false);
ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false);
}

$toolbar->confirmButton('purge')
->text('COM_ASSOCIATIONS_PURGE')
->message(Text::plural('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', (Text::_($this->extensionName) . ' > ' . Text::_($languageKey))))
->task('associations.purge');
ToolbarHelper::custom('associations.clean', 'refresh', 'refresh', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false);
ToolbarHelper::preferences('com_associations');
}

Expand Down
Expand Up @@ -29,8 +29,6 @@
2 => 'icon-archive',
);

Text::script('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT', true);
HTMLHelper::_('script', 'com_associations/admin-associations-default.min.js', ['version' => 'auto', 'relative' => true]);
?>
<form action="<?php echo Route::_('index.php?option=com_associations&view=associations'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
Expand Down Expand Up @@ -147,7 +145,7 @@
</tbody>
</table>

<?php // load the pagination. ?>
<?php // Load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>

<?php endif; ?>
Expand Down
2 changes: 1 addition & 1 deletion administrator/language/en-GB/en-GB.com_associations.ini
Expand Up @@ -31,7 +31,7 @@ COM_ASSOCIATIONS_ITEMS="Items"
COM_ASSOCIATIONS_NO_ASSOCIATION="There is no association for this language"
COM_ASSOCIATIONS_NOTICE_NO_SELECTORS="Please select an Item Type and a reference language to view the associations."
COM_ASSOCIATIONS_PURGE="Delete All Associations"
COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT="Are you sure you want to delete all associations? Confirming will permanently delete them!"
COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT="Are you sure you want to delete all associations concerning %s? Confirming will permanently delete them!"
COM_ASSOCIATIONS_PURGE_FAILED="Failed to delete all associations."
COM_ASSOCIATIONS_PURGE_NONE="There were no associations to delete."
COM_ASSOCIATIONS_PURGE_SUCCESS="All associations have been deleted."
Expand Down

This file was deleted.

0 comments on commit 57c3a12

Please sign in to comment.