Delete scripts/vendor/main.js
This commit is contained in:
176
scripts/vendor/main.js
vendored
176
scripts/vendor/main.js
vendored
@@ -1,176 +0,0 @@
|
||||
/**
|
||||
* Storage Saturation Report - Main JavaScript
|
||||
* Loads report via mode=getreport. PDF/Image export via client-side jsPDF + html2canvas (no XI Chromium pipeline).
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
load_report();
|
||||
|
||||
$('#export-pdf-btn').on('click', function() {
|
||||
exportToPdf();
|
||||
});
|
||||
|
||||
$('#export-image-btn').on('click', function() {
|
||||
exportToImage();
|
||||
});
|
||||
|
||||
function load_report() {
|
||||
var baseUrl = window.saturationreportBaseUrl || (window.location.pathname.replace(/\/[^/]*$/, '/index.php'));
|
||||
var url = baseUrl + '?mode=getreport';
|
||||
|
||||
$.get(url, function(html) {
|
||||
$('#report').html(html);
|
||||
}).fail(function() {
|
||||
$('#report').html(
|
||||
'<div class="alert alert-danger">' +
|
||||
'Error loading storage saturation report.' +
|
||||
'</div>'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function getComponentBase() {
|
||||
return (window.saturationreportBaseUrl || '').replace(/\/[^/]*$/, '');
|
||||
}
|
||||
|
||||
function loadScript(src, onload, onerror) {
|
||||
var script = document.createElement('script');
|
||||
script.src = src;
|
||||
script.onload = onload;
|
||||
script.onerror = onerror || function() {};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
function exportToPdf() {
|
||||
var btn = $('#export-pdf-btn');
|
||||
var originalText = btn.html();
|
||||
btn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Generating...');
|
||||
|
||||
function doPdf() {
|
||||
if (typeof html2canvas === 'undefined') {
|
||||
var componentBase = getComponentBase();
|
||||
var localH2c = componentBase ? (componentBase + '/scripts/vendor/html2canvas.min.js') : '';
|
||||
var cdnH2c = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js';
|
||||
loadScript(localH2c || cdnH2c, function() { doPdf(); }, function() {
|
||||
if (localH2c) { loadScript(cdnH2c, doPdf, fallbackPdf); return; }
|
||||
fallbackPdf();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (typeof window.jspdf === 'undefined' || !window.jspdf.jsPDF) {
|
||||
var componentBase = getComponentBase();
|
||||
var localJspdf = componentBase ? (componentBase + '/scripts/vendor/jspdf.umd.min.js') : '';
|
||||
var cdnJspdf = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
|
||||
loadScript(localJspdf || cdnJspdf, doPdf, function() {
|
||||
if (localJspdf) loadScript(cdnJspdf, doPdf, fallbackPdf);
|
||||
else fallbackPdf();
|
||||
});
|
||||
return;
|
||||
}
|
||||
var container = document.getElementById('saturationreport-container');
|
||||
if (!container) container = document.getElementById('report');
|
||||
if (!container) {
|
||||
alert('Report container not found');
|
||||
btn.prop('disabled', false).html(originalText);
|
||||
return;
|
||||
}
|
||||
html2canvas(container, {
|
||||
backgroundColor: '#ffffff',
|
||||
scale: 2,
|
||||
logging: false,
|
||||
useCORS: true
|
||||
}).then(function(canvas) {
|
||||
try {
|
||||
var JsPDF = window.jspdf.jsPDF;
|
||||
var doc = new JsPDF('p', 'mm', 'a4');
|
||||
var pageW = doc.internal.pageSize.getWidth();
|
||||
var pageH = doc.internal.pageSize.getHeight();
|
||||
var margin = 10;
|
||||
var maxW = pageW - 2 * margin;
|
||||
var maxH = pageH - 2 * margin;
|
||||
var imgW = maxW;
|
||||
var imgH = (canvas.height * maxW) / canvas.width;
|
||||
if (imgH > maxH) {
|
||||
imgH = maxH;
|
||||
imgW = (canvas.width * maxH) / canvas.height;
|
||||
}
|
||||
doc.addImage(canvas.toDataURL('image/png'), 'PNG', margin, margin, imgW, imgH);
|
||||
doc.save('storage-saturation-report-' + new Date().getTime() + '.pdf');
|
||||
} catch (err) {
|
||||
console.error('PDF export error:', err);
|
||||
alert('Failed to generate PDF. Try Print to PDF from the browser.');
|
||||
}
|
||||
btn.prop('disabled', false).html(originalText);
|
||||
}).catch(function(err) {
|
||||
console.error('Capture error:', err);
|
||||
fallbackPdf();
|
||||
});
|
||||
}
|
||||
|
||||
function fallbackPdf() {
|
||||
btn.prop('disabled', false).html(originalText);
|
||||
window.print();
|
||||
}
|
||||
|
||||
doPdf();
|
||||
}
|
||||
|
||||
function exportToImage() {
|
||||
if (typeof html2canvas === 'undefined') {
|
||||
var componentBase = (window.saturationreportBaseUrl || '').replace(/\/[^/]*$/, '');
|
||||
var localSrc = componentBase ? (componentBase + '/scripts/vendor/html2canvas.min.js') : '';
|
||||
var cdnSrc = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js';
|
||||
var script = document.createElement('script');
|
||||
script.src = localSrc || cdnSrc;
|
||||
script.onload = function() { captureImage(); };
|
||||
script.onerror = function() {
|
||||
if (localSrc && script.src === localSrc) {
|
||||
var fallback = document.createElement('script');
|
||||
fallback.src = cdnSrc;
|
||||
fallback.onload = function() { captureImage(); };
|
||||
fallback.onerror = function() {
|
||||
alert('Failed to load image export library. Please try using browser screenshot or print-to-PDF instead.');
|
||||
};
|
||||
document.head.appendChild(fallback);
|
||||
} else {
|
||||
alert('Failed to load image export library. Please try using browser screenshot or print-to-PDF instead.');
|
||||
}
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
} else {
|
||||
captureImage();
|
||||
}
|
||||
}
|
||||
|
||||
function captureImage() {
|
||||
var container = document.getElementById('saturationreport-container');
|
||||
if (!container) {
|
||||
container = document.getElementById('report');
|
||||
}
|
||||
if (!container) {
|
||||
alert('Report container not found');
|
||||
return;
|
||||
}
|
||||
|
||||
var btn = $('#export-image-btn');
|
||||
var originalText = btn.html();
|
||||
btn.prop('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Generating...');
|
||||
|
||||
html2canvas(container, {
|
||||
backgroundColor: '#ffffff',
|
||||
scale: 2,
|
||||
logging: false,
|
||||
useCORS: true
|
||||
}).then(function(canvas) {
|
||||
var link = document.createElement('a');
|
||||
link.download = 'saturation-report-' + new Date().getTime() + '.png';
|
||||
link.href = canvas.toDataURL('image/png');
|
||||
link.click();
|
||||
btn.prop('disabled', false).html(originalText);
|
||||
}).catch(function(err) {
|
||||
console.error('Error capturing image:', err);
|
||||
alert('Failed to generate image. Please try using browser screenshot or print-to-PDF instead.');
|
||||
btn.prop('disabled', false).html(originalText);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user