correction bug extension sur le rename des fichiers
This commit is contained in:
parent
197ce3f0ea
commit
69d3b09e1f
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="fixed inset-0 flex items-center justify-center bg-gray-700 bg-opacity-50 z-50" @click="closeModal">
|
<div class="fixed inset-0 flex items-center justify-center bg-gray-700 bg-opacity-50 z-50" @click="closeModal">
|
||||||
<div class="dark:bg-NcBlack bg-white rounded-lg shadow-lg p-6 w-96" @click.stop>
|
<div class="bg-NcBlack rounded-lg shadow-lg p-6 w-96" @click.stop>
|
||||||
<h2 class="text-lg font-semibold mb-4">{{ translate('modify.file.name') }}</h2>
|
<h2 class="text-lg font-semibold mb-4">{{ translate('modify.file.name') }}</h2>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@ -36,10 +36,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
var newFileName = this.initialFileName;
|
let newFileName = this.initialFileName;
|
||||||
var extension = '';
|
let extension = '';
|
||||||
|
let nbParts = 1;
|
||||||
if(!this.isDirectory) {
|
if(!this.isDirectory) {
|
||||||
let nameSplit = newFileName.split('.');
|
let nameSplit = newFileName.split('.');
|
||||||
|
nbParts = nameSplit.length;
|
||||||
if (nameSplit.length > 1) {
|
if (nameSplit.length > 1) {
|
||||||
extension = nameSplit.pop();
|
extension = nameSplit.pop();
|
||||||
}
|
}
|
||||||
@ -48,6 +50,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
newFileName,
|
newFileName,
|
||||||
extension,
|
extension,
|
||||||
|
nbParts
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -75,17 +78,36 @@ export default {
|
|||||||
},
|
},
|
||||||
onInputChange() {
|
onInputChange() {
|
||||||
if (!this.isDirectory) {
|
if (!this.isDirectory) {
|
||||||
const fileNameWithoutExtension = this.newFileName.slice(0, this.newFileName.lastIndexOf('.'));
|
this.newFileName = this.removeExtensionSurplus(this.newFileName);
|
||||||
|
let lastIndex = this.newFileName.lastIndexOf('.');
|
||||||
|
let fileNameWithoutExtension;
|
||||||
|
if(lastIndex != -1) {
|
||||||
|
fileNameWithoutExtension = this.newFileName.slice(0, lastIndex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fileNameWithoutExtension = this.newFileName.slice(0);
|
||||||
|
}
|
||||||
|
|
||||||
const newFileNameWithOriginalExtension = fileNameWithoutExtension + '.' + this.extension;
|
const newFileNameWithOriginalExtension = fileNameWithoutExtension + '.' + this.extension;
|
||||||
|
|
||||||
// Si l'extension est différente de celle d'origine, on la rétablit
|
// Si l'extension est différente de celle d'origine, on la rétablit
|
||||||
if (this.extension !== '' && this.newFileName !== newFileNameWithOriginalExtension) {
|
if (this.extension !== '' && this.newFileName !== newFileNameWithOriginalExtension) {
|
||||||
// Vous pouvez ici vérifier si l'extension a été modifiée et la rétablir
|
// Vous pouvez ici vérifier si l'extension a été modifiée et la rétablir
|
||||||
|
|
||||||
this.newFileName = newFileNameWithOriginalExtension;
|
this.newFileName = newFileNameWithOriginalExtension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
removeExtensionSurplus(name){
|
||||||
|
let splitName = name.split('.');
|
||||||
|
|
||||||
|
if(this.nbParts != splitName.length) {
|
||||||
|
let lenExtension = this.extension.length;
|
||||||
|
return name.slice(0, name.length - lenExtension);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user