Skip to content

Commit

Permalink
Add support to unpublish module from cpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Lodder committed Feb 18, 2019
1 parent 0ae1a54 commit e61ae03
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 22 deletions.
10 changes: 9 additions & 1 deletion administrator/components/com_cpanel/tmpl/cpanel/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;

HTMLHelper::_('behavior.core');
Text::script('COM_CPANEL_UNPUBLISH_MODULE_SUCCESS');
Text::script('COM_CPANEL_UNPUBLISH_MODULE_ERROR');

HTMLHelper::_('script', 'com_cpanel/admin-cpanel-default.min.js', array('version' => 'auto', 'relative' => true));

$user = Factory::getUser();
?>
Expand All @@ -29,7 +37,7 @@
</div>
<?php endif; ?>
</div>
<div class="row">
<div id="cpanel-modules" class="row">
<?php
$cols = 0;
foreach ($this->modules as $module)
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_cpanel.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ COM_CPANEL_TITLE_SYSTEM_PANEL="System Panel"
COM_CPANEL_MSG_UPDATEDEFAULTSETTINGS_BODY="<p>As part of our security team's review, we have made some changes to the default settings in a new Joomla installation. As these changes are only applied to new installations, we strongly recommend that you review these changes and update your site.</p><p>The changed settings are:</p><ul><li>Global Configuration > Text Filters: The default \"Administrator\" user group has changed from \"No Filtering\" to \"Default Blacklist\"</li><li>Users > Send Password: The option to send a user their password in plain text when an account is created is now disabled by default</li><li>Media Manager: Flash files (\"swf\" file extension and \"application/x-shockwave-flash\" MIME Type) are not allowed to be uploaded</li><li>Articles > Show Email: The option to show an email icon with articles is disabled by default</li></ul><p>We have created a <a href=\"https://docs.joomla.org/Special:MyLanguage/J3.x:Joomla_3.8.8_notes_about_the_changed_default_settings\">dedicated documentation page</a> explaining these changes.</p>"
COM_CPANEL_MSG_UPDATEDEFAULTSETTINGS_TITLE="Updated site security recommendations"
COM_CPANEL_WELCOME_BEGINNERS_MESSAGE="<p>Community resources are available for new users.</p><ul><li><a href=\"https://docs.joomla.org/Special:MyLanguage/Portal:Beginners\">Joomla! Beginners Guide</a></li><li><a href=\"https://forum.joomla.org/viewforum.php?f=706\">New to Joomla! Forum</a></li></ul>"
COM_CPANEL_UNPUBLISH_MODULE_ERROR="Error unpublishing the module"
COM_CPANEL_UNPUBLISH_MODULE_SUCCESS="Module successfully unpublished"
COM_CPANEL_WELCOME_BEGINNERS_TITLE="Welcome to Joomla!"
COM_CPANEL_XML_DESCRIPTION="Control Panel component"
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ JACTION_LOGIN_OFFLINE="Offline Access"
JACTION_LOGIN_SITE="Site Login"
JACTION_MANAGE="Access Administration Interface"
JACTION_OPTIONS="Configure Options Only"
ACTION_UNPUBLISH="Unpublish"

JBROWSERTARGET_MODAL="Modal"
JBROWSERTARGET_NEW="Open in new window"
Expand Down
2 changes: 1 addition & 1 deletion administrator/modules/mod_status/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<span class="badge badge-pill badge-danger"><?php echo count($messages); ?></span>
<?php endif; ?>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-notifications">
<div class="dropdown-menu dropdown-menu-right dropdown-notifications border-0">
<div class="list-group">
<?php if (empty($messages)) : ?>
<p class="list-group-item text-center">
Expand Down
34 changes: 24 additions & 10 deletions administrator/templates/atum/html/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ function modChrome_well($module, &$params, &$attribs)
{
if ($module->content)
{
$id = $module->id;

// Permission checks
$user = Factory::getUser();
$canEdit = $user->authorise('core.edit', 'com_modules.module.' . $module->id) && $user->authorise('core.manage', 'com_modules');
$canEdit = $user->authorise('core.edit', 'com_modules.module.' . $id) && $user->authorise('core.manage', 'com_modules');

$moduleTag = $params->get('module_tag', 'div');
$bootstrapSize = (int) $params->get('bootstrap_size', 6);
Expand All @@ -65,14 +67,19 @@ function modChrome_well($module, &$params, &$attribs)
$headerClass = $params->get('header_class');
$headerClass = ($headerClass) ? ' ' . htmlspecialchars($headerClass) : '';

echo '<div class="' . $moduleClass . '">';
echo '<div class="' . $moduleClass . ' module-wrapper">';
echo '<' . $moduleTag . ' class="card mb-3' . $moduleClassSfx . '">';

if ($canEdit)
{
echo '<div class="module-actions">';
echo '<a href="' . Route::_('index.php?option=com_modules&task=module.edit&id=' . (int) $module->id)
. '"><span class="fa fa-cog"><span class="sr-only">' . Text::_('JACTION_EDIT') . " " . $module->title . '</span></span></a>';
$dropdownPosition = Factory::getLanguage()->isRTL() ? 'left' : 'right';

echo '<div class="module-actions dropdown">';
echo '<a data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="dropdownMenuButton-' . $id . '"><span class="fa fa-cog"><span class="sr-only">' . Text::_('JACTION_EDIT') . ' ' . $module->title . '</span></span></a>';
echo '<div class="dropdown-menu dropdown-menu-' . $dropdownPosition . '" aria-labelledby="dropdownMenuButton-' . $id . '">';
echo '<a class="dropdown-item" href="' . Route::_('index.php?option=com_modules&task=module.edit&id=' . $id) . '">' . Text::_('JACTION_EDIT') . '</a>';
echo '<a class="dropdown-item unpublish-module" data-module-id="' . $id . '">' . Text::_('ACTION_UNPUBLISH') . '</a>';
echo '</div>';
echo '</div>';
}

Expand All @@ -92,9 +99,11 @@ function modChrome_body($module, &$params, &$attribs)
{
if ($module->content)
{
$id = $module->id;

// Permission checks
$user = Factory::getUser();
$canEdit = $user->authorise('core.edit', 'com_modules.module.' . $module->id);
$canEdit = $user->authorise('core.edit', 'com_modules.module.' . $id);

$moduleTag = $params->get('module_tag', 'div');
$bootstrapSize = (int) $params->get('bootstrap_size', 6);
Expand All @@ -106,14 +115,19 @@ function modChrome_body($module, &$params, &$attribs)
$headerClass = $params->get('header_class');
$headerClass = ($headerClass) ? ' ' . htmlspecialchars($headerClass) : '';

echo '<div class="' . $moduleClass . '">';
echo '<div class="' . $moduleClass . ' module-wrapper">';
echo '<' . $moduleTag . ' class="card mb-3' . $moduleClassSfx . '">';

if ($canEdit)
{
echo '<div class="module-actions">';
echo '<a href="' . Route::_('index.php?option=com_modules&task=module.edit&id=' . (int) $module->id)
. '"><span class="fa fa-cog"><span class="sr-only">' . Text::_('JACTION_EDIT') . " " . $module->title . '</span></span></a>';
$dropdownPosition = Factory::getLanguage()->isRTL() ? 'left' : 'right';

echo '<div class="module-actions dropdown">';
echo '<a data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="dropdownMenuButton-' . $id . '"><span class="fa fa-cog"><span class="sr-only">' . Text::_('JACTION_EDIT') . ' ' . $module->title . '</span></span></a>';
echo '<div class="dropdown-menu dropdown-menu-' . $dropdownPosition . '" aria-labelledby="dropdownMenuButton-' . $id . '">';
echo '<a class="dropdown-item" href="' . Route::_('index.php?option=com_modules&task=module.edit&id=' . $id) . '">' . Text::_('JACTION_EDIT') . '</a>';
echo '<a class="dropdown-item unpublish-module" data-module-id="' . $id . '">' . Text::_('ACTION_UNPUBLISH') . '</a>';
echo '</div>';
echo '</div>';
}

Expand Down
4 changes: 2 additions & 2 deletions administrator/templates/atum/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ $btn-border-radius-sm: 0;

// Dropdowns
$dropdown-padding-y: 0;
$dropdown-border-width: 0;
$dropdown-link-hover-color: $white;
$dropdown-border-width: 1px;
//$dropdown-link-hover-color: $white;
$dropdown-item-padding-y: .5rem;
$dropdown-item-padding-x: .75rem;
$dropdown-spacer: 0;
Expand Down
1 change: 0 additions & 1 deletion administrator/templates/atum/scss/blocks/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
.dropdown-menu {
min-width: 280px;
padding: 0;
border: 0;
z-index: 1041;

h2 {
Expand Down
7 changes: 0 additions & 7 deletions administrator/templates/atum/scss/blocks/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@
}
}

.dropdown-item {

&:hover {
color: #212529;
}
}

.dropdown-toggle {

&.btn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
}
}

.dropdown-menu {
box-shadow: $atum-box-shadow;
}

.dropdown-item {
cursor: pointer;
}

.dropdown-item:hover,
.dropdown-item:focus {
.btn-primary + .dropdown-menu & {
Expand Down
75 changes: 75 additions & 0 deletions build/media_source/com_cpanel/js/admin-cpanel-default.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

((window, document, Joomla) => {
let matchesFn = 'matches';

Joomla.unpublishModule = (element) => {
// Get variables
const baseUrl = 'index.php?option=com_modules&task=modules.unpublish&format=json';
const id = element.getAttribute('data-module-id');

Joomla.request({
url: `${baseUrl}&cid=${id}`,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
onSuccess: (resp) => {
const wrapper = closest(element, '.module-wrapper');
wrapper.parentNode.removeChild(wrapper);

Joomla.renderMessages({
message: [Joomla.JText._('COM_CPANEL_UNPUBLISH_MODULE_SUCCESS')]
});
},
onError: () => {
Joomla.renderMessages({
error: [Joomla.JText._('COM_CPANEL_UNPUBLISH_MODULE_ERROR')]
});
},
});
};

const closest = (element, selector) => {
let parent;

// Traverse parents
while (element) {
parent = element.parentElement;
if (parent && parent[matchesFn](selector)) {
return parent;
}
element = parent;
}

return null;
}

const onBoot = () => {
// Find matchesFn with vendor prefix
['matches', 'msMatchesSelector'].some((fn) => {
if (typeof document.body[fn] === 'function') {
matchesFn = fn;
return true;
}
return false;
});

const cpanelModules = document.getElementById('cpanel-modules');
if (cpanelModules) {
const links = [].slice.call(cpanelModules.querySelectorAll('.unpublish-module'));
links.forEach((link) => {
link.addEventListener('click', event => Joomla.unpublishModule(event.target));
});
}

// Cleanup
document.removeEventListener('DOMContentLoaded', onBoot);
};

// Initialise
document.addEventListener('DOMContentLoaded', onBoot);
})(window, document, window.Joomla);
4 changes: 4 additions & 0 deletions build/media_source/system/scss/joomla-toolbar-button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
joomla-toolbar-button .dropdown-item:focus,
joomla-toolbar-button .dropdown-item:hover {
color: #fff;
}

0 comments on commit e61ae03

Please sign in to comment.