// fix adminProducts > images

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10281 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mMarinetti committed 2011-11-18 16:42:51 +00:00
1 parent c7310f3899
commit d6ef55b5ed
3 files changed
+101 -81

No files matched your search

+49 -37
View File
@@ -20,26 +20,31 @@
<ul id="listImage"></ul> <ul id="listImage"></ul>
<script type="text/javascript">var upbutton = "{l s='Upload a file'}"; </script> <script type="text/javascript">var upbutton = "{l s='Upload a file'}"; </script>
<script type="text/javascript"> <script type="text/javascript">
function deleteImg(id) $(document).ready(function(){
$('.delete_product_image').die().live('click', function(e)
{ {
var conf = confirm("{l s='Are you sure?'}"); e.preventDefault();
if (conf) id = $(this).parent().parent().attr('id').substr(3);
$.post(
"ajax-tab.php", if (confirm("{l s='Are you sure?'}"))
$.post("ajax-tab.php",
{ {
action: "deleteImage", action: "deleteProductImage",
id_image:id, id_image:id,
id_product : "{$product->id}", id_product : "{$product->id}",
id_category : "{$id_category_default}", id_category : "{$id_category_default}",
token : "{$token}", token : "{$token}",
tab : "AdminProducts", tab : "AdminProducts",
ajax : 1, ajax : 1,
updateproduct : 1}, },
function (data) { function (data)
{
try{
data = $.parseJSON(data);
if (data) if (data)
{ {
cover = 0; cover = 0;
if(data.imageDeleted) if(data.status == 'ok')
{ {
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif") if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
cover = 1; cover = 1;
@@ -50,11 +55,16 @@
$("#countImage").html(parseInt($("#countImage").html()) - 1); $("#countImage").html(parseInt($("#countImage").html()) - 1);
// refreshImagePositions($("#imageTable")); refreshImagePositions($("#imageTable"));
} }
}
catch(e){
alert("TECHNICAL ERROR");
}
}
);
});
}); });
return false;
}
function delQueue(id) function delQueue(id)
{ {
@@ -73,8 +83,7 @@
token : "{$token}", token : "{$token}",
tab : "AdminProducts", tab : "AdminProducts",
updateproduct : 1, updateproduct : 1,
addImage : 1, action : 'addImage',
ajaxMode : 1,
ajax: 1, ajax: 1,
}, },
onComplete: function(id, fileName, responseJSON){ onComplete: function(id, fileName, responseJSON){
@@ -99,9 +108,9 @@
nbfile = 0; nbfile = 0;
filecheck = 0; filecheck = 0;
} }
if (responseJSON.success) if (responseJSON.status == 'ok')
{ {
$("#imageTable tr:last").after(responseJSON.success); $("#imageTable tr:last").after(responseJSON.html);
$("#countImage").html(parseInt($("#countImage").html()) + 1); $("#countImage").html(parseInt($("#countImage").html()) + 1);
$("#img" + id).remove(); $("#img" + id).remove();
} }
@@ -152,29 +161,9 @@
<th style="width: 100px;">{l s='Image'}</th> <th style="width: 100px;">{l s='Image'}</th>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>{l s='Position'}</th> <th>{l s='Position'}</th>
{if $shops}
<script type="text/javascript">
$(document).ready(function() {
$('.image_shop').change(function() {
$.post("ajax-tab.php",
{
updateProductImageShopAsso: 1,
id_image:$(this).attr("name"),
id_shop: $(this).val(),
active:$(this).attr("checked"),
id_product : "{$product->id}",
id_category : "{$product->id_category_default}",
token : "{$token}",
tab : "AdminProducts",
updateproduct : 1,
});
});
});
</script>
{foreach from=$shops item=shop} {foreach from=$shops item=shop}
<th>{$shop.name}</th> <th>{$shop.name}</th>
{/foreach} {/foreach}
{/if}
<th>{l s='Cover'}</th> <th>{l s='Cover'}</th>
<th>{l s='Action'}</th> <th>{l s='Action'}</th>
@@ -196,16 +185,19 @@
<img src="../img/admin/down.gif" alt="" border="0"> <img src="../img/admin/down.gif" alt="" border="0">
</a> </a>
</td> </td>
{if $shops}
{foreach from=$shops item=shop} {foreach from=$shops item=shop}
<td class="center"> <td class="center">
<input type="checkbox" class="image_shop" name="{$image->id_image}" value="{$shop.id_shop}" {if $image->isAssociatedToShop($shop.id_shop)}checked="checked"{/if} /> <input type="checkbox" class="image_shop" name="{$image->id_image}" value="{$shop.id_shop}" {if $image->isAssociatedToShop($shop.id_shop)}checked="checked"{/if} />
</td> </td>
{/foreach} {/foreach}
{/if}
<td class="center"><a href="{$currentIndex}&amp;id_image={$image->id_image}&amp;coverImage&amp;token={$token}"> <td class="center"><a href="{$currentIndex}&amp;id_image={$image->id_image}&amp;coverImage&amp;token={$token}">
<img class="covered" src="../img/admin/{if $image->cover}enabled.gif{else}forbbiden.gif{/if}" alt="e" /></a> <img class="covered" src="../img/admin/{if $image->cover}enabled.gif{else}forbbiden.gif{/if}" alt="e" /></a>
</td> </td>
<td class="center"> <td class="center">
<a href="#" onclick="deleteImg('{$image->id_image}');"> <a href="#" class="delete_product_image" >
<img src="../img/admin/delete.gif" alt="{l s='Delete this image'}" title="{l s='Delete this image'}" /> <img src="../img/admin/delete.gif" alt="{l s='Delete this image'}" title="{l s='Delete this image'}" />
</a> </a>
</td> </td>
@@ -218,3 +210,23 @@
</table> </table>
</div> </div>
{if $shops}
<script type="text/javascript">
$(document).ready(function() {
$('.image_shop').change(function() {
$.post("ajax-tab.php",
{
updateProductImageShopAsso: 1,
id_image:$(this).attr("name"),
id_shop: $(this).val(),
active:$(this).attr("checked"),
id_product : "{$product->id}",
id_category : "{$product->id_category_default}",
token : "{$token}",
tab : "AdminProducts",
updateproduct : 1,
});
});
});
</script>
{/if}
+5
View File
@@ -919,7 +919,9 @@ class AdminControllerCore extends Controller
$this->object = new $this->className($id); $this->object = new $this->className($id);
if (Validate::isLoadedObject($this->object)) if (Validate::isLoadedObject($this->object))
return $this->object; return $this->object;
// throw exception
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
return false;
} }
else if ($opt) else if ($opt)
{ {
@@ -927,7 +929,10 @@ class AdminControllerCore extends Controller
return $this->object; return $this->object;
} }
else else
{
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)'); $this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
return false;
}
$this->content = $this->displayErrors(); $this->content = $this->displayErrors();
return $this->object; return $this->object;
+47 -44
View File
@@ -460,29 +460,9 @@ class AdminProductsController extends AdminController
{ {
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
{ {
/* Delete product image */
if (isset($_GET['deleteImage']) || $this->action == 'deleteImage')
{
$image->delete();
if (!Image::getCover($image->id_product))
{
$first_img = Db::getInstance()->getRow('
SELECT `id_image` FROM `'._DB_PREFIX_.'image`
WHERE `id_product` = '.(int)($image->id_product));
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'image`
SET `cover` = 1
WHERE `id_image` = '.(int)($first_img['id_image']));
}
@unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg');
@unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg');
if (!$this->ajax)
Tools::redirectAdmin($currentIndex.'&id_product='.$image->id_product.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&add'.$this->table.'&tabs=1'.'&token='.($token ? $token : $this->token));
}
/* Update product image/legend */ /* Update product image/legend */
else if (isset($_GET['editImage'])) // @todo : move in processEditProductImage
if (isset($_GET['editImage']))
{ {
if ($image->cover) if ($image->cover)
$_POST['cover'] = 1; $_POST['cover'] = 1;
@@ -931,14 +911,12 @@ class AdminProductsController extends AdminController
//Manage suppliers //Manage suppliers
else if (Tools::isSubmit('submitSupplierReferences')) else if (Tools::isSubmit('submitSupplierReferences'))
$this->postProcessFormSupplierReferences(); $this->postProcessFormSupplierReferences();
else
parent::postProcess(true); parent::postProcess(true);
} }
public function ajaxPreProcess() // @todo rename to processaddproductimage
{ public function ajaxProcessAddImage()
$this->action = Tools::getValue('action');
if (Tools::getValue('addImage') !== false)
{ {
self::$currentIndex = 'index.php?tab=AdminProducts'; self::$currentIndex = 'index.php?tab=AdminProducts';
$allowedExtensions = array("jpeg", "gif", "png", "jpg"); $allowedExtensions = array("jpeg", "gif", "png", "jpg");
@@ -956,12 +934,16 @@ class AdminProductsController extends AdminController
$images = Image::getImages($this->context->language->id, $obj->id); $images = Image::getImages($this->context->language->id, $obj->id);
$imagesTotal = Image::getImagesTotal($obj->id); $imagesTotal = Image::getImagesTotal($obj->id);
$html = $this->getLineTableImage($result['success'], $imagesTotal + 1, $this->token, $shops); $html = $this->getLineTableImage($result['success'], $imagesTotal + 1, $this->token, $shops);
die(Tools::jsonEncode(array("success" => $html))); die($html);
} }
else else
die(Tools::jsonEncode($result)); die(Tools::jsonEncode($result));
} }
public function ajaxPreProcess()
{
$this->action = Tools::getValue('action');
if (Tools::getValue('updateProductImageShopAsso')) if (Tools::getValue('updateProductImageShopAsso'))
{ {
if ($id_image = (int)Tools::getValue('id_image') && $id_shop = (int)Tools::getValue('id_shop')) if ($id_image = (int)Tools::getValue('id_image') && $id_shop = (int)Tools::getValue('id_shop'))
@@ -970,15 +952,13 @@ class AdminProductsController extends AdminController
else else
die(Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'image_shop WHERE `id_image`='.(int)$id_image.' && `id_shop`='.(int)$id_shop)); die(Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'image_shop WHERE `id_image`='.(int)$id_image.' && `id_shop`='.(int)$id_shop));
} }
} }
public function ajaxProcessDeleteImage() public function ajaxProcessDeleteProductImage()
{
/* Delete product image */
if (isset($_GET['deleteProductImage']) || $this->action == 'deleteProductImage')
{ {
if (false)
{
$image = new Image((int)Tools::getValue('id_image')); $image = new Image((int)Tools::getValue('id_image'));
$image->delete(); $image->delete();
if (!Image::getCover($image->id_product)) if (!Image::getCover($image->id_product))
@@ -986,16 +966,18 @@ if (false)
$first_img = Db::getInstance()->getRow(' $first_img = Db::getInstance()->getRow('
SELECT `id_image` FROM `'._DB_PREFIX_.'image` SELECT `id_image` FROM `'._DB_PREFIX_.'image`
WHERE `id_product` = '.(int)($image->id_product)); WHERE `id_product` = '.(int)($image->id_product));
Db::getInstance()->execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'image` UPDATE `'._DB_PREFIX_.'image`
SET `cover` = 1 SET `cover` = 1
WHERE `id_image` = '.(int)($first_img['id_image'])); WHERE `id_image` = '.(int)($first_img['id_image']));
} }
@unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg'); @unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg');
@unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg'); @unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg');
if (!$this->ajax)
Tools::redirectAdmin($currentIndex.'&id_product='.$image->id_product.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&add'.$this->table.'&tabs=1'.'&token='.($token ? $token : $this->token));
else
$this->content = '{"status":"ok"}';
} }
$this->content = '{deleted:1}';
die("deleted");
} }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to) protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to)
@@ -1540,10 +1522,14 @@ if (false)
if (Tools::getValue('id_product') || ((Tools::isSubmit('submitAddproduct') OR Tools::isSubmit('submitAddproductAndPreview') OR Tools::isSubmit('submitAddproductAndStay') OR Tools::isSubmit('submitSpecificPricePriorities') OR Tools::isSubmit('submitPriceAddition') OR Tools::isSubmit('submitPricesModification')) AND sizeof($this->_errors)) OR Tools::isSubmit('updateproduct') OR Tools::isSubmit('addproduct')) if (Tools::getValue('id_product') || ((Tools::isSubmit('submitAddproduct') OR Tools::isSubmit('submitAddproductAndPreview') OR Tools::isSubmit('submitAddproductAndStay') OR Tools::isSubmit('submitSpecificPricePriorities') OR Tools::isSubmit('submitPriceAddition') OR Tools::isSubmit('submitPricesModification')) AND sizeof($this->_errors)) OR Tools::isSubmit('updateproduct') OR Tools::isSubmit('addproduct'))
{ {
$this->fields_form = array(); $this->fields_form = array();
if (empty($this->action) || !method_exists($this, 'initForm'.$this->action)) if (empty($this->action))
$this->action = 'Informations'; $this->action = 'Informations';
if(method_exists($this, 'initForm'.$this->action))
$this->tpl_form = 'products/'.strtolower($this->action).'.tpl'; $this->tpl_form = 'products/'.strtolower($this->action).'.tpl';
if ($this->ajax) if ($this->ajax)
{ {
$this->display = 'edit'; $this->display = 'edit';
@@ -1782,7 +1768,8 @@ if (false)
*/ */
public function initForm() public function initForm()
{ {
$product = $this->object = new Product((int)(Tools::getValue('id_product'))); if(!method_exists($this, 'initForm'.$this->action))
return "";
// getLanguages init this->_languages // getLanguages init this->_languages
$this->getLanguages(); $this->getLanguages();
$languages = $this->_languages; $languages = $this->_languages;
@@ -1804,9 +1791,12 @@ if (false)
$this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label; $this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label;
// let's calculate this once for all // let's calculate this once for all
if (!($obj = $this->loadObject(true))) if (!Validate::isLoadedObject($this->object) && Tools::getValue('id_product'))
throw new PrestashopException('object not loaded'); $this->_errors[] = 'Unable to load object';
$this->_displayDraftWarning($obj->active); // throw new PrestashopException('object not loaded');
else
{
$this->_displayDraftWarning($this->object->active);
$this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage); $this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage);
$this->tpl_form_vars['product'] = $this->object; $this->tpl_form_vars['product'] = $this->object;
if ($this->ajax) if ($this->ajax)
@@ -1814,6 +1804,7 @@ if (false)
throw new PrestashopException('custom_form empty for action '.$this->action); throw new PrestashopException('custom_form empty for action '.$this->action);
else else
return $this->tpl_form_vars['custom_form']; return $this->tpl_form_vars['custom_form'];
}
return parent::initForm(); return parent::initForm();
} }
@@ -2470,6 +2461,7 @@ if (false)
$cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute'); $cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute');
$data->assign('feature_shop_active', Shop::isFeatureActive()); $data->assign('feature_shop_active', Shop::isFeatureActive());
// @todo : uses the helperform
$data->assign('displayAssoShop', $this->displayAssoShop()); $data->assign('displayAssoShop', $this->displayAssoShop());
$product_props = array(); $product_props = array();
@@ -3255,10 +3247,21 @@ if (false)
$html .= ' $html .= '
<td class="center"><a href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&coverImage&token='.($token ? $token : $this->token).'"><img class="covered" src="../img/admin/'.($image['cover'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></a></td> <td class="center"><a href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&coverImage&token='.($token ? $token : $this->token).'"><img class="covered" src="../img/admin/'.($image['cover'] ? 'enabled.gif' : 'forbbiden.gif').'" alt="" /></a></td>
<td class="center"> <td class="center">
<a href="#" onclick="deleteImg('.(int)$image['id_image'].');"><img src="../img/admin/delete.gif" alt="'.$this->l('Delete this image').'" title="'.$this->l('Delete this image').'" /></a> <a href="#" class="delete_product_image"><img src="../img/admin/delete.gif" alt="'.$this->l('Delete this image').'" title="'.$this->l('Delete this image').'" /></a>
</td> </td>
</tr>'; </tr>';
return $html; $json = array(
'status' => 'ok',
'id'=>$image_obj->id,
'path' => _THEME_PROD_DIR_.$img_path.'.jpg',
'path_small' => _THEME_PROD_DIR_.$img_path.'-small.jpg',
'position' => $image['position'],
'cover' => $image['cover'],
'html' => $html
);
return $this->content = Tools::jsonEncode($json);
// return $html;
} }
public function getCombinationImagesJS() public function getCombinationImagesJS()