select fix

This commit is contained in:
2026-07-27 09:45:42 +02:00
parent 1e9132f240
commit 53eb569539
3 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -122,7 +122,7 @@ ActiveAdmin.register_page "Files" do
text_node " "
abs_path = "/softwares/#{entry[:path]}"
a "Select", href: "#", class: "fm-btn fm-btn-select",
onclick: "window.parent.postMessage({type:'file-picked',field:'#{j picker_field}',path:'#{j abs_path}'},'*');return false;"
onclick: "window.parent.filePickerSelect('#{j picker_field}','#{j abs_path}');return false;"
end
# Hidden rename form
@@ -61,17 +61,15 @@
}
}
// Listen for file selection from iframe
window.addEventListener('message', function(event) {
if (event.data && event.data.type === 'file-picked') {
var input = document.getElementById(event.data.field);
if (input) {
input.value = event.data.path;
input.dispatchEvent(new Event('change', { bubbles: true }));
}
closeFilePicker();
// Global callback for iframe to call directly (same-origin)
window.filePickerSelect = function(fieldId, path) {
var input = document.getElementById(fieldId);
if (input) {
input.value = path;
input.dispatchEvent(new Event('change', { bubbles: true }));
}
});
closeFilePicker();
};
document.addEventListener('DOMContentLoaded', addBrowseButtons);
@@ -15,7 +15,7 @@
.fm-btn { display: inline-block; padding: 5px 12px; background: #5a6268; color: #fff; border: none; border-radius: 3px; font-size: 12px; cursor: pointer; text-decoration: none;
&:hover { background: #484e53; color: #fff; }
}
.fm-btn-select { background: #28a745; &:hover { background: #218838; } }
.fm-btn-select { background: #28a745; color: #fff !important; &:hover { background: #218838; color: #fff !important; } &:visited { color: #fff !important; } }
.fm-table {
width: 100%; border-collapse: collapse;
th { background: #f0f0f0; padding: 8px 12px; text-align: left; font-size: 12px; text-transform: uppercase; color: #666; border-bottom: 2px solid #ddd; }