[*] BO : Product attributes are now sortable.

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8639 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
vChabot
2011-09-19 13:11:00 +00:00
parent 40e0f3dca5
commit a88c90fbe1
15 changed files with 232 additions and 55 deletions
+29
View File
@@ -794,3 +794,32 @@ if (Tools::isSubmit('syncImapMail'))
imap_close($mbox);
die('{"hasError" : false, "errors" : '.$str_errors.'}');
}
/* Modify attribute position */
if (array_key_exists('ajaxAttributesPositions', $_POST))
{
$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_'.(int)(Tools::getValue('id_attribute_group')));
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]) AND isset($pos[2])) AND ($pos[1] == $id_attribute_group AND (int)$pos[2] === $id_attribute))
{
if ($attribute = new Attribute((int)$pos[2]))
if (isset($position) && $attribute->updatePosition($way, $position))
echo "ok position $position for attribute $pos[2]\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update attribute '. $id_attribute . ' to position '.$position.' "}';
else
echo '{"hasError" : true, "errors" : "This attribute ('.$id_attribute.') can t be loaded"}';
break;
}
}
}
+1 -1
View File
@@ -101,7 +101,7 @@ class AdminAttributeGenerator extends AdminTab
private static function displayAndReturnAttributeJs()
{
$attributes = Attribute::getAttributes($this->context->language->id, true);
$attributes = Attribute::getAttributes(Context::getContext()->language->id, true);
$attributeJs = array();
foreach ($attributes AS $k => $attribute)
$attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
+12 -1
View File
@@ -155,8 +155,19 @@ class AdminAttributes extends AdminTab
}
elseif (Tools::isSubmit('submitAddattribute'))
{
$id_attribute = (int)Tools::getValue('id_attribute');
// Adding last position to the attribute if not exist
if ($id_attribute <= 0)
{
$sql = 'SELECT `position`+1
FROM `'._DB_PREFIX_.'attribute`
WHERE id_attribute_group = '.(int)Tools::getValue('id_attribute_group').'
ORDER BY position DESC';
// set the position of the new attribute in $_POST for postProcess() method
$_POST['position'] = DB::getInstance()->getValue($sql);
}
// clean \n\r characters
foreach($_POST as $key => $value)
foreach ($_POST as $key => $value)
if (preg_match('/^name_/Ui', $key))
$_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value));
parent::postProcess();
+81 -34
View File
@@ -109,11 +109,24 @@ class AdminAttributesGroups extends AdminTab
if ($this->_list === false)
Tools::displayError('No elements found');
$this->displayListHeader();
$this->displayListHeader($this->token);
echo '<input type="hidden" name="groupid" value="0">';
if (!sizeof($this->_list))
echo '<tr><td class="center" colspan="'.sizeof($this->_list).'">'.$this->l('No elements found').'</td></tr>';
//$this->displayListContent($this->token);
echo '
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
<script type="text/javascript">
var token = \''.$this->token.'\';
var come_from = \''.$this->table.'\';
var alternate = \''.($this->_orderWay == 'DESC' ? '1' : '0' ).'\';
</script>
<script type="text/javascript" src="../js/admin-dnd.js"></script>
';
$irow = 0;
foreach ($this->_list AS $tr)
@@ -123,39 +136,10 @@ class AdminAttributesGroups extends AdminTab
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').'>
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center"><input type="checkbox" name="'.$this->table.'Box[]" value="'.$id.'" class="noborder" /></td>
<td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#attributes_'.$id.'\').slideToggle();">'.$tr['name'].'</td>
<td style="vertical-align: top; padding: 4px 0 4px 0; width: 340px">
<div id="attributes_'.$id.'" style="display: none">
<table class="table" cellpadding="0" cellspacing="0">
<tr>
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'attribute'.$id.'Box[]\', this.checked)" /></th>
<th width="100%">'.$this->l('Attribute').'</th>
<th>'.$this->l('Actions').'</th>
</tr>';
$attributes = AttributeGroup::getAttributes(Context::getContext()->language->id, $id);
foreach ($attributes AS $attribute)
{
echo '
<tr>
<td class="center"><input type="checkbox" name="attribute'.$id.'Box[]" value="'.$attribute['id_attribute'].'" class="noborder" /></td>
<td>
'.($tr['is_color_group'] ? '<div style="float: left; width: 18px; height: 12px; border: 1px solid #996633; background-color: '.$attribute['color'].'; margin-right: 4px;"></div>' : '')
.$attribute['name'].'
</td>
<td class="center">
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&updateattribute&token='.$this->token.'">
<img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>&nbsp;
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&deleteattribute&token='.$this->token.'"
onclick="return confirm(\''.$this->l('Delete attribute', __CLASS__, true, false).' : '.$attribute['name'].'?\');">
<img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
</td>
</tr>';
}
<td style="vertical-align: top; padding: 4px 0 4px 0; width: 340px">';
$this->displayListAttributes($id, $irow, $tr);
echo '
</table>
<p><input type="Submit" class="button" name="submitDelattribute" value="'.$this->l('Delete selection').'"
onclick="changeFormParam(this.form, \''.self::$currentIndex.'\', '.$id.'); return confirm(\''.$this->l('Delete selected items?', __CLASS__, true, false).'\');" /></p>
</div>
</td>';
</td>';
echo '
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center">
@@ -167,7 +151,7 @@ class AdminAttributesGroups extends AdminTab
</tr>';
}
$this->displayListFooter();
$this->displayListFooter($this->token);
}
public function displayForm($isMainTab = true)
@@ -235,6 +219,69 @@ class AdminAttributesGroups extends AdminTab
</fieldset>
</form>';
}
/**
* displayListAttributes
*
* Display a list of attributes from a group
*/
public function displayListAttributes($id, $irow, $tr)
{
echo '
<div id="attributes_'.$id.'" style="display: none">
<table class="attribute table tableDnD" cellpadding="0" cellspacing="0" id="attribute_'.$id.'">
<thead>
<tr class="nodrag nodrop">
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'attribute'.$id.'Box[]\', this.checked)" /></th>
<th width="100%">'.$this->l('Attribute').'</th>
<th>'.$this->l('Position').'</th>
<th>'.$this->l('Actions').'</th>
</tr>
</thead>
<tbody>';
$attributes = AttributeGroup::getAttributes(Context::getContext()->language->id, $id);
$nbrow = 0;
foreach ($attributes AS $attribute)
{
$class = ($irow % 2) ? '': 'not_';
echo '
<tr'.($nbrow++ % 2 ? ' class="'.$class.'alt_row"' : '').' id="tr_'.$attribute['id_attribute_group'].'_'.$attribute['id_attribute'].'_'.$attribute['position'].'">
<td class="center"><input type="checkbox" name="attribute'.$id.'Box[]" value="'.$attribute['id_attribute'].'" class="noborder" /></td>
<td>
'.($tr['is_color_group'] ? '<div style="float: left; width: 18px; height: 12px; border: 1px solid #996633; background-color: '.$attribute['color'].'; margin-right: 4px;"></div>' : '')
.$attribute['name'].'
</td>
<td class="dragHandle">';
echo '<a'.(!($attribute['position'] != $attributes[sizeof($attributes) - 1]['position']) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&id_attribute_group='.(int)($attribute['id_attribute_group']).'&id_attribute='.$attribute['id_attribute'].'
&way=1&position='.(int)($attribute['position'] + 1).'&token='.$this->token.'">
<img src="../img/admin/down.gif"
alt="'.$this->l('Down').'" title="'.$this->l('Down').'" /></a>';
echo '<a'.(!($attribute['position'] != $attributes[0]['position']) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&id_attribute_group='.(int)($attribute['id_attribute_group']).'&&id_attribute='.$attribute['id_attribute'].'
&way=0&position='.(int)($attribute['position'] - 1).'&token='.$this->token.'">
<img src="../img/admin/up.gif"
alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a>';
echo'
</td>
<td class="center">
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&updateattribute&token='.$this->token.'">
<img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>&nbsp;
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&deleteattribute&token='.$this->token.'"
onclick="return confirm(\''.$this->l('Delete attribute', __CLASS__, true, false).' : '.$attribute['name'].'?\');">
<img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
</td>
</tr>';
}
echo '
</tbody>
</table>
<p><input type="Submit" class="button" name="submitDelattribute" value="'.$this->l('Delete selection').'"
onclick="changeFormParam(this.form, \''.self::$currentIndex.'\', '.$id.'); return confirm(\''.$this->l('Delete selected items?', __CLASS__, true, false).'\');" /></p>
</div>';
}
}
+2 -2
View File
@@ -3461,7 +3461,7 @@ class AdminProducts extends AdminTab
</tr>
<tr>
<td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left" style="width:150px">'.$this->l('Available date:').'</td>
<td style="padding-bottom:5px;"><input id="available_date" name="available_date" value="'.(($this->getFieldValue($obj, 'available_date')!=0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($obj, 'available_date'), $language['id_lang']))) : '00-00-0000').'" style="text-align: center;" type="text" />
<td style="padding-bottom:5px;"><input id="available_date" name="available_date" value="'.(($this->getFieldValue($obj, 'available_date')!=0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($obj, 'available_date'), $language['id_lang']))) : '0000-00-00').'" style="text-align: center;" type="text" />
<p>'.$this->l('The available date when this product is out of stock').'</p>
</td>
</tr>';
@@ -3567,7 +3567,7 @@ class AdminProducts extends AdminTab
$list = rtrim($list, ', ');
$jsList = rtrim($jsList, ', ');
$attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false;
$available_date = ($product_attribute['available_date'] != 0) ? date('Y-m-j', strtotime($product_attribute['available_date'])) : '00-00-0000';
$available_date = ($product_attribute['available_date'] != 0) ? date('Y-m-j', strtotime($product_attribute['available_date'])) : '0000-00-00';
echo '
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').($product_attribute['default_on'] ? ' style="background-color:#D1EAEF"' : '').'>
<td>'.stripslashes($list).'</td>
+1
View File
@@ -23,6 +23,7 @@ input.button[disabled=disabled]:hover{background-color:#FFF6D3}
.table tr td{border-bottom:1px solid #DEDEDE;color:#963;font-size:.9em;height:23px;padding:0 4px 0 6px}
.table tr.last td{border-bottom:none}
.alt_row{background-color:#EFEFEF}
.not_alt_row{background-color:#FFF}
.path_bar{background-color:#E2EBEE;border:1px solid #999999;font-family:Trebuchet,Arial,Helvetica,sans-serif;font-size:13px;margin-bottom:20px;padding:5px}
.path_bar a{font-weight:700}
.cat_bar{background-color:#F4E8CD;border:1px solid #999999;font-family:Trebuchet,Arial,Helvetica,sans-serif;font-size:12px;font-weight:700;margin-bottom:20px;padding:5px}