System: Trust: Revocation - work in progress for https://github.com/opnsense/core/issues/7248

move download_content() to opnsense.js for easier re-use.
This commit is contained in:
Ad Schellevis 2024-03-14 14:24:16 +01:00
parent d48dd6f9a3
commit 0591ff28a6
3 changed files with 20 additions and 30 deletions

View File

@ -26,21 +26,6 @@
<script>
'use strict';
function download_content(payload, filename, file_type) {
let a_tag = $('<a></a>').attr('href','data:application/json;charset=utf8,' + encodeURIComponent(payload))
.attr('download', filename).appendTo('body');
a_tag.ready(function() {
if ( window.navigator.msSaveOrOpenBlob && window.Blob ) {
var blob = new Blob( [ payload ], { type: file_type } );
navigator.msSaveOrOpenBlob( blob, 'aliases.json' );
} else {
a_tag.get(0).click();
}
});
}
$( document ).ready(function () {
let grid_cert = $("#grid-cert").UIBootgrid({
search:'/api/trust/ca/search/',

View File

@ -26,21 +26,6 @@
<script>
'use strict';
function download_content(payload, filename, file_type) {
let a_tag = $('<a></a>').attr('href','data:application/json;charset=utf8,' + encodeURIComponent(payload))
.attr('download', filename).appendTo('body');
a_tag.ready(function() {
if ( window.navigator.msSaveOrOpenBlob && window.Blob ) {
var blob = new Blob( [ payload ], { type: file_type } );
navigator.msSaveOrOpenBlob( blob, 'aliases.json' );
} else {
a_tag.get(0).click();
}
});
}
$( document ).ready(function () {
let grid_cert = $("#grid-cert").UIBootgrid({
search:'/api/trust/cert/search/',

View File

@ -332,3 +332,23 @@ function watchScrollPosition() {
});
}
}
/**
* Simple wrapper to download a file received via an api endpoint
* @param {*} payload
* @param {*} filename
* @param {*} file_type
*/
function download_content(payload, filename, file_type) {
let a_tag = $('<a></a>').attr('href','data:application/json;charset=utf8,' + encodeURIComponent(payload))
.attr('download', filename).appendTo('body');
a_tag.ready(function() {
if ( window.navigator.msSaveOrOpenBlob && window.Blob ) {
var blob = new Blob( [ payload ], { type: file_type } );
navigator.msSaveOrOpenBlob( blob, filename);
} else {
a_tag.get(0).click();
}
});
}