Permalink
Browse files

Merge pull request #2445 from Paphos/image_product

Improve product image management
  • Loading branch information...
roadster31 committed Nov 21, 2017
2 parents 5361adb + 8020769 commit 79d04cee8c181763d95719ca1337ccd1a995f8e8
@@ -99,6 +99,11 @@
<requirement key="parentType">.*</requirement>
<requirement key="parentId">\d+</requirement>
</route>
<route id="admin.image.update-title" path="/admin/image/type/{parentType}/{imageId}/update-title" methods="post">
<default key="_controller">Thelia\Controller\Admin\FileController::updateImageTitleAction</default>
<requirement key="parentType">.*</requirement>
<requirement key="imageId">\d+</requirement>
</route>
<route id="admin.image.toggle.process" path="/admin/image/type/{parentType}/{documentId}/toggle">
<default key="_controller">Thelia\Controller\Admin\FileController::toggleVisibilityImageAction</default>
<requirement key="parentType">.*</requirement>
@@ -756,6 +756,33 @@ public function updateFilePositionAction($parentType, $parentId, $objectType, $e
return new Response($message);
}
public function updateImageTitleAction($imageId, $parentType)
{
if (null !== $response = $this->checkAuth($this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT), array(), AccessManager::UPDATE)) {
return $response;
}
$fileManager = $this->getFileManager();
$fileModelInstance = $fileManager->getModelInstance('image', $parentType);
/** @var FileModelInterface $file */
$file = $fileModelInstance->getQueryInstance()->findPk($imageId);
$new_title = $this->getRequest()->request->get('title');
$locale = $this->getRequest()->request->get('locale');
if (!empty($new_title)) {
$file->setLocale($locale);
$file->setTitle($new_title);
$file->save();
}
return $this->generateRedirect(
URL::getInstance()->absoluteUrl($this->getRequest()->request->get('success_url'), ['current_tab' => 'images'])
);
}
public function updateImagePositionAction($parentType, /** @noinspection PhpUnusedParameterInspection */ $parentId)
{
$imageId = $this->getRequest()->request->get('image_id');
@@ -21,6 +21,7 @@
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ProductDocumentQuery;
use Thelia\Model\ProductImage;
use Thelia\Model\ProductImageQuery;
use Thelia\Type\BooleanOrBothType;
use Thelia\Type\TypeCollection;
use Thelia\Type\EnumListType;
@@ -293,7 +294,6 @@ public function parseResults(LoopResult $loopResult)
case 'none':
default:
$resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
}
$baseSourceFilePath = ConfigQuery::read('images_library_path');
@@ -353,6 +353,8 @@ public function parseResults(LoopResult $loopResult)
->set("OBJECT_ID", $this->objectId)
;
$this->findNextPrev($loopResultRow, $result->getId(), $this->objectType, $result->getPosition());
$addRow = true;
$returnErroredImages = $this->getBackendContext() || ! $this->getIgnoreProcessingErrors();
@@ -392,4 +394,61 @@ public function parseResults(LoopResult $loopResult)
return $loopResult;
}
/**
* Set the fields HAS_PREVIOUS, HAS_NEXT, PREVIOUS, NEXT for the image loop
*
* @param LoopResultRow $loopResultRow
* @param int $imageId Image id
* @param string $imageType Type of the image. Only 'product' is currently supported to get the NEXT and PREVIOUS values
* @param int $currentPosition The position of the image
*/
private function findNextPrev(LoopResultRow $loopResultRow, $imageId, $imageType, $currentPosition)
{
if ($imageType == 'product') {
$imageRow = ProductImageQuery::create()
->filterById($imageId)
->findOne();
if ($imageRow != null) {
$previousQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::LESS_THAN);
$nextQuery = ProductImageQuery::create()
->filterByProductId($imageRow->getProductId())
->filterByPosition($currentPosition, Criteria::GREATER_THAN);
if (!$this->getBackendContext()) {
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
$previousQuery->useProductQuery()
->filterByVisible(true)
->endUse();
}
$previous = $previousQuery
->orderByPosition(Criteria::DESC)
->findOne();
$next = $nextQuery
->orderByPosition(Criteria::ASC)
->findOne();
$loopResultRow
->set("HAS_PREVIOUS", $previous != null ? 1 : 0)
->set("HAS_NEXT", $next != null ? 1 : 0)
->set("PREVIOUS", $previous != null ? $previous->getId() : -1)
->set("NEXT", $next != null ? $next->getId() : -1);
return;
}
}
$loopResultRow
->set("HAS_PREVIOUS", 0)
->set("HAS_NEXT", 0);
}
}
@@ -326,6 +326,7 @@
'Delete profile' => 'Delete profile',
'Delete sale' => 'Delete sale',
'Delete selected countries' => 'Delete selected countries',
'Delete selected images' => 'Delete selected images',
'Delete shipping zone' => 'Delete shipping zone',
'Delete state' => 'Delete state',
'Delete tax' => 'Delete tax',
@@ -371,6 +372,7 @@
'Delivery module' => 'Delivery module',
'Delivery modules' => 'Delivery modules',
'Description' => 'Description',
'Deselect all' => 'Deselect all',
'Destinations' => 'Destinations',
'Developer mode' => 'Developer mode',
'Disabled' => 'Disabled',
@@ -385,6 +387,7 @@
'Do you really want to add this attribute to all product templates ?' => 'Do you really want to add this attribute to all product templates ?',
'Do you really want to add this feature to all product templates ?' => 'Do you really want to add this feature to all product templates ?',
'Do you really want to cancel this order ?' => 'Do you really want to cancel this order ?',
'Do you really want to delete these %count image(s) ?' => 'Do you really want to delete these %count image(s) ?',
'Do you really want to delete this address ?' => 'Do you really want to delete this address ?',
'Do you really want to delete this administrator ?' => 'Do you really want to delete this administrator ?',
'Do you really want to delete this api access ?' => 'Do you really want to delete this API access ?',
@@ -859,6 +862,7 @@
'Please select a coupon type' => 'Please select a coupon type',
'Please select another condition' => 'Please select another condition',
'Please select at least one category.' => 'Please select at least one category.',
'Please select at least one image to delete.' => 'Please select at least one image to delete.',
'Please select items to translate' => 'Please select items to translate',
'Please select one or more categories which contains some products' => 'Please select one or more categories which contains some products',
'Please select the B.O. template to translate' => 'Please select the B.O. template to translate',
@@ -998,6 +1002,7 @@
'Select a tax tule' => 'Select a tax tule',
'Select a template' => 'Select a template',
'Select a value click (+) to add it to the combination' => 'Select a value click (+) to add it to the combination',
'Select all' => 'Select all',
'Select an attribute and click (+) to add it to this template' => 'Select an attribute and click (+) to add it to this template',
'Select an attribute and click (+) to view available values' => 'Select an attribute and click (+) to view available values',
'Select an attribute value...' => 'Select an attribute value...',
@@ -326,6 +326,7 @@
'Delete profile' => 'Supprimer le profil',
'Delete sale' => 'Supprimer cette promotion',
'Delete selected countries' => 'Supprimer les pays sélectionnés',
'Delete selected images' => 'Supprimer les images sélectionnées',
'Delete shipping zone' => 'Supprimer une zone de livraison',
'Delete state' => 'Supprimer l\'État',
'Delete tax' => 'Supprimer la taxe',
@@ -371,6 +372,7 @@
'Delivery module' => 'Module de livraison',
'Delivery modules' => 'Modules de livraison',
'Description' => 'Description',
'Deselect all' => 'Tout désélectionner',
'Destinations' => 'Destinations',
'Developer mode' => 'Mode développeur',
'Disabled' => 'Désactivé',
@@ -385,6 +387,7 @@
'Do you really want to add this attribute to all product templates ?' => 'Voulez-vous vraiment ajouter cette déclinaison de tous les gabarits de produit ?',
'Do you really want to add this feature to all product templates ?' => 'Voulez-vous vraiment ajouter cette caractéristique à tous les gabarits de produit ?',
'Do you really want to cancel this order ?' => 'Voulez-vous vraiment supprimer cette commande ?',
'Do you really want to delete these %count image(s) ?' => 'Voulez-vous vraiment supprimer ces %count images ?',
'Do you really want to delete this address ?' => 'Voulez-vous vraiment supprimer cette adresse ?',
'Do you really want to delete this administrator ?' => 'Confirmez-vous la suppression de cet administrateur ?',
'Do you really want to delete this api access ?' => 'êtes-vous sur de vouloir supprimer cet accès à l\'API',
@@ -859,6 +862,7 @@
'Please select a coupon type' => 'Merci d\'entrer le type de code',
'Please select another condition' => 'Merci de sélectionner une autre condition',
'Please select at least one category.' => 'Merci de choisir au moins une catégorie',
'Please select at least one image to delete.' => 'Veuillez sélectionner au moins une image à supprimer.',
'Please select items to translate' => 'Veuillez sélectionner un élément',
'Please select one or more categories which contains some products' => 'Choisissez une ou plusieurs catégories de produits',
'Please select the B.O. template to translate' => 'Sélectionnez le template back-office à traduire',
@@ -998,6 +1002,7 @@
'Select a tax tule' => 'Sélectionnez une règle de taxes',
'Select a template' => 'Choisissez un gabarit',
'Select a value click (+) to add it to the combination' => 'Sélectionnez une valeur et cliquez sur (+) pour l\'ajouter à la combinaison',
'Select all' => 'Tout sélectionner',
'Select an attribute and click (+) to add it to this template' => 'Sélectionner une déclinaison et cliquer sur (+) pour l\'ajouter à ce gabarit',
'Select an attribute and click (+) to view available values' => 'Sélectionnez une déclinaison et cliquez sur (+) pour voir les valeurs disponibles',
'Select an attribute value...' => 'Sélectionnez une valeur de déclinaison...',

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -12,6 +12,8 @@ $(function($){
$.imageUploadManager.onModalHidden();
$.imageUploadManager.sortImage();
$.imageUploadManager.onClickToggleVisibilityImage();
$.imageUploadManager.onClickBtnDeleteSelectedImages();
$.imageUploadManager.onClickBtnSelectDeselectImages();
var imageDropzone = new Dropzone("#images-dropzone", {
dictDefaultMessage : $('.btn-browse').html(),
@@ -77,57 +79,114 @@ $(function($){
$.imageUploadManager.onClickDeleteImage = function() {
$('.image-manager .image-delete-btn').on('click', function (e) {
e.preventDefault();
$("#submit-delete-image").data("element-id", $(this).attr("id"));
var $btnSubmit = $("#submit-delete-image");
$btnSubmit.data("element-id", $(this).attr("id"));
$btnSubmit.data("type", "one");
$('#modal-body-delete-image').html(imageDeleteOneWarningMessage);
$('#image_delete_dialog').modal("show");
return false;
});
};
$.imageUploadManager.onClickBtnDeleteSelectedImages = function(){
$('.btn-delete-selected-images').on('click', function(e) {
e.preventDefault();
var $btnSubmit = $("#submit-delete-image");
var $btnCancel = $("#jsBtnDismissImageDeleteModal");
$btnSubmit.data("type", "multiple");
var $count = $('.image-select-checkbox:checked').length;
var $warning;
if($count == 0){
$btnSubmit.hide();
$btnCancel.html(textBtnDeleteImageModal_Close);
$warning = imageDeleteNoImageSelectedMessage;
}else{
$btnSubmit.show();
$btnCancel.html('<span class="glyphicon glyphicon-remove"></span>'+textBtnDeleteImageModal_No);
if($count == 1){
$warning = imageDeleteOneWarningMessage;
} else {
$warning = imageDeleteMultipleWarningMessage.replace("%count", $count);
}
}
$('#modal-body-delete-image').html($warning);
$('#image_delete_dialog').modal("show");
return false;
});
};
$.imageUploadManager.onClickBtnSelectDeselectImages = function(){
$('.btn-select-all-images').on('click', function(e) {
e.preventDefault();
$('.image-select-checkbox').prop('checked', true);
});
$('.btn-deselect-all-images').on('click', function(e) {
e.preventDefault();
$('.image-select-checkbox').prop('checked', false);
});
};
$.imageUploadManager.onModalHidden = function() {
$("#image_delete_dialog").on('hidden.bs.modal', function (e) {
$("#submit-delete-image").data("element-id", "");
var $btnSubmit = $("#submit-delete-image");
$btnSubmit.data("element-id", "");
$btnSubmit.data("type", "");
$('#modal-body-delete-image').html('');
});
};
$.imageUploadManager.onClickModal = function() {
$("#submit-delete-image").on('click', function(e){
$.imageUploadManager.deleteSelectedImages = function(){
$('.image-select-checkbox:checked').each(function(){
$.imageUploadManager.deleteImage($(this).data("id"));
});
};
var $id= $(this).data("element-id");
var $this = $("#"+$id);
var $parent = $this.parent();
var $greatParent = $parent.parent();
$.imageUploadManager.deleteImage = function($id){
var $this = $("#"+$id);
var $parent = $this.parent();
var $greatParent = $parent.parent();
$greatParent.append('<div class="loading" ></div>');
$greatParent.find('.btn-group').remove();
var $url = $this.attr("href");
var errorMessage = $this.attr("data-error-message");
$.ajax({
type: "POST",
url: $url,
statusCode: {
404: function() {
$(".image-manager .message").html(
errorMessage
);
}
$greatParent.append('<div class="loading" ></div>');
$greatParent.find('.btn-group').remove();
var $url = $this.attr("href");
var errorMessage = $this.attr("data-error-message");
$.ajax({
type: "POST",
url: $url,
statusCode: {
404: function() {
$(".image-manager .message").html(
errorMessage
);
}
}).done(function(data) {
$greatParent.remove();
$(".image-manager .message").html(
data
);
}
}).done(function(data) {
$greatParent.parent().remove();
$(".image-manager .message").html(
data
);
/* refresh position */
$( "#js-sort-image").children('li').each(function(position, element) {
$(element).find('.js-sorted-position').html(position + 1);
});
}).always(function(){
$('#image_delete_dialog').modal("hide");
$("#submit-delete-image").data("element-id", "");
/* refresh position */
$( "#js-sort-image").children('li').each(function(position, element) {
$(element).find('.js-sorted-position').html(position + 1);
});
}).always(function(){
$('#image_delete_dialog').modal("hide");
});
};
$.imageUploadManager.onClickModal = function() {
$("#submit-delete-image").on('click', function(e){
var $type = $(this).data("type");
if($type == 'one') {
var $id = $(this).data("element-id");
$.imageUploadManager.deleteImage($id);
}else if($type == 'multiple'){
$.imageUploadManager.deleteSelectedImages();
}
});
};
Oops, something went wrong.

0 comments on commit 79d04ce

Please sign in to comment.