diff --git a/asset/static/src/asset_category/assetCategoryView.js b/asset/static/src/asset_category/assetCategoryView.js index 6babcb245..8e4ecc151 100644 --- a/asset/static/src/asset_category/assetCategoryView.js +++ b/asset/static/src/asset_category/assetCategoryView.js @@ -47,6 +47,48 @@ function getCurrentLanguageCode(callback) { } } +function getAssetImportTemplate() { + var languageCode = null; + getCurrentLanguageCode(function (code) { + languageCode = code; + var confirmMessage = downloadMessages[languageCode]; + // Use SweetAlert for the confirmation dialog + Swal.fire({ + text: confirmMessage, + icon: "question", + showCancelButton: true, + confirmButtonColor: "#008000", + cancelButtonColor: "#d33", + confirmButtonText: "Confirm", + }).then(function (result) { + if (result.isConfirmed) { + $.ajax({ + type: "GET", + url: "/asset/asset-excel", + dataType: "binary", + xhrFields: { + responseType: "blob", + }, + success: function (response) { + const file = new Blob([response], { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + }); + const url = URL.createObjectURL(file); + const link = document.createElement("a"); + link.href = url; + link.download = "my_excel_file.xlsx"; + document.body.appendChild(link); + link.click(); + }, + error: function (xhr, textStatus, errorThrown) { + console.error("Error downloading file:", errorThrown); + }, + }); + } + }); + }); +} + $(document).ready(function () { $("#import-dropdown").hide(); // asset category accordion @@ -102,45 +144,8 @@ $(document).ready(function () { }); }); + $(".asset-info-import").click(function (e) { e.preventDefault(); - var languageCode = null; - getCurrentLanguageCode(function (code) { - languageCode = code; - var confirmMessage = downloadMessages[languageCode]; - // Use SweetAlert for the confirmation dialog - Swal.fire({ - text: confirmMessage, - icon: "question", - showCancelButton: true, - confirmButtonColor: "#008000", - cancelButtonColor: "#d33", - confirmButtonText: "Confirm", - }).then(function (result) { - if (result.isConfirmed) { - $.ajax({ - type: "GET", - url: "/asset/asset-excel", - dataType: "binary", - xhrFields: { - responseType: "blob", - }, - success: function (response) { - const file = new Blob([response], { - type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - }); - const url = URL.createObjectURL(file); - const link = document.createElement("a"); - link.href = url; - link.download = "my_excel_file.xlsx"; - document.body.appendChild(link); - link.click(); - }, - error: function (xhr, textStatus, errorThrown) { - console.error("Error downloading file:", errorThrown); - }, - }); - } - }); - }); + getAssetImportTemplate(); }); diff --git a/asset/templates/asset/asset_import.html b/asset/templates/asset/asset_import.html index 0c06b0fca..9a5a0fc50 100644 --- a/asset/templates/asset/asset_import.html +++ b/asset/templates/asset/asset_import.html @@ -1,9 +1,31 @@ -{% extends 'index.html' %} {% load i18n %} -{% block content %} -
-{% endblock %} +