[*] 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
@@ -430,7 +430,6 @@ class AdminAttributesGroupsControllerCore extends AdminController
return;
}
// toolbar (save, cancel, new, ..)
$this->initToolbar();
if ($this->display == 'edit' || $this->display == 'add')
@@ -544,7 +543,7 @@ class AdminAttributesGroupsControllerCore extends AdminController
protected function setTypeAttribute()
{
if (Tools::getValue('id_attribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute') || Tools::isSubmit('submitBulkdeleteattribute'))
if (Tools::getValue('updateattribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute') || Tools::isSubmit('submitBulkdeleteattribute'))
{
$this->table = 'attribute';
$this->className = 'Attribute';
@@ -577,11 +576,8 @@ class AdminAttributesGroupsControllerCore extends AdminController
return;
// If it's an attribute, load object Attribute()
if (Tools::getValue('id_attribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute'))
if (Tools::getValue('updateattribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute'))
{
/* Hook */
Hook::exec('actionObjectAttributeAddBefore');
// Override var of Controller
$this->table = 'attribute';
$this->className = 'Attribute';
@@ -609,6 +605,7 @@ class AdminAttributesGroupsControllerCore extends AdminController
}
else if (Tools::isSubmit('submitAddattribute'))
{
Hook::exec('actionObjectAttributeAddBefore');
$this->action = 'save';
$id_attribute = (int)Tools::getValue('id_attribute');
// Adding last position to the attribute if not exist
@@ -627,9 +624,6 @@ class AdminAttributesGroupsControllerCore extends AdminController
}
else
{
/* Hook */
Hook::exec('actionObjectAttributeGroupAddBefore');
if (Tools::getValue('submitDel'.$this->table))
{
if ($this->tabAccess['delete'] === '1')
@@ -651,6 +645,7 @@ class AdminAttributesGroupsControllerCore extends AdminController
}
else if (Tools::isSubmit('submitAdd'.$this->table))
{
Hook::exec('actionObjectAttributeGroupAddBefore');
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
// Adding last position to the attribute if not exist
if ($id_attribute_group <= 0)
@@ -727,4 +722,63 @@ class AdminAttributesGroupsControllerCore extends AdminController
return $result;
}
/* Modify group attribute position */
public function ajaxProcessUpdateGroupsPositions()
{
$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 = 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 attribute position */
public function ajaxProcessUpdateAttributesPositions()
{
$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 = 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;
}
}
}
}
@@ -649,6 +649,32 @@ class AdminCarriersControllerCore extends AdminController
if ($list['name'] == '0')
$this->_list[$key]['name'] = Configuration::get('PS_SHOP_NAME');
}
public function ajaxProcessUpdatePositions()
{
$way = (int)(Tools::getValue('way'));
$id_carrier = (int)(Tools::getValue('id'));
$positions = Tools::getValue($this->table);
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;
}
}
}
}
@@ -651,6 +651,37 @@ class AdminCategoriesControllerCore extends AdminController
INSERT INTO '._DB_PREFIX_.$this->table.'_'.$type.' (`'.pSQL($this->identifier).'`, `id_'.$type.'`)
VALUES '.pSQL($insert));
}
public function ajaxProcessUpdatePositions()
{
$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]) && isset($pos[2])) && ($pos[1] == $id_category_parent && $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"}');
}
}
@@ -138,6 +138,8 @@ class AdminCmsContentControllerCore extends AdminController
|| (Tools::isSubmit('statuscms_category') && Tools::isSubmit('id_cms_category'))
|| (Tools::isSubmit('position') && Tools::isSubmit('id_cms_category_to_move')))
$this->adminCMSCategories->postProcess();
parent::postProcess();
}
public function setMedia()
@@ -146,4 +148,60 @@ class AdminCmsContentControllerCore extends AdminController
$this->addJqueryUi('ui.widget');
$this->addJqueryPlugin('tagify');
}
public function ajaxProcessUpdateCmsPositions()
{
$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]) && isset($pos[2])) && ($pos[1] == $id_category && $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"}');
}
public function ajaxProcessUpdateCmsCategoriesPositions()
{
$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]) && isset($pos[2])) && ($pos[1] == $id_cms_category_parent && $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"}');
}
}
@@ -471,4 +471,33 @@ class AdminFeaturesControllerCore extends AdminController
}
}
public function ajaxProcessUpdatePositions()
{
$way = (int)Tools::getValue('way');
$id_feature = (int)Tools::getValue('id');
$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 = 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, $id_feature))
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;
}
}
}
}
@@ -1100,5 +1100,4 @@ class AdminModulesControllerCore extends AdminController
}
$smarty->assign($tpl_vars);
}
}
@@ -391,4 +391,21 @@ class AdminModulesPositionsControllerCore extends AdminController
return $content;
}
public function ajaxProcessUpdatePositions()
{
$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"}');
}
}
@@ -4178,4 +4178,31 @@ class AdminProductsControllerCore extends AdminController
LIMIT '.(int)$limit);
die(Tools::jsonEncode($result));
}
public function ajaxProcessUpdatePositions()
{
$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 = explode('_', $value);
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_category && (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;
}
}
}
}
+33
View File
@@ -281,4 +281,37 @@ class AdminTabsControllerCore extends AdminController
return;
@rename(_PS_IMG_DIR_.'t/'.$obj->id.'.gif', _PS_IMG_DIR_.'t/'.$obj->class_name.'.gif');
}
public function ajaxProcessUpdatePositions()
{
$way = (int)(Tools::getValue('way'));
$id_tab = (int)(Tools::getValue('id'));
$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;
}
}
}
}