From f4378054d9a36b3bfabf9b6f13aabcf4712cec0a Mon Sep 17 00:00:00 2001 From: Horilla Date: Tue, 15 Oct 2024 14:15:20 +0530 Subject: [PATCH] [UPDT] ASSET: Replace asset import form load to HTMX --- .../src/asset_category/assetCategoryView.js | 83 +- asset/templates/asset/asset_import.html | 38 +- asset/templates/asset/asset_return_form.html | 4 +- .../category/asset_category_view.html | 314 ++- .../asset_request_allocation_view.html | 14 +- .../request_allocation/group_by.html | 1869 ++++++++--------- asset/views.py | 2 + 7 files changed, 1125 insertions(+), 1199 deletions(-) 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 %} -
- {% csrf_token %} - - -
-{% endblock %} +
+

+ {% trans "Import Assets" %} +

+ +
+
+
+
+ {% csrf_token %} +
+ + + +
+ +
+
diff --git a/asset/templates/asset/asset_return_form.html b/asset/templates/asset/asset_return_form.html index 0a8a2c2b9..ca3e4f890 100644 --- a/asset/templates/asset/asset_return_form.html +++ b/asset/templates/asset/asset_return_form.html @@ -69,9 +69,9 @@ class="oh-btn oh-btn--primary oh-btn--shadow w-100 ml-2" type="button" hx-get="{% url "asset-fine" %}?employee_id={{asset_alocation.assigned_to_employee_id.id}}&asset_id={{asset_id}}" - hx-target="#assetFineModalBody" + hx-target="#dynamicCreateModalTarget" data-toggle="oh-modal-toggle" - data-target="#assetFineModal" + data-target="#dynamicCreateModal" > {% trans "Add Fine" %} diff --git a/asset/templates/category/asset_category_view.html b/asset/templates/category/asset_category_view.html index 303b65a03..a8c77cf97 100644 --- a/asset/templates/category/asset_category_view.html +++ b/asset/templates/category/asset_category_view.html @@ -10,35 +10,37 @@ .button-link { display: inline-block; padding: 12px 15px; - background-color: #F0EFEF; /* Change this to your desired button color */ - color: #312D2D; /* Text color for the button */ + background-color: #F0EFEF; + /* Change this to your desired button color */ + color: #312D2D; + /* Text color for the button */ text-align: center; text-decoration: none; cursor: pointer; } .oh-modal_close--custom { - border: none; - background: none; - font-size: 1.5rem; - opacity: 0.7; - position: absolute; - top: 25px; - right: 15px; + border: none; + background: none; + font-size: 1.5rem; + opacity: 0.7; + position: absolute; + top: 25px; + right: 15px; } - + {% if messages %} -
- {% for message in messages %} -
-
- {{ message }} +
+ {% for message in messages %} +
+
+ {{ message }} +
+ {% endfor %}
- {% endfor %} -
{% endif %} @@ -56,31 +58,22 @@
-
+ - - {% comment %} +
- - - - - {% comment %}
- - -
{% endcomment %} -
- +
{% if perms.asset.add_assetcategory %} - {% endif %} + {% endif %}
-
- - + diff --git a/asset/views.py b/asset/views.py index 346007342..42bc64df1 100644 --- a/asset/views.py +++ b/asset/views.py @@ -1056,6 +1056,8 @@ def asset_import(request): Returns: HttpResponseRedirect: A redirect to the asset category view after processing the import. """ + if request.META.get("HTTP_HX_REQUEST"): + return render(request, "asset/asset_import.html") try: if request.method == "POST": file = request.FILES.get("asset_import")