Index: admin_templates/incs/form_blocks.tpl =================================================================== --- admin_templates/incs/form_blocks.tpl (revision 15345) +++ admin_templates/incs/form_blocks.tpl (working copy) @@ -350,6 +350,7 @@
+ Index: admin_templates/js/uploader/uploader.js =================================================================== --- admin_templates/js/uploader/uploader.js (revision 15338) +++ admin_templates/js/uploader/uploader.js (working copy) @@ -354,6 +354,19 @@ return $ret; } +Uploader.prototype.getSortedFiles = function($ordered_queue) { + var $me = this; + + var $ret = $.map($me.files, function ($elem, $index) { + var $file_id = $ordered_queue[$index].replace(/_queue_row$/, ''), + $file_index = $me.getFileIndex({id: $file_id}); + + return $me.files[$file_index].name; + }); + + return $ret; +} + Uploader.prototype.updateQueueFile = function($file_index, $delete_file) { $queue_container = $( jq('#' + this.id + '_queueinfo') ); Index: kernel/utility/formatters/upload_formatter.php =================================================================== --- kernel/utility/formatters/upload_formatter.php (revision 15346) +++ kernel/utility/formatters/upload_formatter.php (working copy) @@ -26,6 +26,14 @@ */ var $fileHelper = NULL; + /** + * Uploaded files, that are ordered as required (both live & temp images in one list) + * + * @var Array + * @access protected + */ + protected $sorting = Array (); + public function __construct() { parent::__construct(); @@ -63,6 +71,8 @@ // SWF Uploader if (is_array($value) && isset($value['tmp_ids'])) { + $this->sorting = isset($value['order']) ? explode('|', $value['order']) : Array (); + if ($value['tmp_deleted']) { $deleted = explode('|', $value['tmp_deleted']); $upload = explode('|', $value['upload']); @@ -78,8 +88,8 @@ } if (!$value['tmp_ids']) { - // no pending files -> return already uploded files - return getArrayValue($value, 'upload'); + // no pending files -> return already uploaded files + return $this->_sortFiles($value['upload']); } $swf_uploaded_ids = explode('|', $value['tmp_ids']); @@ -119,9 +129,11 @@ @chmod($file_name, 0666); $fret[] = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath . $real_name; + + $this->_renameFileInSorting($swf_uploaded_names[$i], $real_name); } - return implode('|', array_merge($existing, $fret)); + return $this->_sortFiles(array_merge($existing, $fret)); } // SWF Uploader END @@ -225,6 +237,42 @@ } /** + * Resorts uploaded files according to given file order + * + * @param Array|string $new_files + * @return string + * @access protected + */ + protected function _sortFiles($files) + { + if ( !is_array($files) ) { + $files = explode('|', $files); + } + + $sorted_files = array_intersect($this->sorting, $files); // removes deleted files from sorting + $new_files = array_diff($files, $sorted_files); // files, that weren't sorted - add to the end + + return implode('|', array_merge($sorted_files, $new_files)); + } + + /** + * Renames file in sorting list + * + * @param string $old_name + * @param string $new_name + * @return void + * @access protected + */ + protected function _renameFileInSorting($old_name, $new_name) + { + $index = array_search($old_name, $this->sorting); + + if ( $index !== false ) { + $this->sorting[$index] = $new_name; + } + } + + /** * Checks, that given file name has on of provided file extensions * * @param string $filename