Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FileManager to use originals parameter instead of hard coded 'originals' #64

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ services:
arguments:
# For bc reasons we're not changing the names of the parameters
- file_base_path: '%file_uploader.file_base_path%'
originals: '%file_uploader.originals%'

punk_ave.twig.file_extension:
class: PunkAve\FileUploaderBundle\Twig\FileExtension
Expand Down
9 changes: 5 additions & 4 deletions Resources/public/js/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ function PunkAveFileUploader(options)
var self = this,
uploadUrl = options.uploadUrl,
viewUrl = options.viewUrl,
originalsDir = options.originalsDir || 'originals',
$el = $(options.el),
uploaderTemplate = _.template($.trim($('#file-uploader-template').html()));
$el.html(uploaderTemplate({}));

var fileTemplate = _.template($.trim($('#file-uploader-file-template').html())),
editor = $el.find('[data-files="1"]'),
thumbnails = $el.find('[data-thumbnails="1"]');

self.uploading = false;

self.errorCallback = 'errorCallback' in options ? options.errorCallback : function( info ) { if (window.console && console.log) { console.log(info) } },

self.addExistingFiles = function(files)
Expand All @@ -21,7 +22,7 @@ function PunkAveFileUploader(options)
appendEditableImage({
// cmsMediaUrl is a global variable set by the underscoreTemplates partial of MediaItems.html.twig
'thumbnail_url': viewUrl + '/thumbnails/' + file,
'url': viewUrl + '/originals/' + file,
'url': viewUrl + '/' + originalsDir + '/' + file,
'name': file
});
});
Expand Down Expand Up @@ -119,7 +120,7 @@ function PunkAveFileUploader(options)
var newAdditionalURL = "";
var tempArray = url.split("?");
var baseURL = tempArray[0];
var additionalURL = tempArray[1];
var additionalURL = tempArray[1];
var temp = "";
if (additionalURL)
{
Expand Down
10 changes: 6 additions & 4 deletions Services/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ public function __construct($options)
}

/**
* Get a list of files already present. The 'folder' option is required.
* Get a list of files already present. The 'folder' option is required.
* If you pass consistent options to this method and handleFileUpload with
* regard to paths, then you will get consistent results.
*/
public function getFiles($options = array())
{
$options = array_merge($this->options, $options);

$originals = $options['originals'];

$folder = $options['file_base_path'] . '/' . $options['folder'];
if (file_exists($folder))
{
$dirs = glob("$folder/originals/*");
$dirs = glob($folder . '/' . $originals['folder'] . '/*');
$fullPath = isset($options['full_path']) ? $options['full_path'] : false;
if ($fullPath)
{
Expand Down Expand Up @@ -68,11 +70,11 @@ public function removeFiles($options = array())
/**
* Sync existing files from one folder to another. The 'fromFolder' and 'toFolder'
* options are required. As with the 'folder' option elsewhere, these are appended
* to the file_base_path for you, missing parent folders are created, etc. If
* to the file_base_path for you, missing parent folders are created, etc. If
* 'fromFolder' does not exist no error is reported as this is common if no files
* have been uploaded. If there are files and the sync reports errors an exception
* is thrown.
*
*
* If you pass consistent options to this method and handleFileUpload with
* regard to paths, then you will get consistent results.
*/
Expand Down