// fix #PSTEST-125
This commit is contained in:
@@ -219,41 +219,44 @@
|
|||||||
$("#listImage").append("<li id='img"+id+"'><div class=\"float\" >" + filename + "</div></div><a style=\"margin-left:10px\"href=\"javascript:delQueue(" + id +");\"><img src=\"../img/admin/disabled.gif\" alt=\"\" border=\"0\"></a><p class=\"errorImg\"></p></li>");
|
$("#listImage").append("<li id='img"+id+"'><div class=\"float\" >" + filename + "</div></div><a style=\"margin-left:10px\"href=\"javascript:delQueue(" + id +");\"><img src=\"../img/admin/disabled.gif\" alt=\"\" border=\"0\"></a><p class=\"errorImg\"></p></li>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* on success function
|
||||||
|
*/
|
||||||
|
function afterDeleteProductImage(data)
|
||||||
|
{
|
||||||
|
data = $.parseJSON(data);
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
cover = 0;
|
||||||
|
id = data.content.id;
|
||||||
|
if(data.status == 'ok')
|
||||||
|
{
|
||||||
|
if ($("#" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
|
||||||
|
cover = 1;
|
||||||
|
$("#" + id).remove();
|
||||||
|
}
|
||||||
|
if (cover)
|
||||||
|
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
|
||||||
|
$("#countImage").html(parseInt($("#countImage").html()) - 1);
|
||||||
|
refreshImagePositions($("#imageTable"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$('.delete_product_image').die().live('click', function(e)
|
$('.delete_product_image').die().live('click', function(e)
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
id = $(this).parent().parent().attr('id');
|
id = $(this).parent().parent().attr('id');
|
||||||
if (confirm("{/literal}{l s='Are you sure?' js=1}{literal}"))
|
if (confirm("{/literal}{l s='Are you sure?' js=1}{literal}"))
|
||||||
$.ajax(
|
doAdminAjax({
|
||||||
{
|
"action":"deleteProductImage",
|
||||||
url : "ajax-tab.php",
|
|
||||||
data : {"action":"deleteProductImage",
|
|
||||||
"id_image":id,
|
"id_image":id,
|
||||||
"id_product" : {/literal}{$id_product}{literal},
|
"id_product" : {/literal}{$id_product}{literal},
|
||||||
"id_category" : {/literal}{$id_category_default}{literal},
|
"id_category" : {/literal}{$id_category_default}{literal},
|
||||||
"token" : "{/literal}{$token}{literal}",
|
"token" : "{/literal}{$token}{literal}",
|
||||||
"tab" : "AdminProducts",
|
"tab" : "AdminProducts",
|
||||||
"ajax" : 1 },
|
"ajax" : 1 }, afterDeleteProductImage
|
||||||
success : function (data)
|
);
|
||||||
{
|
|
||||||
data = jQuery.parseJSON(data);
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
cover = 0;
|
|
||||||
if(data.status == 'ok')
|
|
||||||
{
|
|
||||||
if ($("#" + id).find(".covered").attr("src") == "../img/admin/enabled.gif")
|
|
||||||
cover = 1;
|
|
||||||
$("#" + id).remove();
|
|
||||||
}
|
|
||||||
if (cover)
|
|
||||||
$("#imageTable tr").eq(1).find(".covered").attr("src", "../img/admin/enabled.gif");
|
|
||||||
$("#countImage").html(parseInt($("#countImage").html()) - 1);
|
|
||||||
refreshImagePositions($("#imageTable"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.covered').die().live('click', function(e)
|
$('.covered').die().live('click', function(e)
|
||||||
@@ -298,7 +301,7 @@
|
|||||||
function updateImagePositon(json)
|
function updateImagePositon(json)
|
||||||
{
|
{
|
||||||
doAdminAjax(
|
doAdminAjax(
|
||||||
{
|
{
|
||||||
"action":"updateImagePosition",
|
"action":"updateImagePosition",
|
||||||
"json":json,
|
"json":json,
|
||||||
"token" : "{/literal}{$token}{literal}",
|
"token" : "{/literal}{$token}{literal}",
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ class AdminControllerCore extends Controller
|
|||||||
protected $_redirect = true;
|
protected $_redirect = true;
|
||||||
|
|
||||||
/** @var array Name and directory where class image are located */
|
/** @var array Name and directory where class image are located */
|
||||||
public $fieldImageSettings = array();
|
public $fieldImageSettings = null;
|
||||||
|
|
||||||
/** @var string Image type */
|
/** @var string Image type */
|
||||||
public $imageType = 'jpg';
|
public $imageType = 'jpg';
|
||||||
@@ -528,8 +528,9 @@ class AdminControllerCore extends Controller
|
|||||||
*/
|
*/
|
||||||
public function processDelete($token)
|
public function processDelete($token)
|
||||||
{
|
{
|
||||||
if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings))
|
if (Validate::isLoadedObject($object = $this->loadObject()))
|
||||||
{
|
{
|
||||||
|
$res = true;
|
||||||
// check if request at least one object with noZeroObject
|
// check if request at least one object with noZeroObject
|
||||||
if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1)
|
if (isset($object->noZeroObject) && count(call_user_func(array($this->className, $object->noZeroObject))) <= 1)
|
||||||
{
|
{
|
||||||
@@ -543,7 +544,12 @@ class AdminControllerCore extends Controller
|
|||||||
{
|
{
|
||||||
if ($this->deleted)
|
if ($this->deleted)
|
||||||
{
|
{
|
||||||
$object->deleteImage();
|
if (isset($this->fieldImageSettings))
|
||||||
|
$res = $object->deleteImage();
|
||||||
|
|
||||||
|
if (!$res)
|
||||||
|
$this->_errors[] = Tools::displayError('Unable to delete associated images');
|
||||||
|
|
||||||
$object->deleted = 1;
|
$object->deleted = 1;
|
||||||
if ($object->update())
|
if ($object->update())
|
||||||
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$token;
|
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$token;
|
||||||
|
|||||||
@@ -1239,22 +1239,33 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
|
|
||||||
public function ajaxProcessDeleteProductImage()
|
public function ajaxProcessDeleteProductImage()
|
||||||
{
|
{
|
||||||
|
$this->json = true;
|
||||||
|
$this->display = 'content';
|
||||||
|
$res = true;
|
||||||
|
/* Delete product image */
|
||||||
$image = new Image((int)Tools::getValue('id_image'));
|
$image = new Image((int)Tools::getValue('id_image'));
|
||||||
$image->delete();
|
$this->content['id'] = $image->id;
|
||||||
|
$res &= $image->delete();
|
||||||
|
// if deleted image was the cover, change it to the first one
|
||||||
if (!Image::getCover($image->id_product))
|
if (!Image::getCover($image->id_product))
|
||||||
{
|
{
|
||||||
$first_img = Db::getInstance()->getRow('
|
$res &= Db::getInstance()->Execute('
|
||||||
SELECT `id_image` FROM `'._DB_PREFIX_.'image`
|
|
||||||
WHERE `id_product` = '.(int)$image->id_product);
|
|
||||||
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_product` = '.(int)$image->id_product.' LIMIT 1');
|
||||||
}
|
}
|
||||||
@unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg');
|
|
||||||
@unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg');
|
|
||||||
|
|
||||||
$this->content = '{"status":"ok"}';
|
if(file_exists(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg'))
|
||||||
|
$res &= @unlink(_PS_TMP_IMG_DIR_.'/product_'.$image->id_product.'.jpg');
|
||||||
|
if(file_exists(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg'))
|
||||||
|
$res &= @unlink(_PS_TMP_IMG_DIR_.'/product_mini_'.$image->id_product.'.jpg');
|
||||||
|
|
||||||
|
if ($res)
|
||||||
|
$this->confirmations[] = $this->_conf[7];
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('Error on deleting product image');
|
||||||
|
|
||||||
|
$this->status = 'ok';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to)
|
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to)
|
||||||
|
|||||||
+9
-9
@@ -929,14 +929,8 @@ function refreshImagePositions(imageTable)
|
|||||||
var reg = /_[0-9]$/g;
|
var reg = /_[0-9]$/g;
|
||||||
var up_reg = new RegExp("imgPosition=[0-9]+&");
|
var up_reg = new RegExp("imgPosition=[0-9]+&");
|
||||||
|
|
||||||
imageTable.find("tbody tr").each(function(i) {
|
imageTable.find("tbody tr").each(function(i,el) {
|
||||||
// Update link position
|
$(el).find("td.positionImage").html(i + 1);
|
||||||
// Up links
|
|
||||||
$(this).find("td.dragHandle a:first").attr("href", $(this).find("td.dragHandle a:first").attr("href").replace(up_reg, "imgPosition="+ i +"&"));//, "imgPosition="+ (i - 1) +"&"));
|
|
||||||
// Down links
|
|
||||||
$(this).find("td.dragHandle a:last").attr("href", $(this).find("td.dragHandle a:last").attr("href").replace(up_reg, "imgPosition="+ (i + 2) +"&"));
|
|
||||||
// Position image cell
|
|
||||||
$(this).find("td.positionImage").html(i + 1);
|
|
||||||
});
|
});
|
||||||
imageTable.find("tr td.dragHandle a:hidden").show();
|
imageTable.find("tr td.dragHandle a:hidden").show();
|
||||||
imageTable.find("tr td.dragHandle:first a:first").hide();
|
imageTable.find("tr td.dragHandle:first a:first").hide();
|
||||||
@@ -944,13 +938,16 @@ function refreshImagePositions(imageTable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doAdminAjax(data)
|
function doAdminAjax(data, success_func, error_func)
|
||||||
{
|
{
|
||||||
$.ajax(
|
$.ajax(
|
||||||
{
|
{
|
||||||
url : 'index.php',
|
url : 'index.php',
|
||||||
data : data,
|
data : data,
|
||||||
success : function(data){
|
success : function(data){
|
||||||
|
if (success_func)
|
||||||
|
return success_func(data);
|
||||||
|
|
||||||
data = $.parseJSON(data);
|
data = $.parseJSON(data);
|
||||||
if(data.confirmations.length != 0)
|
if(data.confirmations.length != 0)
|
||||||
showSuccessMessage(data.confirmations);
|
showSuccessMessage(data.confirmations);
|
||||||
@@ -958,6 +955,9 @@ function doAdminAjax(data)
|
|||||||
showErrorMessage(data.error);
|
showErrorMessage(data.error);
|
||||||
},
|
},
|
||||||
error : function(data){
|
error : function(data){
|
||||||
|
if (error_func)
|
||||||
|
return error_func(data);
|
||||||
|
|
||||||
alert("[TECHNICAL ERROR]");
|
alert("[TECHNICAL ERROR]");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user