magento2-docker/app/code/IpSupply/DataSheet/view/frontend/templates/widget/datasheetwidget.phtml

80 lines
3.5 KiB
PHTML
Executable File

<?php $dataSheet = $block->getDataSheet(); ?>
<div class="prology-dataSheet page-main">
<link href="<?php echo $block->getAssetUrl('IpSupply_DataSheet::css/datasheet.css'); ?>" type="text/css" rel="stylesheet" />
<div class="prology-block__content">
<!-- <div class="prology-block__content-box grid grid-2-cols align-items-center">
<div class="prology-block__content-text d-flex align-items-start flex-direction-col">
<h2>DATA SHEET</h2>
</div>
</div> -->
<div class="prology-block__content-box grid grid-35/65">
<ul class="stackList">
<div class="prology-filter-form">
<form action="" method="GET">
<input type="hidden" name="page" value="1">
<input id="search_datasheet" type="text" name="search" value="<?= $dataSheet['searchKey'] ?>" placeholder="Enter file name"/>
<button id="btn_search_datasheet" type="submit">Search</button>
</form>
</div>
<?php foreach ($dataSheet["data"] as $item): ?>
<li>
<h3 class="heading">
<?= $item->brand." ".$item->title ?>
</h3>
<span onclick="viewPDF('<?= $item->urlFile ?>')">[View]</span>
<span onclick="saveFileFromUrl('<?= $item->urlFile ?>')">[Download]</span>
</li>
<?php endforeach; ?>
</ul>
<div id="view-pdf" class="border border-radius p-1rem d-none"></div>
</div>
<div class="pagination">
<a href="<?= $dataSheet["previousPage"] ?>">&laquo;</a>
<?php if($dataSheet["haveLeft"] == TRUE): ?>
<a href="">...</a>
<?php endif; ?>
<?php foreach($dataSheet["pagination"] as $item): ?>
<?php if($dataSheet["activePage"] == $item["index"]): ?>
<a class="active" href="<?= $item["url"] ?>"><?= $item["index"] ?></a>
<?php else: ?>
<a href="<?= $item["url"] ?>"><?= $item["index"] ?></a>
<?php endif; ?>
<?php endforeach; ?>
<?php if($dataSheet["haveRight"] == TRUE): ?>
<a href="">...</a>
<?php endif; ?>
<a href="<?= $dataSheet['nextPage'] ?>">&raquo;</a>
</div>
</div>
</div>
<script type="text/javascript">
function viewPDF(fileURL) {
let elementPDF = document.getElementById("view-pdf");
elementPDF.classList.add("d-md-flex");
// elementPDF.style.display = "inline-block";
elementPDF.innerHTML = "<object type='application/pdf' data='"+fileURL+"#navpanes=0' width='100%' height='100%'></object>";
}
async function saveFileFromUrl(url) {
try {
const response = await fetch(url);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = blobUrl;
let splitURL = url.split("/");
link.download = url != "" ? splitURL[splitURL.length - 1] : "download.pdf"
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error("Error saving the file:", error);
}
}
</script>