Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes that the media library uses the wrong file extensions #16449

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
}

var urlValue = $('#uploadFiles').val();
var allowedExtensions = $('#allowedExtensions').val();
if (allowedExtensions && allowedExtensions !== "") {
urlValue = urlValue + (urlValue.indexOf('?') == -1 ? '?' : '&') + "extensions=" + encodeURIComponent(allowedExtensions);
}

return urlValue + (urlValue.indexOf('?') == -1 ? '?' : '&') + "path=" + encodeURIComponent(this.selectedFolder.path);
},
Expand All @@ -233,6 +237,10 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
this.selectedMedias = [];
var self = this;
var mediaUrl = $('#getMediaItemsUrl').val();
var allowedExtensions = $('#allowedExtensions').val();
if (allowedExtensions && allowedExtensions !== "") {
mediaUrl = mediaUrl + (mediaUrl.indexOf('?') == -1 ? '?' : '&') + "extensions=" + encodeURIComponent(allowedExtensions);
}
console.log(folder.path);
$.ajax({
url: mediaUrl + (mediaUrl.indexOf('?') == -1 ? '?' : '&') + "path=" + encodeURIComponent(folder.path),
Expand All @@ -252,6 +260,12 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
}
});
},
refresh: function () {
var self = this;
if (self.selectedFolder) {
self.loadFolder(self.selectedFolder);
}
},
selectAll: function () {
this.selectedMedias = [];
for (var i = 0; i < this.filteredMediaItems.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple, allowMediaText, allowAnchors) {
function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple, allowMediaText, allowAnchors, allowedExtensions) {
//BagPart create a script section without other DOM elements
if(el === null)
return;
Expand Down Expand Up @@ -27,6 +27,7 @@ function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple,
allowMediaText: allowMediaText,
backupMediaText: '',
allowAnchors: allowAnchors,
allowedExtensions: allowedExtensions,
backupAnchor: null,
mediaTextModal: null,
anchoringModal: null
Expand Down Expand Up @@ -140,9 +141,13 @@ function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple,
showModal: function (event) {
var self = this;
if (self.canAddMedia) {
$('#allowedExtensions').val(this.allowedExtensions);
$("#mediaApp").appendTo($(modalBodyElement).find('.modal-body'));
$("#mediaApp").show();

// Reload current folder in case the allowed extensions have changed.
mediaApp.refresh();

var modal = new bootstrap.Modal(modalBodyElement);
modal.show();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@
<input type="hidden" id="getFoldersUrl" value="@Url.Action("GetFolders", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="deleteFolderUrl" value="@Url.Action("DeleteFolder", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="createFolderUrl" value="@Url.Action("CreateFolder", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="getMediaItemsUrl" value="@Url.Action("GetMediaItems", "Admin", new { area = "OrchardCore.Media", extensions = Model.Extensions })" />
<input type="hidden" id="getMediaItemsUrl" value="@Url.Action("GetMediaItems", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="deleteMediaUrl" value="@Url.Action("DeleteMedia", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="renameMediaUrl" value="@Url.Action("MoveMedia", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="deleteMediaListUrl" value="@Url.Action("DeleteMediaList", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="moveMediaListUrl" value="@Url.Action("MoveMediaList", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="uploadFiles" value="@Url.Action("Upload", "Admin", new { area = "OrchardCore.Media", extensions = Model.Extensions })" />
<input type="hidden" id="uploadFiles" value="@Url.Action("Upload", "Admin", new { area = "OrchardCore.Media" })" />
<input type="hidden" id="allowedExtensions" value="@Model.Extensions" />

@* Settings *@
<input type="hidden" id="allowNewRootFolders" value="@(Model.AllowNewRootFolders ? "true" : "false")" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
document.getElementById('@Html.IdFor(m => m)'),
document.getElementById('@Html.IdFor(m => m)-ModalBody'),
'@Url.Action("GetMediaItem", "Admin", new { area = "OrchardCore.Media" })',
@(settings.Multiple ? "true" : "false"),
@(settings.AllowMediaText ? "true" : "false"),
@(settings.AllowAnchors ? "true" : "false"));
@(settings.Multiple ? "true" : "false"),
@(settings.AllowMediaText ? "true" : "false"),
@(settings.AllowAnchors ? "true" : "false"),
'@string.Join(',', Model.AllowedExtensions)');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,10 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
return null;
}
var urlValue = $('#uploadFiles').val();
var allowedExtensions = $('#allowedExtensions').val();
if (allowedExtensions && allowedExtensions !== "") {
urlValue = urlValue + (urlValue.indexOf('?') == -1 ? '?' : '&') + "extensions=" + encodeURIComponent(allowedExtensions);
}
return urlValue + (urlValue.indexOf('?') == -1 ? '?' : '&') + "path=" + encodeURIComponent(this.selectedFolder.path);
},
selectRoot: function selectRoot() {
Expand All @@ -1773,6 +1777,10 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
this.selectedMedias = [];
var self = this;
var mediaUrl = $('#getMediaItemsUrl').val();
var allowedExtensions = $('#allowedExtensions').val();
if (allowedExtensions && allowedExtensions !== "") {
mediaUrl = mediaUrl + (mediaUrl.indexOf('?') == -1 ? '?' : '&') + "extensions=" + encodeURIComponent(allowedExtensions);
}
console.log(folder.path);
$.ajax({
url: mediaUrl + (mediaUrl.indexOf('?') == -1 ? '?' : '&') + "path=" + encodeURIComponent(folder.path),
Expand All @@ -1792,6 +1800,12 @@ function initializeMediaApplication(displayMediaApplication, mediaApplicationUrl
}
});
},
refresh: function refresh() {
var self = this;
if (self.selectedFolder) {
self.loadFolder(self.selectedFolder);
}
},
selectAll: function selectAll() {
this.selectedMedias = [];
for (var i = 0; i < this.filteredMediaItems.length; i++) {
Expand Down Expand Up @@ -2991,7 +3005,7 @@ Vue.component('mediaFieldThumbsContainer', {
}
}
});
function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple, allowMediaText, allowAnchors) {
function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple, allowMediaText, allowAnchors, allowedExtensions) {
//BagPart create a script section without other DOM elements
if (el === null) return;
var target = $(document.getElementById($(el).data('for')));
Expand All @@ -3016,6 +3030,7 @@ function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple,
allowMediaText: allowMediaText,
backupMediaText: '',
allowAnchors: allowAnchors,
allowedExtensions: allowedExtensions,
backupAnchor: null,
mediaTextModal: null,
anchoringModal: null
Expand Down Expand Up @@ -3139,8 +3154,12 @@ function initializeMediaField(el, modalBodyElement, mediaItemUrl, allowMultiple,
showModal: function showModal(event) {
var self = this;
if (self.canAddMedia) {
$('#allowedExtensions').val(this.allowedExtensions);
$("#mediaApp").appendTo($(modalBodyElement).find('.modal-body'));
$("#mediaApp").show();

// Reload current folder in case the allowed extensions have changed.
mediaApp.refresh();
var modal = new bootstrap.Modal(modalBodyElement);
modal.show();
$(modalBodyElement).find('.mediaFieldSelectButton').off('click').on('click', function (v) {
Expand Down

Large diffs are not rendered by default.