[UPDT] ASSET : Data action in asset module and individual delete updated to htmx method
This commit is contained in:
@@ -1,4 +1,22 @@
|
||||
{% load i18n %}
|
||||
|
||||
<!-- start of messages -->
|
||||
{% if messages %}
|
||||
<div class="oh-wrapper">
|
||||
{% for message in messages %}
|
||||
<div class="oh-alert-container">
|
||||
<div class="oh-alert oh-alert--animated {{message.tags}}">
|
||||
{{ message }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<span class="oh-span__class" hx-trigger="load" hx-get="{%url 'asset-list' cat_id=asset.asset_category_id.id %}?{{pd}}"
|
||||
hx-target="#assetCategory{{asset.asset_category_id.id}}"></span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<!-- end of messages -->
|
||||
|
||||
<div class="oh-modal__dialog-header">
|
||||
<span class="oh-modal__dialog-title" id="assetModalLabel">{{asset.asset_name}}</span>
|
||||
<button class="oh-modal__close" aria-label="Close" style="top:17px" >
|
||||
@@ -8,12 +26,12 @@
|
||||
<div class="oh-modal__dialog-body oh-modal__dialog-relative">
|
||||
{% if request.GET.requests_ids %}
|
||||
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
|
||||
<button hx-get="{% url 'asset-information' previous %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev">
|
||||
<button hx-get="{% url 'asset-information' previous %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev" data-action="previous">
|
||||
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron back outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
<button hx-get="{% url 'asset-information' next %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next">
|
||||
<button hx-get="{% url 'asset-information' next %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next" data-action="next">
|
||||
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron forward outline"></ion-icon>
|
||||
</button>
|
||||
@@ -111,9 +129,13 @@
|
||||
>
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>{% trans "Edit" %}
|
||||
</a>
|
||||
<a href="{% url 'asset-delete' asset.id %}?asset_list=asset_filter&{{pg}}" onclick="event.preventDefault();event.stopPropagation(); confirm(`Do you want to delete this asset?`)" class="oh-btn oh-btn--danger" style="width: 50%;">
|
||||
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>{% trans "Delete" %}
|
||||
</a>
|
||||
<form hx-confirm="{% trans 'Do you want to delete this asset?' %}"
|
||||
hx-post="{% url 'asset-delete' asset.id %}?{{pg}}&requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalTarget" onclick="event.stopPropagation()" class="w-50">
|
||||
{% csrf_token %}
|
||||
<button type='submit' class="oh-btn oh-btn--danger w-100" data-action="delete"><ion-icon name="trash-outline" role="img"
|
||||
class="md hydrated" aria-label="create outline"></ion-icon>{% trans "Delete" %}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
class="oh-sticky-table__tr"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#objectDetailsModal"
|
||||
hx-get="{% url 'asset-information' asset_id=asset.id %}?requests_ids={{requests_ids}}"
|
||||
hx-get="{% url 'asset-information' asset_id=asset.id %}?{{pd}}&requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalTarget"
|
||||
id="assetDelete{{asset.id}}"
|
||||
draggable="true"
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
<div class="oh-modal__dialog-body oh-modal__dialog-relative p-0 pt-2">
|
||||
{% if request.GET.requests_ids %}
|
||||
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
|
||||
<button hx-get="{% url "asset-history-single-view" previous %}?requests_ids={{requests_ids}}" hx-target = "#objectDetailsModalTarget" style="left:-90px" class="oh-modal__diaglog-nav oh-modal__nav-prev">
|
||||
<button hx-get="{% url "asset-history-single-view" previous %}?requests_ids={{requests_ids}}" hx-target = "#objectDetailsModalTarget" style="left:-90px" class="oh-modal__diaglog-nav oh-modal__nav-prev" data-action="previous">
|
||||
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron back outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
<button hx-get="{% url "asset-history-single-view" next %}?requests_ids={{requests_ids}}" hx-target = "#objectDetailsModalTarget" style="right:-60px" class="oh-modal__diaglog-nav oh-modal__nav-next">
|
||||
<button hx-get="{% url "asset-history-single-view" next %}?requests_ids={{requests_ids}}" hx-target = "#objectDetailsModalTarget" style="right:-60px" class="oh-modal__diaglog-nav oh-modal__nav-next" data-action="next">
|
||||
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron forward outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
hx-get="{% url 'asset-allocation-individual-view' previous %}?allocations_ids={{allocations_ids}}"
|
||||
hx-target="#objectDetailsModalW25Target"
|
||||
class="oh-modal__diaglog-nav oh-modal__nav-prev"
|
||||
data-action="previous"
|
||||
>
|
||||
<ion-icon
|
||||
name="chevron-back-outline"
|
||||
@@ -17,6 +18,7 @@
|
||||
hx-get="{% url 'asset-allocation-individual-view' next %}?allocations_ids={{allocations_ids}}"
|
||||
hx-target="#objectDetailsModalW25Target"
|
||||
class="oh-modal__diaglog-nav oh-modal__nav-next"
|
||||
data-action="next"
|
||||
>
|
||||
<ion-icon
|
||||
name="chevron-forward-outline"
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<div class="oh-modal__dialog-body">
|
||||
{% if request.GET.assets_ids %}
|
||||
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
|
||||
<button hx-get="{% url 'own-asset-individual-view' previous %}?assets_ids={{assets_ids}}" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev">
|
||||
<button hx-get="{% url 'own-asset-individual-view' previous %}?assets_ids={{assets_ids}}" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev" data-action="previous">
|
||||
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron back outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
<button hx-get="{% url 'own-asset-individual-view' next %}?assets_ids={{assets_ids}}" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next">
|
||||
<button hx-get="{% url 'own-asset-individual-view' next %}?assets_ids={{assets_ids}}" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next" data-action="next">
|
||||
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron forward outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
hx-get="{% url 'asset-request-individual-view' previous %}?requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalW25Target"
|
||||
class="oh-modal__diaglog-nav oh-modal__nav-prev"
|
||||
data-action="previous"
|
||||
>
|
||||
<ion-icon
|
||||
name="chevron-back-outline"
|
||||
@@ -18,6 +19,7 @@
|
||||
hx-get="{% url 'asset-request-individual-view' next %}?requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalW25Target"
|
||||
class="oh-modal__diaglog-nav oh-modal__nav-next"
|
||||
data-action="next"
|
||||
>
|
||||
<ion-icon
|
||||
name="chevron-forward-outline"
|
||||
|
||||
@@ -254,6 +254,10 @@ def asset_delete(request, asset_id):
|
||||
Otherwise, redirect to the asset list view for the asset
|
||||
category of the deleted asset.
|
||||
"""
|
||||
|
||||
request_copy = request.GET.copy()
|
||||
request_copy.pop("requests_ids", None)
|
||||
previous_data = request_copy.urlencode()
|
||||
try:
|
||||
asset = Asset.objects.get(id=asset_id)
|
||||
except Asset.DoesNotExist:
|
||||
@@ -287,13 +291,36 @@ def asset_delete(request, asset_id):
|
||||
asset_del(request, asset)
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
|
||||
instances_ids = request.GET.get("requests_ids")
|
||||
instances_list = json.loads(instances_ids)
|
||||
if status == "In use":
|
||||
messages.info(request, _("Asset is in use"))
|
||||
return redirect(
|
||||
f"/asset/asset-information/{asset.id}/?{previous_data}&requests_ids={instances_list}&asset_info=true"
|
||||
)
|
||||
elif asset_allocation:
|
||||
messages.error(request, _("Asset is used in allocation!."))
|
||||
return redirect(
|
||||
f"/asset/asset-information/{asset.id}/?{previous_data}&requests_ids={instances_list}&asset_info=true"
|
||||
)
|
||||
else:
|
||||
asset_del(request, asset)
|
||||
return redirect(f"/asset/asset-list/{asset_cat_id}")
|
||||
|
||||
if Asset.find(asset.id):
|
||||
return redirect(
|
||||
f"/asset/asset-information/{asset.id}/?{previous_data}&requests_ids={instances_list}&asset_info=true"
|
||||
)
|
||||
else:
|
||||
instances_ids = request.GET.get("requests_ids")
|
||||
instances_list = json.loads(instances_ids)
|
||||
if asset_id in instances_list:
|
||||
instances_list.remove(asset_id)
|
||||
previous_instance, next_instance = closest_numbers(
|
||||
json.loads(instances_ids), asset_id
|
||||
)
|
||||
return redirect(
|
||||
f"/asset/asset-information/{next_instance}/?{previous_data}&requests_ids={instances_list}&asset_info=true"
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user