correction bug extension sur le rename des fichiers
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
<template>
 | 
			
		||||
<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>
 | 
			
		||||
        <input
 | 
			
		||||
            type="text"
 | 
			
		||||
@@ -36,10 +36,12 @@ export default {
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    data() {
 | 
			
		||||
        var newFileName = this.initialFileName;
 | 
			
		||||
        var extension = '';
 | 
			
		||||
        let newFileName = this.initialFileName;
 | 
			
		||||
        let extension = '';
 | 
			
		||||
        let nbParts = 1;
 | 
			
		||||
        if(!this.isDirectory) {
 | 
			
		||||
            let nameSplit = newFileName.split('.');
 | 
			
		||||
            nbParts = nameSplit.length;
 | 
			
		||||
            if (nameSplit.length > 1) {
 | 
			
		||||
                extension = nameSplit.pop();
 | 
			
		||||
            }
 | 
			
		||||
@@ -48,6 +50,7 @@ export default {
 | 
			
		||||
        return {
 | 
			
		||||
            newFileName,
 | 
			
		||||
            extension,
 | 
			
		||||
            nbParts
 | 
			
		||||
        };
 | 
			
		||||
    },
 | 
			
		||||
    methods: {
 | 
			
		||||
@@ -75,17 +78,36 @@ export default {
 | 
			
		||||
        },
 | 
			
		||||
        onInputChange() {
 | 
			
		||||
            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;
 | 
			
		||||
 | 
			
		||||
                // Si l'extension est différente de celle d'origine, on la rétablit
 | 
			
		||||
                if (this.extension !== '' && this.newFileName !== newFileNameWithOriginalExtension) {
 | 
			
		||||
                    // Vous pouvez ici vérifier si l'extension a été modifiée et la rétablir
 | 
			
		||||
                    
 | 
			
		||||
                    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>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user