[*] BO : #PSFV-865 - it is now possible to use drag and drop positions in custom controllers using HelperList

This commit is contained in:
tDidierjean
2012-04-18 15:48:38 +00:00
parent 0a9aaee6b9
commit 45ea9fdaae
14 changed files with 340 additions and 432 deletions
-319
View File
@@ -92,171 +92,6 @@ if (Tools::isSubmit('getAvailableFields') AND Tools::isSubmit('entity'))
die('['.implode(',', $jsonArray).']');
}
if (Tools::isSubmit('ajaxModulesPositions'))
{
$id_module = (int)(Tools::getValue('id_module'));
$id_hook = (int)(Tools::getValue('id_hook'));
$way = (int)(Tools::getValue('way'));
$positions = Tools::getValue(strval($id_hook));
$position = (is_array($positions)) ? array_search($id_hook.'_'.$id_module, $positions) : null;
$module = Module::getInstanceById($id_module);
if (Validate::isLoadedObject($module))
if ($module->updatePosition($id_hook, $way, $position))
die(true);
else
die('{"hasError" : true, "errors" : "Can not update module position"}');
else
die('{"hasError" : true, "errors" : "This module can not be loaded"}');
}
if (Tools::isSubmit('ajaxCategoriesPositions'))
{
$id_category_to_move = (int)(Tools::getValue('id_category_to_move'));
$id_category_parent = (int)(Tools::getValue('id_category_parent'));
$way = (int)(Tools::getValue('way'));
$positions = Tools::getValue('category');
if (is_array($positions))
foreach ($positions AS $key => $value)
{
$pos = explode('_', $value);
if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category_parent AND $pos[2] == $id_category_to_move))
{
$position = $key + 1;
break;
}
}
$category = new Category($id_category_to_move);
if (Validate::isLoadedObject($category))
{
if (isset($position) && $category->updatePosition($way, $position))
{
Hook::exec('actionCategoryUpdate');
die(true);
}
else
die('{"hasError" : true, errors : "Can not update categories position"}');
}
else
die('{"hasError" : true, "errors" : "This category can not be loaded"}');
}
if (Tools::isSubmit('ajaxCMSCategoriesPositions'))
{
$id_cms_category_to_move = (int)(Tools::getValue('id_cms_category_to_move'));
$id_cms_category_parent = (int)(Tools::getValue('id_cms_category_parent'));
$way = (int)(Tools::getValue('way'));
$positions = Tools::getValue('cms_category');
if (is_array($positions))
foreach ($positions AS $key => $value)
{
$pos = explode('_', $value);
if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_cms_category_parent AND $pos[2] == $id_cms_category_to_move))
{
$position = $key;
break;
}
}
$cms_category = new CMSCategory($id_cms_category_to_move);
if (Validate::isLoadedObject($cms_category))
{
if (isset($position) && $cms_category->updatePosition($way, $position))
die(true);
else
die('{"hasError" : true, "errors" : "Can not update cms categories position"}');
}
else
die('{"hasError" : true, "errors" : "This cms category can not be loaded"}');
}
if (Tools::isSubmit('ajaxCMSPositions'))
{
$id_cms = (int)(Tools::getValue('id_cms'));
$id_category = (int)(Tools::getValue('id_cms_category'));
$way = (int)(Tools::getValue('way'));
$positions = Tools::getValue('cms');
if (is_array($positions))
foreach ($positions AS $key => $value)
{
$pos = explode('_', $value);
if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND $pos[2] == $id_cms))
{
$position = $key;
break;
}
}
$cms = new CMS($id_cms);
if (Validate::isLoadedObject($cms))
{
if (isset($position) && $cms->updatePosition($way, $position))
die(true);
else
die('{"hasError" : true, "errors" : "Can not update cms position"}');
}
else
die('{"hasError" : true, "errors" : "This cms can not be loaded"}');
}
/* Modify product position in catalog */
if (Tools::isSubmit('ajaxProductsPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_product = (int)(Tools::getValue('id_product'));
$id_category = (int)(Tools::getValue('id_category'));
$positions = Tools::getValue('product');
if (is_array($positions))
foreach ($positions AS $position => $value)
{
// pos[1] = id_categ, pos[2] = id_product, pos[3]=old position
$pos = explode('_', $value);
if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND (int)$pos[2] === $id_product))
{
if ($product = new Product((int)$pos[2]))
if (isset($position) && $product->updatePosition($way, $position))
echo "ok position ".(int)$position." for product ".(int)$pos[2]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update product '. (int)$id_product . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This product ('.(int)$id_product.') can t be loaded"}';
break;
}
}
}
if (Tools::isSubmit('ajaxProductImagesPositions'))
{
$id_image = (int)(Tools::getValue('id_image'));
$way = (int)(Tools::getValue('way'));
$positions = Tools::getValue('imageTable');
if (is_array($positions))
foreach ($positions AS $key => $value)
{
$pos = explode('_', $value);
if ((isset($pos[1])) AND ($pos[1] == $id_image))
{
// +1 is added because images position range starts from 1 instead of 0 for other objects (products, categories...)
$position = ($key + 1);
break;
}
}
$image = new Image($id_image);
if (Validate::isLoadedObject($image))
{
if (isset($position) && $image->updatePosition($way, $position))
die(true);
else
die('{"hasError" : true, "errors" : "Cannot update image position"}');
}
else
die('{"hasError" : true, "errors" : "This image cannot be loaded"}');
}
if (Tools::isSubmit('ajaxProductPackItems'))
{
$jsonArray = array();
@@ -740,126 +575,6 @@ if (Tools::isSubmit('syncImapMail'))
die('{"hasError" : false, "errors" : ["'.$str_errors.$str_error_delete.'"]}');
}
/* Modify attribute position */
if (Tools::isSubmit('ajaxAttributesPositions'))
{
$way = (int)Tools::getValue('way');
$id_attribute = (int)Tools::getValue('id_attribute');
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
$positions = Tools::getValue('attribute');
if (is_array($positions))
foreach ($positions as $position => $value)
{
// pos[1] = id_attribute_group, pos[2] = id_attribute, pos[3]=old position
$pos = explode('_', $value);
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_attribute_group && (int)$pos[2] === $id_attribute))
{
if ($attribute = new Attribute((int)$pos[2]))
if (isset($position) && $attribute->updatePosition($way, $position))
echo "ok position ".(int)$position." for attribute ".(int)$pos[2]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update attribute '. (int)$id_attribute . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This attribute ('.(int)$id_attribute.') can t be loaded"}';
break;
}
}
}
/* Modify group attribute position */
if (Tools::isSubmit('ajaxGroupsAttributesPositions'))
{
$way = (int)Tools::getValue('way');
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
$positions = Tools::getValue('attribute_group');
$new_positions = array();
foreach($positions as $k => $v)
if (count(explode('_', $v)) == 4)
$new_positions[] = $v;
foreach ($new_positions as $position => $value)
{
// pos[1] = id_attribute_group, pos[2] = old position
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_attribute_group)
{
if ($group_attribute = new AttributeGroup((int)$pos[2]))
if (isset($position) && $group_attribute->updatePosition($way, $position))
echo "ok position ".(int)$position." for group attribute ".(int)$pos[2]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update group attribute '. (int)$id_attribute_group . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This group attribute ('.(int)$id_attribute_group.') can t be loaded"}';
break;
}
}
}
/* Modify feature position */
if (Tools::isSubmit('ajaxFeaturesPositions'))
{
$way = (int)Tools::getValue('way');
$id_feature = (int)Tools::getValue('id_feature');
$positions = Tools::getValue('feature');
$new_positions = array();
foreach($positions as $k => $v)
if (!empty($v))
$new_positions[] = $v;
foreach ($new_positions as $position => $value)
{
// pos[2] = id_feature, pos[3] = old position
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_feature)
{
if ($feature = new Feature((int)$pos[2]))
if (isset($position) && $feature->updatePosition($way, $position))
echo "ok position ".(int)$position." for feature ".(int)$pos[1]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update feature '. (int)$id_feature . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This feature ('.(int)$id_feature.') can t be loaded"}';
break;
}
}
}
/* Modify carrier position */
if (Tools::isSubmit('ajaxCarriersPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_carrier = (int)(Tools::getValue('id_carrier'));
$positions = Tools::getValue('carrier');
foreach ($positions as $position => $value)
{
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_carrier)
{
if ($carrier = new Carrier((int)$pos[2]))
if (isset($position) && $carrier->updatePosition($way, $position))
echo "ok position ".(int)$position." for carrier ".(int)$pos[1]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update carrier '. (int)$id_carrier . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This carrier ('.(int)$id_carrier.') can t be loaded"}';
break;
}
}
}
if (Tools::isSubmit('searchCategory'))
{
$q = Tools::getValue('q');
@@ -912,37 +627,3 @@ if (Tools::isSubmit('getZones'))
$array = array('hasError' => false, 'errors' => '', 'data' => $html);
die(Tools::jsonEncode($html));
}
/* Modify carrier position */
if (Tools::isSubmit('ajaxTabsPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_tab = (int)(Tools::getValue('id_tab'));
$positions = Tools::getValue('tab');
// when changing positions in a tab sub-list, the first array value is empty and needs to be removed
if (!$positions[0])
{
unset($positions[0]);
// reset indexation from 0
$positions = array_merge($positions);
}
foreach ($positions as $position => $value)
{
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_tab)
{
if ($tab = new Tab((int)$pos[2]))
if (isset($position) && $tab->updatePosition($way, $position))
echo "ok position ".(int)$position." for tab ".(int)$pos[1]."\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update tab '. (int)$id_tab . ' to position '.(int)$position.' "}';
else
echo '{"hasError" : true, "errors" : "This tab ('.(int)$id_tab.') can t be loaded"}';
break;
}
}
}
@@ -65,6 +65,7 @@
var token_admin_orders = '{getAdminToken tab='AdminOrders' slashes=1 }';
var token_admin_customers = '{getAdminToken tab='AdminCustomers' slashes=1 }';
var token_admin_customer_threads = '{getAdminToken tab='AdminCustomerThreads' slashes=1 }';
var currentIndex = '{$currentIndex}';
</script>
{/if}