diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php new file mode 100644 index 000000000..91a51c3af --- /dev/null +++ b/core/lib/Thelia/Action/Module.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Thelia\Core\Event\Module\ModuleToggleActivationEvent; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class Module + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Module extends BaseAction implements EventSubscriberInterface +{ + + public function toggleActivation(ModuleToggleActivationEvent $event) + { + + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::MODULE_TOGGLE_ACTIVATION => array('toggleActivation', 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index b3bc085bf..8b4cfe783 100755 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -136,6 +136,11 @@ + + + + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index d554f0550..a3a350365 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -820,6 +820,11 @@ Thelia\Controller\Admin\ModuleController::indexAction + + Thelia\Controller\Admin\ModuleController::toggleActivationAction + \d+ + + diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index 1f0411987..66bd11e49 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -22,6 +22,9 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; + +use Thelia\Core\Event\Module\ModuleToggleActivationEvent; +use Thelia\Core\Event\TheliaEvents; use Thelia\Module\ModuleManagement; /** @@ -35,11 +38,10 @@ class ModuleController extends BaseAdminController { if (null !== $response = $this->checkAuth("admin.module.view")) return $response; - $modulemanagement = new ModuleManagement(); $modulemanagement->updateModules(); - return $this->render("modules", array("display_module" => 20)); + return $this->render("modules"); } public function updateAction($module_id) @@ -48,4 +50,28 @@ class ModuleController extends BaseAdminController "module_id" => $module_id )); } + + public function toggleActivationAction($module_id) + { + if (null !== $response = $this->checkAuth("admin.module.update")) return $response; + $message = null; + try { + $event = new ModuleToggleActivationEvent($module_id); + $this->dispatch(TheliaEvents::MODULE_TOGGLE_ACTIVATION, $event); + } catch (\Exception $e) { + $message = $e->getMessage(); + } + + + if($this->getRequest()->isXmlHttpRequest()) { + if($message) { + $response = $this->nullResponse($message, 500); + } + $response = $this->nullResponse(); + } else { + $response = $this->render("modules"); + } + + return $response; + } } diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 8c819159b..e9f359411 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -58,7 +58,7 @@ class BaseController extends ContainerAware /** * Return an empty response (after an ajax request, for example) */ - protected function nullResponse($status = 200) + protected function nullResponse($content = null, $status = 200) { return new Response(null, $status); } @@ -66,9 +66,9 @@ class BaseController extends ContainerAware /** * Return a JSON response */ - protected function jsonResponse($json_data) + protected function jsonResponse($json_data, $status = 200) { - return new Response($json_data, 200, array('content-type' => 'application/json')); + return new Response($json_data, $status, array('content-type' => 'application/json')); } /** diff --git a/core/lib/Thelia/Core/Event/Module/ModuleEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php new file mode 100644 index 000000000..e9cf2623e --- /dev/null +++ b/core/lib/Thelia/Core/Event/Module/ModuleEvent.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Module; + + +/** + * Class ModuleEvent + * @package Thelia\Core\Event\Module + * @author Manuel Raynaud + */ +class ModuleEvent extends ActionEvent +{ + /** + * @var \Thelia\Model\Module + */ + protected $module; + + function __construct(Module $module = null) + { + $this->module = $module; + } + + /** + * @param \Thelia\Model\Module $module + * + * @return $this + */ + public function setModule(Module $module) + { + $this->module = $module; + + return $this; + } + + /** + * @return \Thelia\Model\Module + */ + public function getModule() + { + return $this->module; + } + + + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php new file mode 100644 index 000000000..dd517d8ff --- /dev/null +++ b/core/lib/Thelia/Core/Event/Module/ModuleToggleActivationEvent.php @@ -0,0 +1,67 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; + + +/** + * Class ModuleToggleActivationEvent + * @package Thelia\Core\Event\Module + * @author Manuel Raynaud + */ +class ModuleToggleActivationEvent extends ModuleEvent +{ + /** + * @var int + */ + protected $module_id; + + function __construct($module_id) + { + $this->module_id = $module_id; + } + + /** + * @param int $module_id + * + * @return $this + */ + public function setModuleId($module_id) + { + $this->module_id = $module_id; + + return $this; + } + + /** + * @return int + */ + public function getModuleId() + { + return $this->module_id; + } + + + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index aa365e54a..78e96bf97 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -657,4 +657,6 @@ final class TheliaEvents const GENERATE_PDF = 'thelia.generatePdf'; + const MODULE_TOGGLE_ACTIVATION = 'thelia.module.toggleActivation'; + } diff --git a/templates/admin/default/includes/module-block.html b/templates/admin/default/includes/module-block.html index 7784c84db..2b45f5bc3 100644 --- a/templates/admin/default/includes/module-block.html +++ b/templates/admin/default/includes/module-block.html @@ -22,9 +22,16 @@ {$TITLE} {$CHAPO} -
+
+ {module_include location='modules_table_row'}