Thelia\Controller\Admin\FileController::viewDocumentAction
.*
diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php
index ba9daf5d3..aff1c2d63 100755
--- a/core/lib/Thelia/Controller/Admin/FileController.php
+++ b/core/lib/Thelia/Controller/Admin/FileController.php
@@ -25,7 +25,7 @@ namespace Thelia\Controller\Admin;
use Propel\Runtime\Exception\PropelException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
-use Thelia\Core\Event\UpdateImagePositionEvent;
+use Thelia\Core\Event\UpdateFilePositionEvent;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
@@ -615,10 +615,10 @@ class FileController extends BaseAdminController
}
// Feed event
- $imageUpdateImagePositionEvent = new UpdateImagePositionEvent(
+ $imageUpdateImagePositionEvent = new UpdateFilePositionEvent(
$fileManager->getImageModelQuery($parentType),
$imageId,
- UpdateImagePositionEvent::POSITION_ABSOLUTE,
+ UpdateFilePositionEvent::POSITION_ABSOLUTE,
$position
);
@@ -650,6 +650,60 @@ class FileController extends BaseAdminController
return new Response($message);
}
+ public function updateDocumentPositionAction($parentType, $parentId)
+ {
+ $message = null;
+
+ $documentId = $this->getRequest()->request->get('document_id');
+ $position = $this->getRequest()->request->get('position');
+
+ $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE);
+ $this->checkXmlHttpRequest();
+
+ $fileManager = new FileManager($this->container);
+ $documentModelQuery = $fileManager->getDocumentModelQuery($parentType);
+ $model = $documentModelQuery->findPk($documentId);
+
+ if ($model === null || $position === null) {
+ return $this->pageNotFound();
+ }
+
+ // Feed event
+ $documentUpdateDocumentPositionEvent = new UpdateFilePositionEvent(
+ $fileManager->getDocumentModelQuery($parentType),
+ $documentId,
+ UpdateFilePositionEvent::POSITION_ABSOLUTE,
+ $position
+ );
+
+ // Dispatch Event to the Action
+ try {
+ $this->dispatch(
+ TheliaEvents::DOCUMENT_UPDATE_POSITION,
+ $documentUpdateDocumentPositionEvent
+ );
+ } catch (\Exception $e) {
+
+ $message = $this->getTranslator()
+ ->trans(
+ 'Fail to update document position',
+ array(),
+ 'document'
+ ) . $e->getMessage();
+ }
+
+ if(null === $message) {
+ $message = $this->getTranslator()
+ ->trans(
+ 'Document position updated',
+ array(),
+ 'document'
+ );
+ }
+
+ return new Response($message);
+ }
+
/**
* Manage how a document has to be deleted (AJAX)
*
diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php
index 8073f99cf..c31e824a0 100755
--- a/core/lib/Thelia/Core/Event/TheliaEvents.php
+++ b/core/lib/Thelia/Core/Event/TheliaEvents.php
@@ -404,6 +404,7 @@ final class TheliaEvents
* Save given documents
*/
const DOCUMENT_UPDATE = "action.updateDocument";
+ const DOCUMENT_UPDATE_POSITION = "action.updateDocumentPosition";
/**
* Delete given document
diff --git a/core/lib/Thelia/Core/Event/UpdateImagePositionEvent.php b/core/lib/Thelia/Core/Event/UpdateFilePositionEvent.php
similarity index 97%
rename from core/lib/Thelia/Core/Event/UpdateImagePositionEvent.php
rename to core/lib/Thelia/Core/Event/UpdateFilePositionEvent.php
index cf4479bba..1cd9b6677 100644
--- a/core/lib/Thelia/Core/Event/UpdateImagePositionEvent.php
+++ b/core/lib/Thelia/Core/Event/UpdateFilePositionEvent.php
@@ -25,7 +25,7 @@ namespace Thelia\Core\Event;
use Propel\Runtime\ActiveQuery\ModelCriteria;
-class UpdateImagePositionEvent extends UpdatePositionEvent
+class UpdateFilePositionEvent extends UpdatePositionEvent
{
protected $query;
diff --git a/core/lib/Thelia/Model/CategoryDocument.php b/core/lib/Thelia/Model/CategoryDocument.php
index 0917ab30c..57ae3c460 100755
--- a/core/lib/Thelia/Model/CategoryDocument.php
+++ b/core/lib/Thelia/Model/CategoryDocument.php
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class CategoryDocument extends BaseCategoryDocument
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
diff --git a/core/lib/Thelia/Model/ContentDocument.php b/core/lib/Thelia/Model/ContentDocument.php
index 1409b2713..30093573b 100755
--- a/core/lib/Thelia/Model/ContentDocument.php
+++ b/core/lib/Thelia/Model/ContentDocument.php
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ContentDocument extends BaseContentDocument
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
diff --git a/core/lib/Thelia/Model/FolderDocument.php b/core/lib/Thelia/Model/FolderDocument.php
index 1d84d9e55..29e860294 100755
--- a/core/lib/Thelia/Model/FolderDocument.php
+++ b/core/lib/Thelia/Model/FolderDocument.php
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class FolderDocument extends BaseFolderDocument
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
diff --git a/core/lib/Thelia/Model/ProductDocument.php b/core/lib/Thelia/Model/ProductDocument.php
index b0f8032da..eeaec30e9 100755
--- a/core/lib/Thelia/Model/ProductDocument.php
+++ b/core/lib/Thelia/Model/ProductDocument.php
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ProductDocument extends BaseProductDocument
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
diff --git a/templates/backOffice/default/assets/js/document-upload.js b/templates/backOffice/default/assets/js/document-upload.js
index 7843f5b44..bc9cf5898 100755
--- a/templates/backOffice/default/assets/js/document-upload.js
+++ b/templates/backOffice/default/assets/js/document-upload.js
@@ -6,9 +6,10 @@ $(function($){
- // Remove image on click
+ // Remove document on click
$.documentUploadManager.initDocumentDropZone = function() {
$.documentUploadManager.onClickDeleteDocument();
+ $.documentUploadManager.sortDocument();
var documentDropzone = new Dropzone("#documents-dropzone", {
dictDefaultMessage : $('.btn-browse').html(),
@@ -39,6 +40,7 @@ $(function($){
documentDropzone.removeFile(file);
$.documentUploadManager.updateDocumentListAjax();
$.documentUploadManager.onClickDeleteDocument();
+ $.documentUploadManager.sortDocument();
});
@@ -67,7 +69,7 @@ $(function($){
});
};
- // Remove image on click
+ // Remove document on click
$.documentUploadManager.onClickDeleteDocument = function() {
$('.document-manager .document-delete-btn').on('click', function (e) {
e.preventDefault();
@@ -97,4 +99,52 @@ $(function($){
return false;
});
};
+
+ $.documentUploadManager.sortDocument = function() {
+ $( "#js-sort-document" ).sortable({
+ placeholder: "ui-sortable-placeholder col-sm-6 col-md-3",
+ change: function( event, ui ) {
+ /* refresh position */
+ var pickedElement = ui.item;
+ var position = 0;
+ $( "#js-sort-document").children('li').each(function(k, element) {
+ if($(element).data('sort-id') == pickedElement.data('sort-id')) {
+ return true;
+ }
+ position++;
+ if($(element).is('.ui-sortable-placeholder')) {
+ pickedElement.find('.js-sorted-position').html(position);
+ } else {
+ $(element).find('.js-sorted-position').html(position);
+ }
+ });
+ },
+ stop: function( event, ui ) {
+ /* update */
+ var newPosition = ui.item.find('.js-sorted-position').html();
+ var documentId = ui.item.data('sort-id');
+
+ $.ajax({
+ type: "POST",
+ url: documentReorder,
+ data: {
+ document_id: documentId,
+ position: newPosition
+ },
+ statusCode: {
+ 404: function() {
+ $(".document-manager .message").html(
+ documentReorderErrorMessage
+ );
+ }
+ }
+ }).done(function(data) {
+ $(".document-manager .message").html(
+ data
+ );
+ });
+ }
+ });
+ $( "#js-sort-document" ).disableSelection();
+ };
});
diff --git a/templates/backOffice/default/assets/less/thelia/thelia.less b/templates/backOffice/default/assets/less/thelia/thelia.less
index 8660af2ad..ce9da65a9 100755
--- a/templates/backOffice/default/assets/less/thelia/thelia.less
+++ b/templates/backOffice/default/assets/less/thelia/thelia.less
@@ -428,4 +428,17 @@ table {
}
}
}
+}
+
+// document list style
+ul.document-list {
+ > li {
+ padding: @table-condensed-cell-padding;
+ line-height: @line-height-base;
+ border-top: 1px solid @table-border-color;
+ &:nth-child(odd) {
+ background-color: @table-bg-accent;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/templates/backOffice/default/includes/document-upload-form.html b/templates/backOffice/default/includes/document-upload-form.html
index 58627b688..6d0574fd2 100755
--- a/templates/backOffice/default/includes/document-upload-form.html
+++ b/templates/backOffice/default/includes/document-upload-form.html
@@ -32,5 +32,7 @@ Parameters:
diff --git a/templates/backOffice/default/includes/document-upload-list-ajax.html b/templates/backOffice/default/includes/document-upload-list-ajax.html
index 29effddd7..768129554 100755
--- a/templates/backOffice/default/includes/document-upload-list-ajax.html
+++ b/templates/backOffice/default/includes/document-upload-list-ajax.html
@@ -7,29 +7,27 @@ Parameters:
parentId = Document parent id, ex: category id
*}
-
{ifloop rel="document"}
-
+
{/ifloop}
+
{elseloop rel="document"}
{intl l='There is no documents attached to this %type.' type=$documentType}
{/elseloop}