Skip to content

Commit 7c11cd0

Browse files
authored
[5.2] Error handling while create folder in media manager new pr (#39878)
1 parent 75997cb commit 7c11cd0

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

administrator/components/com_media/resources/scripts/components/modals/create-folder-modal.vue

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,31 @@
3030
type="text"
3131
required
3232
autocomplete="off"
33+
v-bind:class="(isValidName()!==0 && isValid())?'is-invalid':''"
34+
aria-describedby="folderFeedback"
3335
@input="folder = $event.target.value"
3436
>
37+
<div
38+
v-if="isValidName()===1"
39+
id="folderFeedback"
40+
class="invalid-feedback"
41+
>
42+
{{ translate('COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR') }}
43+
</div>
44+
<div
45+
v-if="isValidName()===2"
46+
id="folderFeedback"
47+
class="invalid-feedback"
48+
>
49+
{{ translate('COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR') }}
50+
</div>
51+
<div
52+
v-if="isValidName()===3 && isValid()"
53+
id="folderFeedback"
54+
class="invalid-feedback"
55+
>
56+
{{ translate('COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER') }}
57+
</div>
3558
</div>
3659
</form>
3760
</div>
@@ -46,7 +69,7 @@
4669
</button>
4770
<button
4871
class="btn btn-success"
49-
:disabled="!isValid()"
72+
:disabled="!isValid() || isValidName()!==0"
5073
@click="save()"
5174
>
5275
{{ translate('JACTION_CREATE') }}
@@ -70,6 +93,15 @@ export default {
7093
folder: '',
7194
};
7295
},
96+
computed: {
97+
/* Get the contents of the currently selected directory */
98+
items() {
99+
const directories = this.$store.getters.getSelectedDirectoryDirectories;
100+
const files = this.$store.getters.getSelectedDirectoryFiles;
101+
102+
return [...directories, ...files];
103+
},
104+
},
73105
watch: {
74106
'$store.state.showCreateFolderModal': function (show) {
75107
this.$nextTick(() => {
@@ -79,11 +111,25 @@ export default {
79111
});
80112
},
81113
},
114+
82115
methods: {
83116
/* Check if the form is valid */
84117
isValid() {
85118
return (this.folder);
86119
},
120+
/* Check folder name is valid or not */
121+
isValidName() {
122+
if (this.folder.includes('..')) {
123+
return 1;
124+
}
125+
if ((this.items.filter((file) => file.name.toLowerCase() === (this.folder.toLowerCase())).length !== 0)) {
126+
return 2;
127+
}
128+
if ((!/^[\p{L}\p{N}\-_. ]+$/u.test(this.folder))) {
129+
return 3;
130+
}
131+
return 0;
132+
},
87133
/* Close the modal instance */
88134
close() {
89135
this.reset();

administrator/components/com_media/tmpl/media/default_texts.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
'COM_MEDIA_CREATE_NEW_FOLDER',
2929
'COM_MEDIA_CREATE_NEW_FOLDER_ERROR',
3030
'COM_MEDIA_CREATE_NEW_FOLDER_SUCCESS',
31+
'COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR',
32+
'COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR',
33+
'COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER',
3134
'COM_MEDIA_DECREASE_GRID',
3235
'COM_MEDIA_DELETE_ERROR',
3336
'COM_MEDIA_DELETE_SUCCESS',

administrator/language/en-GB/com_media.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ COM_MEDIA_COPY_FOLDER_NOT_POSSIBLE="Copy folder is not possible"
2525
COM_MEDIA_CREATE_NEW_FOLDER="Create New Folder"
2626
COM_MEDIA_CREATE_NEW_FOLDER_ERROR="Error creating folder."
2727
COM_MEDIA_CREATE_NEW_FOLDER_SUCCESS="Folder created."
28+
COM_MEDIA_CREATE_NEW_FOLDER_EXISTING_FOLDER_ERROR="Folder or file name already exists "
29+
COM_MEDIA_CREATE_NEW_FOLDER_RELATIVE_PATH_ERROR="Use of relative paths not permitted"
30+
COM_MEDIA_CREATE_NEW_FOLDER_UNEXPECTED_CHARACTER="Only Alphanumeric ,underscore(_),hyphen(-) and peroid(.) are allowed"
2831
COM_MEDIA_DECREASE_GRID="Decrease grid size"
2932
COM_MEDIA_DELETE_ERROR="Error deleting the item."
3033
COM_MEDIA_DELETE_NOT_POSSIBLE="Delete not possible!"

0 commit comments

Comments
 (0)