// 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
2011-11-18 16:42:51 +00:00
parent c7310f3899
commit d6ef55b5ed
3 changed files with 152 additions and 132 deletions
+79 -67
View File
@@ -20,41 +20,51 @@
<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?'}"); {
if (conf) e.preventDefault();
$.post( id = $(this).parent().parent().attr('id').substr(3);
"ajax-tab.php",
{ if (confirm("{l s='Are you sure?'}"))
action: "deleteImage", $.post("ajax-tab.php",
id_image:id,
id_product : "{$product->id}",
id_category : "{$id_category_default}",
token : "{$token}",
tab : "AdminProducts",
ajax : 1,
updateproduct : 1},
function (data) {
if (data)
{ {
cover = 0; action: "deleteProductImage",
if(data.imageDeleted) id_image:id,
{ id_product : "{$product->id}",
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif") id_category : "{$id_category_default}",
cover = 1; token : "{$token}",
$("#tr_" + id).remove(); tab : "AdminProducts",
ajax : 1,
},
function (data)
{
try{
data = $.parseJSON(data);
if (data)
{
cover = 0;
if(data.status == 'ok')
{
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
cover = 1;
$("#tr_" + id).remove();
}
if (cover)
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
$("#countImage").html(parseInt($("#countImage").html()) - 1);
refreshImagePositions($("#imageTable"));
}
} }
if (cover) catch(e){
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif"); alert("TECHNICAL ERROR");
}
$("#countImage").html(parseInt($("#countImage").html()) - 1); }
);
// refreshImagePositions($("#imageTable")); });
} });
});
return false;
}
function delQueue(id) function delQueue(id)
{ {
@@ -73,10 +83,9 @@
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){
var percent = ((filecheck * 100) / nbfile); var percent = ((filecheck * 100) / nbfile);
$("#progressBarImage").progressbar({ $("#progressBarImage").progressbar({
@@ -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} {foreach from=$shops item=shop}
<script type="text/javascript"> <th>{$shop.name}</th>
$(document).ready(function() { {/foreach}
$('.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}
<th>{$shop.name}</th>
{/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>
{foreach from=$shops item=shop}
<td class="center"> {if $shops}
<input type="checkbox" class="image_shop" name="{$image->id_image}" value="{$shop.id_shop}" {if $image->isAssociatedToShop($shop.id_shop)}checked="checked"{/if} /> {foreach from=$shops item=shop}
</td> <td class="center">
{/foreach} <input type="checkbox" class="image_shop" name="{$image->id_image}" value="{$shop.id_shop}" {if $image->isAssociatedToShop($shop.id_shop)}checked="checked"{/if} />
</td>
{/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;
+68 -65
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,15 +911,13 @@ 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");
// max file size in bytes // max file size in bytes
@@ -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,32 +952,32 @@ 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()
{ {
if (false) /* Delete product image */
{ if (isset($_GET['deleteProductImage']) || $this->action == 'deleteProductImage')
$image = new Image((int)Tools::getValue('id_image'));
$image->delete();
if (!Image::getCover($image->id_product))
{ {
$first_img = Db::getInstance()->getRow(' $image = new Image((int)Tools::getValue('id_image'));
SELECT `id_image` FROM `'._DB_PREFIX_.'image` $image->delete();
WHERE `id_product` = '.(int)($image->id_product)); if (!Image::getCover($image->id_product))
Db::getInstance()->execute(' {
UPDATE `'._DB_PREFIX_.'image` $first_img = Db::getInstance()->getRow('
SET `cover` = 1 SELECT `id_image` FROM `'._DB_PREFIX_.'image`
WHERE `id_image` = '.(int)($first_img['id_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));
else
$this->content = '{"status":"ok"}';
} }
@unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg');
@unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg');
}
$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';
$this->tpl_form = 'products/'.strtolower($this->action).'.tpl';
if(method_exists($this, 'initForm'.$this->action))
$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,16 +1791,20 @@ 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');
$this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage); else
$this->tpl_form_vars['product'] = $this->object; {
if ($this->ajax) $this->_displayDraftWarning($this->object->active);
if (!isset($this->tpl_form_vars['custom_form'])) $this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage);
throw new PrestashopException('custom_form empty for action '.$this->action); $this->tpl_form_vars['product'] = $this->object;
else if ($this->ajax)
return $this->tpl_form_vars['custom_form']; if (!isset($this->tpl_form_vars['custom_form']))
throw new PrestashopException('custom_form empty for action '.$this->action);
else
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()