mirror of
https://github.com/monstra-cms/monstra.git
synced 2025-07-31 18:30:20 +02:00
Files Manager Improvements - Ability to rename Files & Directories #94
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// Add Plugin Javascript
|
||||
Stylesheet::add('plugins/box/filesmanager/css/style.css', 'backend', 11);
|
||||
Javascript::add('plugins/box/filesmanager/js/fileuploader.js', 'backend', 11);
|
||||
Javascript::add('plugins/box/filesmanager/js/filesmanager.js', 'backend', 11);
|
||||
|
||||
// Add plugin navigation link
|
||||
Navigation::add(__('Files', 'filesmanager'), 'content', 'filesmanager', 3);
|
||||
@@ -97,6 +98,47 @@ class FilesmanagerAdmin extends Backend
|
||||
} else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
|
||||
}
|
||||
|
||||
|
||||
// Rename file/dir
|
||||
// -------------------------------------
|
||||
if (Request::post('rename_type')) {
|
||||
|
||||
if (Security::check(Request::post('csrf'))) {
|
||||
|
||||
$rename_type = Request::post('rename_type');
|
||||
$rename_from = Request::post('rename_from');
|
||||
$rename_to = Request::post('rename_to');
|
||||
|
||||
if (empty($rename_to)) {
|
||||
Notification::set('error', __('Can not be empty', 'system'));
|
||||
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
$ext = ($rename_type === 'file') ? '.'. File::ext($rename_from) : '';
|
||||
$rename_to = $files_path . Security::safeName($rename_to).$ext;
|
||||
|
||||
if (is_dir($rename_to)) {
|
||||
Notification::set('error', __('Directory exists', 'system'));
|
||||
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
if (is_file($rename_to)) {
|
||||
Notification::set('error', __('File exists', 'system'));
|
||||
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
|
||||
}
|
||||
|
||||
$success = rename($files_path.$rename_from, $rename_to);
|
||||
|
||||
if ($success) {
|
||||
Notification::set('success', __('Renamed successfully', 'system'));
|
||||
} else {
|
||||
Notification::set('error', __('Failure', 'system'));
|
||||
}
|
||||
Request::redirect($site_url.'/admin/index.php?id=filesmanager&path='.$path);
|
||||
|
||||
} else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); }
|
||||
}
|
||||
|
||||
// Upload file
|
||||
// -------------------------------------
|
||||
if (Request::post('upload_file')) {
|
||||
|
36
plugins/box/filesmanager/js/filesmanager.js
Normal file
36
plugins/box/filesmanager/js/filesmanager.js
Normal file
@@ -0,0 +1,36 @@
|
||||
if (typeof $.monstra == 'undefined') $.monstra = {};
|
||||
|
||||
$.monstra.filesmanager = {
|
||||
|
||||
init: function(){
|
||||
$('#filesDirsList').on('click', '.js-rename-dir', function(e){
|
||||
$.monstra.filesmanager.showRenameDialog(
|
||||
'dir',
|
||||
$(e.currentTarget).attr('data-dirname'),
|
||||
$(e.currentTarget).attr('data-path')
|
||||
);
|
||||
});
|
||||
$('#filesDirsList').on('click', '.js-rename-file', function(e){
|
||||
$.monstra.filesmanager.showRenameDialog(
|
||||
'file',
|
||||
$(e.currentTarget).attr('data-filename'),
|
||||
$(e.currentTarget).attr('data-path')
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
showRenameDialog: function(type, renameFrom, path){
|
||||
var dialog = $('#renameDialog');
|
||||
dialog.find('input[name="rename_type"]').val(type);
|
||||
dialog.find('input[name="rename_from"]').val(renameFrom);
|
||||
dialog.find('input[name="path"]').val(path);
|
||||
dialog.find('#renameToHolder').text(renameFrom);
|
||||
dialog.find('[id$="RenameType"]').hide();
|
||||
dialog.find('#'+ type +'RenameType').show();
|
||||
dialog.modal('show');
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function(){
|
||||
$.monstra.filesmanager.init();
|
||||
});
|
@@ -69,7 +69,7 @@
|
||||
<!-- /Filesmanger_path -->
|
||||
|
||||
|
||||
<table class="table table-bordered">
|
||||
<table class="table table-bordered" id="filesDirsList">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php echo __('Name', 'filesmanager'); ?></th>
|
||||
@@ -92,11 +92,14 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="pull-right">
|
||||
<button class="btn btn-primary js-rename-dir" data-dirname="<?php echo $dir; ?>" data-path="<?php echo $path; ?>">
|
||||
<?php echo __('Rename', 'filesmanager'); ?>
|
||||
</button>
|
||||
<?php echo Html::anchor(__('Delete', 'filesmanager'),
|
||||
'index.php?id=filesmanager&delete_dir='.$dir.'&path='.$path.'&token='.Security::token(),
|
||||
array('class' => 'btn btn-danger', 'onclick' => "return confirmDelete('".__('Delete directory: :dir', 'filesmanager', array(':dir' => $dir))."')"));
|
||||
?>
|
||||
<div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
@@ -118,6 +121,9 @@
|
||||
</td>
|
||||
<td>
|
||||
<div class="pull-right">
|
||||
<button class="btn btn-primary js-rename-file" data-filename="<?php echo $file; ?>" data-path="<?php echo $path; ?>">
|
||||
<?php echo __('Rename', 'filesmanager'); ?>
|
||||
</button>
|
||||
<?php echo Html::anchor(__('Delete', 'filesmanager'),
|
||||
'index.php?id=filesmanager&delete_file='.$file.'&path='.$path.'&token='.Security::token(),
|
||||
array('class' => 'btn btn-danger', 'onclick' => "return confirmDelete('".__('Delete file: :file', 'filesmanager', array(':file' => $file))."')"));
|
||||
@@ -176,3 +182,35 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="renameDialog" class="modal fade" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h4 class="modal-title">Rename</h4>
|
||||
</div>
|
||||
<form role="form" method="POST">
|
||||
<?php echo Form::hidden('csrf', Security::token()); ?>
|
||||
<div class="modal-body">
|
||||
|
||||
<label for="renameTo">
|
||||
<span id="dirRenameType"><?php echo __('Directory:', 'filesmanager'); ?></span>
|
||||
<span id="fileRenameType"><?php echo __('File:', 'filesmanager'); ?></span>
|
||||
<strong id="renameToHolder"></strong>
|
||||
</label>
|
||||
<input type="hidden" name="path" value="" />
|
||||
<input type="hidden" name="rename_type" value="" />
|
||||
<input type="hidden" name="rename_from" value="" />
|
||||
<input type="text" class="form-control" id="renameTo" name="rename_to" />
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary"><?php echo __('Rename', 'filesmanager'); ?></button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user