mirror of
https://github.com/xevidos/codiad.git
synced 2024-11-14 07:41:14 +01:00
Continued work on renaming files with invalid characters.
This commit is contained in:
parent
3841525525
commit
6f6e2d0fb6
2 changed files with 28 additions and 12 deletions
|
@ -774,12 +774,12 @@ class Filemanager extends Common {
|
||||||
* trying to rename or delete it, allow the actual file name.
|
* trying to rename or delete it, allow the actual file name.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$invalid_characters = preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path );
|
||||||
|
|
||||||
|
if( $invalid_characters && ! ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) {
|
||||||
if( preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path ) && ! ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) {
|
|
||||||
|
|
||||||
exit( '{"status":"error","message":"Error, the filename contains invalid characters, please either rename or delete it."}' );
|
exit( '{"status":"error","message":"Error, the filename contains invalid characters, please either rename or delete it."}' );
|
||||||
} elseif( preg_match( '/[^A-Za-z0-9\-\._\/\ ]/', $path ) && ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) {
|
} elseif( $invalid_characters && ( $_GET['action'] == "modify" || $_GET['action'] == "delete" ) ) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$path = preg_replace( '/[^A-Za-z0-9\-\._\/\ ]/', '', $path );
|
$path = preg_replace( '/[^A-Za-z0-9\-\._\/\ ]/', '', $path );
|
||||||
|
|
|
@ -296,8 +296,13 @@
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
getType: function(path) {
|
getType: function(path) {
|
||||||
return $('#file-manager a[data-path="' + path + '"]')
|
|
||||||
.attr('data-type');
|
if( path.match( /\\/g ) ) {
|
||||||
|
|
||||||
|
path = path.replace( '\\', '\\\\' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $('#file-manager a[data-path="' + path + '"]').attr('data-type');
|
||||||
},
|
},
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
@ -611,6 +616,7 @@
|
||||||
});
|
});
|
||||||
$('#modal-content form')
|
$('#modal-content form')
|
||||||
.live('submit', function(e) {
|
.live('submit', function(e) {
|
||||||
|
let project = codiad.project.getCurrent();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var shortName = $('#modal-content form input[name="object_name"]')
|
var shortName = $('#modal-content form input[name="object_name"]')
|
||||||
.val();
|
.val();
|
||||||
|
@ -631,7 +637,7 @@
|
||||||
codiad.filemanager.openFile(createPath, true);
|
codiad.filemanager.openFile(createPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
codiad.filemanager.rescan( path );
|
codiad.filemanager.rescan( project );
|
||||||
|
|
||||||
/* Notify listeners. */
|
/* Notify listeners. */
|
||||||
amplify.publish('filemanager.onCreate', {createPath: createPath, path: path, shortName: shortName, type: type});
|
amplify.publish('filemanager.onCreate', {createPath: createPath, path: path, shortName: shortName, type: type});
|
||||||
|
@ -660,6 +666,7 @@
|
||||||
} else if (path == this.clipboard) {
|
} else if (path == this.clipboard) {
|
||||||
codiad.message.error(i18n('Cannot Paste Directory Into Itself'));
|
codiad.message.error(i18n('Cannot Paste Directory Into Itself'));
|
||||||
} else {
|
} else {
|
||||||
|
let project = codiad.project.getCurrent();
|
||||||
var shortName = _this.getShortName(_this.clipboard);
|
var shortName = _this.getShortName(_this.clipboard);
|
||||||
if ($('#file-manager a[data-path="' + path + '/' + shortName + '"]')
|
if ($('#file-manager a[data-path="' + path + '/' + shortName + '"]')
|
||||||
.length) { // Confirm overwrite?
|
.length) { // Confirm overwrite?
|
||||||
|
@ -680,7 +687,7 @@
|
||||||
_this.processPasteNode(path,false);
|
_this.processPasteNode(path,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
codiad.filemanager.rescan( path );
|
codiad.filemanager.rescan( project );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -713,6 +720,7 @@
|
||||||
codiad.modal.load(250, this.dialog, { action: 'rename', path: path, short_name: shortName, type: type});
|
codiad.modal.load(250, this.dialog, { action: 'rename', path: path, short_name: shortName, type: type});
|
||||||
$('#modal-content form')
|
$('#modal-content form')
|
||||||
.live('submit', function(e) {
|
.live('submit', function(e) {
|
||||||
|
let project = codiad.project.getCurrent();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var newName = $('#modal-content form input[name="object_name"]')
|
var newName = $('#modal-content form input[name="object_name"]')
|
||||||
.val();
|
.val();
|
||||||
|
@ -725,11 +733,19 @@
|
||||||
var newPath = temp.join('/') + '/' + newName;
|
var newPath = temp.join('/') + '/' + newName;
|
||||||
$.get(_this.controller, { action: 'modify', path: path, new_name: newName} , function(data) {
|
$.get(_this.controller, { action: 'modify', path: path, new_name: newName} , function(data) {
|
||||||
var renameResponse = codiad.jsend.parse(data);
|
var renameResponse = codiad.jsend.parse(data);
|
||||||
|
let renamedMessage = "";
|
||||||
if (renameResponse != 'error') {
|
if (renameResponse != 'error') {
|
||||||
codiad.message.success(type.charAt(0)
|
|
||||||
.toUpperCase() + type.slice(1) + ' Renamed');
|
if( type == undefined ) {
|
||||||
|
|
||||||
|
renamedMessage = 'Successfully Renamed'
|
||||||
|
} else {
|
||||||
|
|
||||||
|
renamedMessage = type.charAt(0).toUpperCase() + type.slice(1) + ' Renamed'
|
||||||
|
}
|
||||||
|
|
||||||
|
codiad.message.success(renamedMessage);
|
||||||
var node = $('#file-manager a[data-path="' + path + '"]');
|
var node = $('#file-manager a[data-path="' + path + '"]');
|
||||||
let parentPath = node.parent().parent().prev().attr('data-path');
|
|
||||||
// Change pathing and name for node
|
// Change pathing and name for node
|
||||||
node.attr('data-path', newPath)
|
node.attr('data-path', newPath)
|
||||||
.html(newName);
|
.html(newName);
|
||||||
|
@ -745,9 +761,9 @@
|
||||||
// Change any active files
|
// Change any active files
|
||||||
codiad.active.rename(path, newPath);
|
codiad.active.rename(path, newPath);
|
||||||
codiad.modal.unload();
|
codiad.modal.unload();
|
||||||
codiad.filemanager.rescan( parentPath );
|
codiad.filemanager.rescan( project );
|
||||||
/* Notify listeners. */
|
/* Notify listeners. */
|
||||||
amplify.publish('filemanager.onRename', {path: path, newPath: newPath, parentPath: parentPath });
|
amplify.publish('filemanager.onRename', {path: path, newPath: newPath, project: project });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue