Improve bulk module enable/disable handling in BO modules list
This commit is contained in:
@@ -48,42 +48,34 @@
|
||||
function modules_management(action)
|
||||
{
|
||||
var modules = document.getElementsByName('modules');
|
||||
var module_list = '';
|
||||
var module_list = [];
|
||||
for (var i = 0; i < modules.length; i++)
|
||||
{
|
||||
if (modules[i].checked == true)
|
||||
if (modules[i].checked)
|
||||
{
|
||||
rel = modules[i].getAttribute('data-rel');
|
||||
var rel = modules[i].getAttribute('data-rel');
|
||||
if (rel != "false" && action == "uninstall")
|
||||
{
|
||||
if (!confirm(rel))
|
||||
return false;
|
||||
}
|
||||
module_list += '|'+modules[i].value;
|
||||
module_list.push(modules[i].value);
|
||||
}
|
||||
}
|
||||
document.location.href=currentIndex+'&token='+token+'&'+action+'='+module_list.substring(1, module_list.length);
|
||||
}
|
||||
|
||||
// Module bulk enable/disable
|
||||
function update_modules_activation_bulk(action)
|
||||
{
|
||||
var modules = document.getElementsByName('modules');
|
||||
var module_list = '';
|
||||
var type = 'enabled';
|
||||
|
||||
for (var i = 0; i < modules.length; i++)
|
||||
{
|
||||
if (modules[i].checked == true)
|
||||
{
|
||||
module_list += '|'+modules[i].value;
|
||||
}
|
||||
}
|
||||
if(action=='bulkDisable'){
|
||||
type = 'disabled';
|
||||
if (!module_list.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
document.location.href=currentIndex+'&token='+token+'&bulkEnable=1&type='+type+'&modules='+module_list.substring(1, module_list.length);
|
||||
module_list = encodeURIComponent(module_list.join('|'));
|
||||
if (action == 'bulk_enable' || action == 'bulk_disable') {
|
||||
var type = action == 'bulk_disable' ? 'disabled' : 'enabled';
|
||||
document.location.href = currentIndex+'&token='+token+'&bulk_enable=1&type='+type+'&modules='+module_list;
|
||||
return false;
|
||||
}
|
||||
|
||||
document.location.href = currentIndex+'&token='+token+'&'+action+'='+module_list;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -191,13 +191,13 @@
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="#" onclick="update_modules_activation_bulk('bulkEnable')">
|
||||
<a href="#" onclick="modules_management('bulk_enable')">
|
||||
<i class="icon-power-off text-success"></i>
|
||||
{l s='Enable selection'}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" onclick="update_modules_activation_bulk('bulkDisable')">
|
||||
<a href="#" onclick="modules_management('bulk_disable')">
|
||||
<i class="icon-power-off text-danger"></i>
|
||||
{l s='Disable selection'}
|
||||
</a>
|
||||
|
||||
@@ -1066,49 +1066,68 @@ class AdminModulesControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
public function postProcessBulkEnable()
|
||||
public function postProcessBulk_Enable()
|
||||
{
|
||||
if ($this->tabAccess['edit'] === 1) {
|
||||
$moduleStatus = Tools::getValue('type');
|
||||
$moduleNames = array_unique(array_filter(
|
||||
explode('|', strip_tags((string) Tools::getValue('modules')))
|
||||
));
|
||||
|
||||
$modules = Tools::getValue('modules');
|
||||
$module_status = Tools::getValue('type');
|
||||
|
||||
if (!empty($modules)) {
|
||||
|
||||
$modules = strip_tags($modules);
|
||||
$modules = explode('|', $modules);
|
||||
|
||||
if (!is_array($modules)) {
|
||||
$modules = (array)$modules;
|
||||
}
|
||||
if (is_array($modules)) {
|
||||
foreach ($modules as $module_name) {
|
||||
$module = Module::getInstanceByName($module_name);
|
||||
if (Validate::isLoadedObject($module)) {
|
||||
if (!$module->getPermission('configure')) {
|
||||
$this->errors[] = Tools::displayError('You do not have the permission to use this module ') . ': ' . $module->displayName;
|
||||
} else {
|
||||
if($module_status == 'enabled') {
|
||||
$module->enable();
|
||||
} else {
|
||||
$module->disable();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = Tools::displayError('Cannot load the module\'s object ') . ': ' . $module_name;
|
||||
}
|
||||
}
|
||||
if(!count($this->errors)) {
|
||||
Configuration::updateValue('PS_SHOW_ENABLED_MODULES_' . (int)$this->id_employee, $module_status);
|
||||
Tools::redirectAdmin($this->getCurrentUrl('bulkEnable'));
|
||||
}
|
||||
}
|
||||
if (!in_array($moduleStatus, array('enabled', 'disabled'), true)) {
|
||||
$this->errors[] = Tools::displayError('Invalid module status.');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (empty($moduleNames)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$modules = array();
|
||||
|
||||
foreach ($moduleNames as $moduleName) {
|
||||
if (!Validate::isModuleName($moduleName)) {
|
||||
$this->errors[] = Tools::displayError('Invalid module name ') . ': ' . $moduleName;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Module::isInstalled($moduleName)) {
|
||||
$this->errors[] = Tools::displayError('This module is not installed ') . ': ' . $moduleName;
|
||||
continue;
|
||||
}
|
||||
|
||||
$module = Module::getInstanceByName($moduleName);
|
||||
if (!Validate::isLoadedObject($module)) {
|
||||
$this->errors[] = Tools::displayError('Cannot load the module\'s object ') . ': ' . $moduleName;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$module->getPermission('configure')) {
|
||||
$this->errors[] = Tools::displayError('You do not have the permission to use this module ') . ': ' . $module->displayName;
|
||||
continue;
|
||||
}
|
||||
|
||||
$modules[] = $module;
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
foreach ($modules as $module) {
|
||||
if ($moduleStatus === 'enabled') {
|
||||
$module->enable();
|
||||
} else {
|
||||
$module->disable();
|
||||
}
|
||||
}
|
||||
Configuration::updateValue('PS_SHOW_ENABLED_MODULES_' . (int)$this->id_employee, $moduleStatus);
|
||||
Tools::redirectAdmin($this->getCurrentUrl(array('bulk_enable', 'type', 'modules')));
|
||||
}
|
||||
|
||||
}else{
|
||||
$this->errors[] = Tools::displayError('You do not have permission to add this.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getModulesByInstallation($tab_modules_list = null)
|
||||
{
|
||||
// $all_modules = Module::getModulesOnDisk(true, $this->logged_on_addons, $this->id_employee);
|
||||
@@ -1172,7 +1191,7 @@ class AdminModulesControllerCore extends AdminController
|
||||
|
||||
// Execute filter or callback methods
|
||||
$filter_methods = array('filterModules', 'resetFilterModules', 'filterCategory', 'unfilterCategory');
|
||||
$callback_methods = array('reset', 'download', 'enable', 'delete', 'enable_device', 'disable_device', 'bulkEnable');
|
||||
$callback_methods = array('reset', 'download', 'enable', 'delete', 'enable_device', 'disable_device', 'bulk_enable');
|
||||
$post_process_methods_list = array_merge((array)$filter_methods, (array)$callback_methods);
|
||||
foreach ($post_process_methods_list as $ppm) {
|
||||
if (Tools::isSubmit($ppm)) {
|
||||
|
||||
Reference in New Issue
Block a user