Merge branch 'master' of github.com:thelia/thelia

This commit is contained in:
Manuel Raynaud
2013-08-08 10:39:03 +02:00
6 changed files with 112 additions and 35 deletions

View File

@@ -235,6 +235,29 @@ class Category implements EventSubscriberInterface
$event->stopPropagation(); $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. * Returns an array of event names this subscriber listens to.
* *
@@ -261,6 +284,8 @@ class Category implements EventSubscriberInterface
"action.createCategory" => array("create", 128), "action.createCategory" => array("create", 128),
"action.modifyCategory" => array("modify", 128), "action.modifyCategory" => array("modify", 128),
"action.deleteCategory" => array("delete", 128), "action.deleteCategory" => array("delete", 128),
);
"action.toggleCategoryVisibility" => array("toggleVisibility", 128),
);
} }
} }

View File

@@ -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 $templateName the complete template name, with extension
* @param array $args the template arguments * @param array $args the template arguments

View File

@@ -25,20 +25,10 @@ namespace Thelia\Admin\Controller;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Security\Exception\AuthenticationException;
class CategoryController extends BaseAdminController { class CategoryController extends BaseAdminController {
public function indexAction() protected function createNewCategory($args) {
{
// Show top level categories and products
$args = array(
'action' => 'browse',
'current_category_id' => 0
);
return $this->browseCategory($args);
}
public function createNewCategory($args) {
$this->checkAuth("ADMIN", "admin.category.create"); $this->checkAuth("ADMIN", "admin.category.create");
@@ -48,14 +38,14 @@ class CategoryController extends BaseAdminController {
return $this->render('categories', $args); return $this->render('categories', $args);
} }
public function editCategory($args) { protected function editCategory($args) {
$this->checkAuth("AMIN", "admin.category.edit"); $this->checkAuth("AMIN", "admin.category.edit");
return $this->render('edit_category', $args); return $this->render('edit_category', $args);
} }
public function deleteCategory($category_id) { protected function deleteCategory($category_id) {
$this->checkAuth("AMIN", "admin.category.delete"); $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"); $this->checkAuth("AMIN", "admin.catalog.view");
return $this->render('categories', $args); 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() public function processAction()
{ {
// Get the current action // Get the current action
@@ -91,21 +110,24 @@ class CategoryController extends BaseAdminController {
); );
try { try {
// Browse categories switch($action) {
if ($action == 'browse') { case 'browse' : // Browse categories
return $this->browseCategory($args); return $this->browseCategory($args);
}
// Create a new category case 'create' : // Create a new category
else if ($action == 'create') { return $this->createNewCategory($args);
return $this->createNewCategory($args);
} case 'edit' : // Edit an existing category
// Edit an existing category return $this->editCategory($args);
else if ($action == 'edit') {
return $this->editCategory($args); case 'delete' : // Delete an existing category
} return $this->deleteCategory($id);
// Delete an existing category
else if ($action == 'delete') { case 'visibilityToggle' : // Toggle visibility
return $this->deleteCategory($id); return $this->visibilityToggle($id);
case 'changePosition' : // Change position
return $this->changePosition($args);
} }
} }
catch(AuthenticationException $ex) { catch(AuthenticationException $ex) {

View File

@@ -109,6 +109,12 @@ final class TheliaEvents
*/ */
const AFTER_DELETECATEGORY = "action.after_deletecategory"; const AFTER_DELETECATEGORY = "action.after_deletecategory";
/**
* Sent just after a successful change of a category in the database.
*/
const AFTER_CHANGECATEGORY = "action.after_changecategory";
/** /**
* sent when a new existing cat id duplicated. This append when current customer is different from current cart * sent when a new existing cat id duplicated. This append when current customer is different from current cart
*/ */
@@ -123,5 +129,4 @@ final class TheliaEvents
* sent when a cart item is modify * sent when a cart item is modify
*/ */
const CART_MODIFYITEM = "cart.modifyItem"; const CART_MODIFYITEM = "cart.modifyItem";
} }

View File

@@ -57,7 +57,13 @@
{module_include location='category_list_row'} {module_include location='category_list_row'}
<td> <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>
<td> <td>
@@ -222,6 +228,17 @@ $(function() {
$('#'+'delete-category-id').val($(this).data('id')); $('#'+'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> </script>

View File

@@ -88,7 +88,7 @@
{loop name="menu-auth-order" type="auth" context="admin" roles="ADMIN" permissions="admin.orders.view"} {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"> <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"> <ul class="dropdown-menu config_menu" role="menu">