// 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>
<script type="text/javascript">var upbutton = "{l s='Upload a file'}"; </script>
<script type="text/javascript">
function deleteImg(id)
{
var conf = confirm("{l s='Are you sure?'}");
if (conf)
$.post(
"ajax-tab.php",
{
action: "deleteImage",
id_image:id,
id_product : "{$product->id}",
id_category : "{$id_category_default}",
token : "{$token}",
tab : "AdminProducts",
ajax : 1,
updateproduct : 1},
function (data) {
if (data)
$(document).ready(function(){
$('.delete_product_image').die().live('click', function(e)
{
e.preventDefault();
id = $(this).parent().parent().attr('id').substr(3);
if (confirm("{l s='Are you sure?'}"))
$.post("ajax-tab.php",
{
cover = 0;
if(data.imageDeleted)
{
if ($("#tr_" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
cover = 1;
$("#tr_" + id).remove();
action: "deleteProductImage",
id_image:id,
id_product : "{$product->id}",
id_category : "{$id_category_default}",
token : "{$token}",
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)
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
$("#countImage").html(parseInt($("#countImage").html()) - 1);
// refreshImagePositions($("#imageTable"));
}
});
return false;
}
catch(e){
alert("TECHNICAL ERROR");
}
}
);
});
});
function delQueue(id)
{
@@ -73,10 +83,9 @@
token : "{$token}",
tab : "AdminProducts",
updateproduct : 1,
addImage : 1,
ajaxMode : 1,
action : 'addImage',
ajax: 1,
},
},
onComplete: function(id, fileName, responseJSON){
var percent = ((filecheck * 100) / nbfile);
$("#progressBarImage").progressbar({
@@ -99,9 +108,9 @@
nbfile = 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);
$("#img" + id).remove();
}
@@ -152,29 +161,9 @@
<th style="width: 100px;">{l s='Image'}</th>
<th>&nbsp;</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}
<th>{$shop.name}</th>
{/foreach}
{/if}
{foreach from=$shops item=shop}
<th>{$shop.name}</th>
{/foreach}
<th>{l s='Cover'}</th>
<th>{l s='Action'}</th>
@@ -196,16 +185,19 @@
<img src="../img/admin/down.gif" alt="" border="0">
</a>
</td>
{foreach from=$shops item=shop}
<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} />
</td>
{/foreach}
{if $shops}
{foreach from=$shops item=shop}
<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} />
</td>
{/foreach}
{/if}
<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>
</td>
<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'}" />
</a>
</td>
@@ -218,3 +210,23 @@
</table>
</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);
if (Validate::isLoadedObject($this->object))
return $this->object;
// throw exception
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');
return false;
}
else if ($opt)
{
@@ -927,7 +929,10 @@ class AdminControllerCore extends Controller
return $this->object;
}
else
{
$this->_errors[] = Tools::displayError('Object cannot be loaded (identifier missing or invalid)');
return false;
}
$this->content = $this->displayErrors();
return $this->object;
+68 -65
View File
@@ -460,29 +460,9 @@ class AdminProductsController extends AdminController
{
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 */
else if (isset($_GET['editImage']))
// @todo : move in processEditProductImage
if (isset($_GET['editImage']))
{
if ($image->cover)
$_POST['cover'] = 1;
@@ -931,15 +911,13 @@ class AdminProductsController extends AdminController
//Manage suppliers
else if (Tools::isSubmit('submitSupplierReferences'))
$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';
$allowedExtensions = array("jpeg", "gif", "png", "jpg");
// max file size in bytes
@@ -956,12 +934,16 @@ class AdminProductsController extends AdminController
$images = Image::getImages($this->context->language->id, $obj->id);
$imagesTotal = Image::getImagesTotal($obj->id);
$html = $this->getLineTableImage($result['success'], $imagesTotal + 1, $this->token, $shops);
die(Tools::jsonEncode(array("success" => $html)));
die($html);
}
else
die(Tools::jsonEncode($result));
}
public function ajaxPreProcess()
{
$this->action = Tools::getValue('action');
if (Tools::getValue('updateProductImageShopAsso'))
{
if ($id_image = (int)Tools::getValue('id_image') && $id_shop = (int)Tools::getValue('id_shop'))
@@ -970,32 +952,32 @@ class AdminProductsController extends AdminController
else
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)
{
$image = new Image((int)Tools::getValue('id_image'));
$image->delete();
if (!Image::getCover($image->id_product))
/* Delete product image */
if (isset($_GET['deleteProductImage']) || $this->action == 'deleteProductImage')
{
$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']));
$image = new Image((int)Tools::getValue('id_image'));
$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));
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)
@@ -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'))
{
$this->fields_form = array();
if (empty($this->action) || !method_exists($this, 'initForm'.$this->action))
if (empty($this->action))
$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)
{
$this->display = 'edit';
@@ -1782,7 +1768,8 @@ if (false)
*/
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
$this->getLanguages();
$languages = $this->_languages;
@@ -1804,16 +1791,20 @@ if (false)
$this->tpl_form_vars['country_display_tax_label'] = $this->context->country->display_tax_label;
// let's calculate this once for all
if (!($obj = $this->loadObject(true)))
throw new PrestashopException('object not loaded');
$this->_displayDraftWarning($obj->active);
$this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage);
$this->tpl_form_vars['product'] = $this->object;
if ($this->ajax)
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'];
if (!Validate::isLoadedObject($this->object) && Tools::getValue('id_product'))
$this->_errors[] = 'Unable to load object';
// throw new PrestashopException('object not loaded');
else
{
$this->_displayDraftWarning($this->object->active);
$this->{'initForm'.$this->action}($this->object, $languages, $defaultLanguage);
$this->tpl_form_vars['product'] = $this->object;
if ($this->ajax)
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();
}
@@ -2470,6 +2461,7 @@ if (false)
$cache_default_attribute = (int) $this->getFieldValue($product, 'cache_default_attribute');
$data->assign('feature_shop_active', Shop::isFeatureActive());
// @todo : uses the helperform
$data->assign('displayAssoShop', $this->displayAssoShop());
$product_props = array();
@@ -3255,10 +3247,21 @@ if (false)
$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="#" 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>
</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()