Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
fix double rename error
Browse files Browse the repository at this point in the history
fix double rename error and refactoring
  • Loading branch information
trippo committed Aug 4, 2018
1 parent 4a7ba24 commit 2023765
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
13 changes: 7 additions & 6 deletions filemanager/dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ function extensionSort($x, $y) {
$file_prevent_rename = isset($filePermissions[$file]['prevent_rename']) && $filePermissions[$file]['prevent_rename'];
$file_prevent_delete = isset($filePermissions[$file]['prevent_delete']) && $filePermissions[$file]['prevent_delete'];
}
?><figure data-name="<?php echo $file ?>" class="<?php if($file=="..") echo "back-";?>directory" data-type="<?php if($file!=".."){ echo "dir"; } ?>">
?><figure data-name="<?php echo $file ?>" data-path="<?php echo $rfm_subfolder.$subdir.$file;?>" class="<?php if($file=="..") echo "back-";?>directory" data-type="<?php if($file!=".."){ echo "dir"; } ?>">
<?php if($file==".."){ ?>
<input type="hidden" class="path" value="<?php echo str_replace('.','',dirname($rfm_subfolder.$subdir));?>"/>
<input type="hidden" class="path_thumb" value="<?php echo dirname($thumbs_path.$subdir)."/";?>"/>
Expand Down Expand Up @@ -1008,9 +1008,9 @@ function extensionSort($x, $y) {
<?php } ?>
<div class='file-extension'><?php echo fix_strtolower(trans('Type_dir'));?></div>
<figcaption>
<a href="javascript:void('')" class="tip-left edit-button rename-file-paths <?php if($rename_folders && !$file_prevent_rename) echo "rename-folder";?>" title="<?php echo trans('Rename')?>" data-folder="1" data-permissions="<?php echo $file_array['permissions']; ?>" data-path="<?php echo $rfm_subfolder.$subdir.$file;?>">
<a href="javascript:void('')" class="tip-left edit-button rename-file-paths <?php if($rename_folders && !$file_prevent_rename) echo "rename-folder";?>" title="<?php echo trans('Rename')?>" data-folder="1" data-permissions="<?php echo $file_array['permissions']; ?>">
<i class="icon-pencil <?php if(!$rename_folders || $file_prevent_rename) echo 'icon-white';?>"></i></a>
<a href="javascript:void('')" class="tip-left erase-button <?php if($delete_folders && !$file_prevent_delete) echo "delete-folder";?>" title="<?php echo trans('Erase')?>" data-confirm="<?php echo trans('Confirm_Folder_del');?>" data-path="<?php echo $rfm_subfolder.$subdir.$file;?>" >
<a href="javascript:void('')" class="tip-left erase-button <?php if($delete_folders && !$file_prevent_delete) echo "delete-folder";?>" title="<?php echo trans('Erase')?>" data-confirm="<?php echo trans('Confirm_Folder_del');?>" >
<i class="icon-trash <?php if(!$delete_folders || $file_prevent_delete) echo 'icon-white';?>"></i>
</a>
</figcaption>
Expand Down Expand Up @@ -1145,7 +1145,8 @@ function extensionSort($x, $y) {
$file_prevent_rename = isset($filePermissions[$file]['prevent_rename']) && $filePermissions[$file]['prevent_rename'];
$file_prevent_delete = isset($filePermissions[$file]['prevent_delete']) && $filePermissions[$file]['prevent_delete'];
}
?> <figure data-name="<?php echo $file ?>" data-type="<?php if($is_img){ echo "img"; }else{ echo "file"; } ?>">
?>
<figure data-name="<?php echo $file ?>" data-path="<?php echo $rfm_subfolder.$subdir.$file;?>" data-type="<?php if($is_img){ echo "img"; }else{ echo "file"; } ?>">
<a href="javascript:void('')" class="link" data-file="<?php echo $file;?>" data-function="<?php echo $apply;?>">
<div class="img-precontainer">
<?php if($is_icon_thumb){ ?><div class="filetype"><?php echo $file_array['extension'] ?></div><?php } ?>
Expand Down Expand Up @@ -1215,10 +1216,10 @@ function extensionSort($x, $y) {
<?php }else{ ?>
<a class="preview disabled"><i class="icon-eye-open icon-white"></i></a>
<?php } ?>
<a href="javascript:void('')" class="tip-left edit-button rename-file-paths <?php if($rename_files && !$file_prevent_rename) echo "rename-file";?>" title="<?php echo trans('Rename')?>" data-folder="0" data-permissions="<?php echo $file_array['permissions']; ?>" data-path="<?php echo $rfm_subfolder.$subdir .$file;?>">
<a href="javascript:void('')" class="tip-left edit-button rename-file-paths <?php if($rename_files && !$file_prevent_rename) echo "rename-file";?>" title="<?php echo trans('Rename')?>" data-folder="0" data-permissions="<?php echo $file_array['permissions']; ?>">
<i class="icon-pencil <?php if(!$rename_files || $file_prevent_rename) echo 'icon-white';?>"></i></a>

<a href="javascript:void('')" class="tip-left erase-button <?php if($delete_files && !$file_prevent_delete) echo "delete-file";?>" title="<?php echo trans('Erase')?>" data-confirm="<?php echo trans('Confirm_del');?>" data-path="<?php echo $rfm_subfolder.$subdir.$file;?>">
<a href="javascript:void('')" class="tip-left erase-button <?php if($delete_files && !$file_prevent_delete) echo "delete-file";?>" title="<?php echo trans('Erase')?>" data-confirm="<?php echo trans('Confirm_del');?>">
<i class="icon-trash <?php if(!$delete_files || $file_prevent_delete) echo 'icon-white';?>"></i>
</a>
</form>
Expand Down
80 changes: 39 additions & 41 deletions resources/assets/js/include.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
{
"use strict";

var version = "9.13.0";
var version = "9.13.3";
var active_contextmenu = true;
var myLazyLoad = null;
var clipboard = null;
Expand Down Expand Up @@ -450,8 +450,8 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
grid.on('click', '.rename-file', function ()
{
var _this = jQuery(this);

var file_container = _this.parent().parent().parent();
var file_container = _this.closest('figure');
var path = file_container.attr('data-path');
var file_title = file_container.find('h4');
var old_name = $.trim(file_title.text());
bootbox.prompt(jQuery('#rename').val(), jQuery('#cancel').val(), jQuery('#ok').val(), function (name)
Expand All @@ -461,7 +461,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
name = fix_filename(name);
if (name != old_name)
{
execute_action('rename_file', _this.attr('data-path'), name, file_container, 'apply_file_rename');
execute_action('rename_file', path, name, file_container, 'apply_file_rename');
}
}
}, old_name);
Expand All @@ -470,8 +470,9 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
grid.on('click', '.rename-folder', function ()
{
var _this = jQuery(this);
var file_container = _this.closest('figure');
var path = file_container.attr('data-path');

var file_container = _this.parent().parent().parent();
var file_title = file_container.find('h4');
var old_name = $.trim(file_title.text());
bootbox.prompt(jQuery('#rename').val(), jQuery('#cancel').val(), jQuery('#ok').val(), function (name)
Expand All @@ -481,7 +482,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
name = fix_filename(name).replace('.', '');
if (name != old_name)
{
execute_action('rename_folder', _this.attr('data-path'), name, file_container, 'apply_folder_rename');
execute_action('rename_folder', path, name, file_container, 'apply_folder_rename');
}
}
}, old_name);
Expand All @@ -490,11 +491,12 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
grid.on('click', '.delete-file', function ()
{
var _this = jQuery(this);
var path = _this.closest('figure').attr('data-path');
bootbox.confirm(_this.attr('data-confirm'), jQuery('#cancel').val(), jQuery('#ok').val(), function (result)
{
if (result == true)
{
execute_action('delete_file', _this.attr('data-path'), '', '', '');
execute_action('delete_file', path, '', '', '');
var fil = jQuery('#files_number');
fil.text(parseInt(fil.text())-1);
_this.parent().parent().parent().parent().remove();
Expand All @@ -505,12 +507,13 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
grid.on('click', '.delete-folder', function ()
{
var _this = jQuery(this);
var path = _this.closest('figure').attr('data-path');

bootbox.confirm(_this.attr('data-confirm'), jQuery('#cancel').val(), jQuery('#ok').val(), function (result)
{
if (result == true)
{
execute_action('delete_folder', _this.attr('data-path'), '', '', '');
execute_action('delete_folder', path, '', '', '');
var fol = jQuery('#folders_number');
fol.text(parseInt(fol.text())-1);
_this.parent().parent().parent().remove();
Expand Down Expand Up @@ -1210,7 +1213,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
// remove to prevent duplicates
jQuery('#textfile_edit_area').parent().parent().remove();

var full_path = $trigger.find('.rename-file-paths').attr('data-path');
var full_path = $trigger.closest('figure').attr('data-path');

$.ajax({
type: "POST",
Expand Down Expand Up @@ -1309,7 +1312,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
jQuery('#files_permission_start').parent().parent().remove();

var obj = $trigger.find('.rename-file-paths');
var full_path = obj.attr('data-path');
var full_path = $trigger.closest('figure').attr('data-path');
var permissions = obj.attr('data-permissions');
var folder = obj.attr('data-folder');

Expand Down Expand Up @@ -1529,14 +1532,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any

var thumb_path, full_path;

if (!$trigger.hasClass('directory'))
{
full_path = $trigger.find('.rename-file-paths').attr('data-path');
}
else
{
full_path = $trigger.find('.rename-file-paths').attr('data-path');
}
full_path = $trigger.closest('figure').attr('data-path');

$.ajax({
type: "POST",
Expand Down Expand Up @@ -1568,7 +1564,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
var folder_path;
if (typeof dnd != 'undefined')
{
folder_path = dnd.find('.rename-folder').attr('data-path');
folder_path = dnd.closest('figure').attr('data-path');
}
else
{
Expand Down Expand Up @@ -1616,7 +1612,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
obj = $trigger.find('.rename-folder');
}

var full_path = obj.attr('data-path');
var full_path = $trigger.closest('figure').attr('data-path');

$trigger.parent().hide(100);

Expand Down Expand Up @@ -1644,7 +1640,7 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
}
else
{
folder_path = dnd.find('.rename-folder').attr('data-path');
folder_path = dnd.closest('figure').attr('data-path');
}
}
else
Expand Down Expand Up @@ -2186,18 +2182,27 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any

var old_name = file.substring(file.lastIndexOf('/') + 1);
var extension = file.substring(file.lastIndexOf('.') + 1);
if(extension){
extension = "."+extension;
}else{
extension = '';
}

link.each(function ()
{
jQuery(this).attr('data-file', encodeURIComponent(name + "." + extension));
jQuery(this).attr('data-file', encodeURIComponent(name + extension));
});

//thumbnails
container.find('img').each(function ()
{
var src = jQuery(this).attr('src');

jQuery(this).attr('src', src.replace(old_name, name + "." + extension) + '?time=' + new Date().getTime());
if(src){
jQuery(this).attr('src', src.replace(old_name, name + extension) + '?time=' + new Date().getTime());
}else{
var src = jQuery(this).attr('data-src');
jQuery(this).attr('data-src', src.replace(old_name, name + extension) + '?time=' + new Date().getTime());
}
jQuery(this).attr('alt', name + " thumbnails");
});

Expand All @@ -2206,25 +2211,21 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
file = link2.attr('data-url');
if (typeof file !== "undefined" && file)
{
link2.attr('data-url', file.replace(encodeURIComponent(old_name), encodeURIComponent(name + "." + extension)));
link2.attr('data-url', file.replace(encodeURIComponent(old_name), encodeURIComponent(name + extension)));
}

//li data-name
container.parent().attr('data-name', name + "." + extension);
container.attr('data-name', name + "." + extension);
container.parent().attr('data-name', name + extension);
container.attr('data-name', name + extension);

//download link
container.find('.name_download').val(name + "." + extension);

//rename link && delete link
var link3 = container.find('a.rename-file');
var link4 = container.find('a.delete-file');
container.find('.name_download').val(name + extension);

var path_old = link3.attr('data-path');
var new_path = path_old.replace(old_name, name + "." + extension);
//rename path
var path_old = container.attr('data-path');
var new_path = path_old.replace(old_name, name + extension);

link3.attr('data-path', new_path);
link4.attr('data-path', new_path);
container.attr('data-path', new_path);
}

apply_folder_rename = function (container, name)
Expand All @@ -2247,13 +2248,10 @@ var encodeURL,show_animation,hide_animation,apply,apply_none,apply_img,apply_any
});

//rename link && delete link
var link2 = container.find('a.delete-folder');
var link3 = container.find('a.rename-folder');
var path_old = link3.attr('data-path');
var path_old = container.attr('data-path');
var index = path_old.lastIndexOf('/');
var new_path = path_old.substr(0, index + 1) + name;
link2.attr('data-path', new_path);
link3.attr('data-path', new_path);
container.attr('data-path', new_path);

}

Expand Down

0 comments on commit 2023765

Please sign in to comment.