Category visibility toggle implementation
This commit is contained in:
@@ -235,6 +235,29 @@ class Category implements EventSubscriberInterface
|
||||
$event->stopPropagation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle category visibility. No form used here
|
||||
*
|
||||
* @param ActionEvent $event
|
||||
*/
|
||||
public function toggleVisibility(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
$category = CategoryQuery::create()->findPk($request->get('id', 0));
|
||||
|
||||
if ($category !== null) {
|
||||
|
||||
$category->setVisible($category->getVisible() ? false : true);
|
||||
|
||||
$category->save();
|
||||
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECATEGORY, $categoryEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber listens to.
|
||||
*
|
||||
@@ -261,6 +284,8 @@ class Category implements EventSubscriberInterface
|
||||
"action.createCategory" => array("create", 128),
|
||||
"action.modifyCategory" => array("modify", 128),
|
||||
"action.deleteCategory" => array("delete", 128),
|
||||
);
|
||||
|
||||
"action.toggleCategoryVisibility" => array("toggleVisibility", 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,16 @@ class BaseAdminController extends ContainerAware
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an empty response (after an ajax request, for example)
|
||||
*/
|
||||
protected function nullResponse()
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the givent template, and returns the result as an Http Response.
|
||||
* Render the given template, and returns the result as an Http Response.
|
||||
*
|
||||
* @param $templateName the complete template name, with extension
|
||||
* @param array $args the template arguments
|
||||
|
||||
@@ -25,20 +25,10 @@ namespace Thelia\Admin\Controller;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
|
||||
class CategoryController extends BaseAdminController {
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
// Show top level categories and products
|
||||
$args = array(
|
||||
'action' => 'browse',
|
||||
'current_category_id' => 0
|
||||
);
|
||||
|
||||
return $this->browseCategory($args);
|
||||
}
|
||||
|
||||
public function createNewCategory($args) {
|
||||
protected function createNewCategory($args) {
|
||||
|
||||
$this->checkAuth("ADMIN", "admin.category.create");
|
||||
|
||||
@@ -48,14 +38,14 @@ class CategoryController extends BaseAdminController {
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
public function editCategory($args) {
|
||||
protected function editCategory($args) {
|
||||
|
||||
$this->checkAuth("AMIN", "admin.category.edit");
|
||||
|
||||
return $this->render('edit_category', $args);
|
||||
}
|
||||
|
||||
public function deleteCategory($category_id) {
|
||||
protected function deleteCategory($category_id) {
|
||||
|
||||
$this->checkAuth("AMIN", "admin.category.delete");
|
||||
|
||||
@@ -70,13 +60,42 @@ class CategoryController extends BaseAdminController {
|
||||
);
|
||||
}
|
||||
|
||||
public function browseCategory($args) {
|
||||
protected function browseCategory($args) {
|
||||
|
||||
$this->checkAuth("AMIN", "admin.catalog.view");
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
protected function visibilityToggle($args) {
|
||||
|
||||
$this->checkAuth("AMIN", "admin.category.edit");
|
||||
|
||||
$this->dispatchEvent("toggleCategoryVisibility");
|
||||
|
||||
return $this->nullResponse();
|
||||
}
|
||||
|
||||
protected function changePosition($args) {
|
||||
|
||||
$this->checkAuth("AMIN", "admin.category.edit");
|
||||
|
||||
$this->dispatchEvent("changeCategoryPosition");
|
||||
|
||||
return $this->render('categories', $args);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
// Show top level categories and products
|
||||
$args = array(
|
||||
'action' => 'browse',
|
||||
'current_category_id' => 0
|
||||
);
|
||||
|
||||
return $this->browseCategory($args);
|
||||
}
|
||||
|
||||
public function processAction()
|
||||
{
|
||||
// Get the current action
|
||||
@@ -91,21 +110,24 @@ class CategoryController extends BaseAdminController {
|
||||
);
|
||||
|
||||
try {
|
||||
// Browse categories
|
||||
if ($action == 'browse') {
|
||||
return $this->browseCategory($args);
|
||||
}
|
||||
// Create a new category
|
||||
else if ($action == 'create') {
|
||||
return $this->createNewCategory($args);
|
||||
}
|
||||
// Edit an existing category
|
||||
else if ($action == 'edit') {
|
||||
return $this->editCategory($args);
|
||||
}
|
||||
// Delete an existing category
|
||||
else if ($action == 'delete') {
|
||||
return $this->deleteCategory($id);
|
||||
switch($action) {
|
||||
case 'browse' : // Browse categories
|
||||
return $this->browseCategory($args);
|
||||
|
||||
case 'create' : // Create a new category
|
||||
return $this->createNewCategory($args);
|
||||
|
||||
case 'edit' : // Edit an existing category
|
||||
return $this->editCategory($args);
|
||||
|
||||
case 'delete' : // Delete an existing category
|
||||
return $this->deleteCategory($id);
|
||||
|
||||
case 'visibilityToggle' : // Toggle visibility
|
||||
return $this->visibilityToggle($id);
|
||||
|
||||
case 'changePosition' : // Change position
|
||||
return $this->changePosition($args);
|
||||
}
|
||||
}
|
||||
catch(AuthenticationException $ex) {
|
||||
|
||||
@@ -109,4 +109,9 @@ final class TheliaEvents
|
||||
*/
|
||||
const AFTER_DELETECATEGORY = "action.after_deletecategory";
|
||||
|
||||
/**
|
||||
* Sent just after a successful change of a category in the database.
|
||||
*/
|
||||
const AFTER_CHANGECATEGORY = "action.after_changecategory";
|
||||
|
||||
}
|
||||
@@ -57,7 +57,13 @@
|
||||
{module_include location='category_list_row'}
|
||||
|
||||
<td>
|
||||
<input type="checkbox" data-id="{$ID}" class="displayToggle" {if $VISIBLE == 1}checked="checked"{/if}>
|
||||
{loop type="auth" name="can_change" context="admin" roles="ADMIN" permissions="admin.category.edit"}
|
||||
<input type="checkbox" data-id="{$ID}" class="categoryVisibleToggle" {if $VISIBLE == 1}checked="checked"{/if}>
|
||||
{/loop}
|
||||
|
||||
{elseloop rel="can_change"}
|
||||
<input type="checkbox" class="disabled" disabled="disabled" {if $VISIBLE == 1}checked="checked"{/if}>
|
||||
{/elseloop}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
@@ -222,6 +228,17 @@ $(function() {
|
||||
$('#'+'delete-category-id').val($(this).data('id'));
|
||||
});
|
||||
|
||||
// Toggle category visibility
|
||||
$(".categoryVisibleToggle").click(function() {
|
||||
$.ajax({
|
||||
url : "{url path='admin/catalog/category'}",
|
||||
data : {
|
||||
id : $(this).data('id'),
|
||||
action : 'visibilityToggle'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
{loop name="menu-auth-order" type="auth" context="admin" roles="ADMIN" permissions="admin.orders.view"}
|
||||
<li class="dropdown {if $admin_current_location == 'customer'}active{/if}" id="orders_menu" data-toggle="dropdown">
|
||||
|
||||
<a href="#">{intl l="Orders"}<span class="caret"></span></a>
|
||||
<a href="#">{intl l="Orders"} <span class="caret"></span></a>
|
||||
|
||||
<ul class="dropdown-menu config_menu" role="menu">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user