[UPDT] BASE: Base app request comments delete and file delete HTMX attributes

This commit is contained in:
Horilla
2024-11-14 15:35:44 +05:30
parent 3b8b198ecd
commit 5a3e6488d0
9 changed files with 485 additions and 756 deletions

View File

@@ -61,138 +61,138 @@
</div>
<div class="oh-sticky-table__tbody">
{% for shift_request in data %}
<div class="oh-sticky-table__tr" draggable="true"
hx-get="{% url 'shift-request-details' shift_request.id %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget" data-toggle='oh-modal-toggle'
data-target='#objectDetailsModal'>
<div class="oh-sticky-table__sd {% if shift_request.approved %} row-status--yellow {% elif shift_request.canceled %} row-status--red {% endif %}" onclick="event.stopPropagation();">
<div class="centered-div">
<input type="checkbox" id="{{shift_request.id}}" onchange="highlightRow($(this))" class="oh-input employee-checkbox oh-input__checkbox all-shift-requests-row" />
</div>
</div>
<div class="oh-sticky-table__td">
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
<img src="{{shift_request.employee_id.get_avatar}}" class="oh-profile__image"
alt="Username">
<div class="oh-sticky-table__tr" draggable="true"
hx-get="{% url 'shift-request-details' shift_request.id %}?instances_ids={{requests_ids}}"
hx-target="#objectDetailsModalTarget" data-toggle='oh-modal-toggle'
data-target='#objectDetailsModal'>
<div class="oh-sticky-table__sd {% if shift_request.approved %} row-status--yellow {% elif shift_request.canceled %} row-status--red {% endif %}" onclick="event.stopPropagation();">
<div class="centered-div">
<input type="checkbox" id="{{shift_request.id}}" onchange="highlightRow($(this))" class="oh-input employee-checkbox oh-input__checkbox all-shift-requests-row" />
</div>
<span class="oh-profile__name oh-text--dark">{{shift_request.employee_id}}</span>
</div>
</div>
<div class="oh-sticky-table__td" data-cell-index="2">{{shift_request.shift_id}}</div>
<div class="oh-sticky-table__td" data-cell-index="3">{{shift_request.previous_shift_id}}
</div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="4">
{{shift_request.requested_date}}</div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="5">
{{shift_request.requested_till}}</div>
<div class="oh-sticky-table__td" data-cell-index="6">
{% if shift_request.approved %}
{% trans "Approved" %}
{% elif shift_request.canceled %}
{% trans "Rejected" %}
{% else %}
{% trans "Requested" %}
{% endif %}
</div>
<div class="oh-sticky-table__td">
<div class="oh-profile oh-profile--md">
<div class="oh-profile__avatar mr-1">
<img src="{{shift_request.employee_id.get_avatar}}" class="oh-profile__image"
alt="Username">
</div>
<span class="oh-profile__name oh-text--dark">{{shift_request.employee_id}}</span>
</div>
</div>
<div class="oh-sticky-table__td" data-cell-index="2">{{shift_request.shift_id}}</div>
<div class="oh-sticky-table__td" data-cell-index="3">{{shift_request.previous_shift_id}}
</div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="4">
{{shift_request.requested_date}}</div>
<div class="oh-sticky-table__td dateformat_changer" data-cell-index="5">
{{shift_request.requested_till}}</div>
<div class="oh-sticky-table__td" data-cell-index="6">
{% if shift_request.approved %}
{% trans "Approved" %}
{% elif shift_request.canceled %}
{% trans "Rejected" %}
{% else %}
{% trans "Requested" %}
{% endif %}
</div>
<div class="oh-sticky-table__td" data-cell-index="7">
{{shift_request.description|truncatechars:30}}
</div>
<div class="oh-sticky-table__td" data-cell-index="7">
{{shift_request.description|truncatechars:30}}
</div>
<div class="oh-sticky-table__td" onclick="event.stopPropagation();">
<button type="button" hx-get="{% url 'view-shift-comment' shift_request.id %}"
hx-target="#commentContainer" data-target='#activitySidebar' title="View Comment"
class="oh-btn oh-btn--light oh-activity-sidebar__open w-100"
style="flex: 1 0 auto; width:20px;height: 40.68px; padding: 0;"
onclick="event.stopPropagation()">
<ion-icon name="newspaper-outline" role="img" class="md hydrated"
aria-label="newspaper outline"></ion-icon>
</button>
</div>
<div class="oh-sticky-table__td" onclick="event.stopPropagation();">
<button type="button" hx-get="{% url 'view-shift-comment' shift_request.id %}"
hx-target="#commentContainer" data-target='#activitySidebar' title="View Comment"
class="oh-btn oh-btn--light oh-activity-sidebar__open w-100"
style="flex: 1 0 auto; width:20px;height: 40.68px; padding: 0;"
onclick="event.stopPropagation()">
<ion-icon name="newspaper-outline" role="img" class="md hydrated"
aria-label="newspaper outline"></ion-icon>
</button>
</div>
<div class="oh-sticky-table__td" onclick="event.stopPropagation();">
{% if request.user.employee_get == shift_request.employee_id or perms.base.change_shiftrequest or perms.base.add_shiftrequest or perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
<div class="oh-btn-group">
{% if request.user.employee_get == shift_request.employee_id or perms.base.change_shiftrequest or request.user|is_reportingmanager %}
{% if shift_request.approved == False and not shift_request.canceled %}
<a hx-get="{% url 'shift-request-update' shift_request.id %}"
hx-target='#shiftRequestModalUpdateBody' data-toggle="oh-modal-toggle"
data-target='#shiftRequestModalUpdate' class="oh-btn oh-btn--light-bkg w-50"
title="{% trans 'Edit' %}"><ion-icon name="create-outline"></ion-icon></a>
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled><ion-icon name="create-outline"></ion-icon></button></td>
<div class="oh-sticky-table__td" onclick="event.stopPropagation();">
{% if request.user.employee_get == shift_request.employee_id or perms.base.change_shiftrequest or perms.base.add_shiftrequest or perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
<div class="oh-btn-group">
{% if request.user.employee_get == shift_request.employee_id or perms.base.change_shiftrequest or request.user|is_reportingmanager %}
{% if shift_request.approved == False and not shift_request.canceled %}
<a hx-get="{% url 'shift-request-update' shift_request.id %}"
hx-target='#shiftRequestModalUpdateBody' data-toggle="oh-modal-toggle"
data-target='#shiftRequestModalUpdate' class="oh-btn oh-btn--light-bkg w-50"
title="{% trans 'Edit' %}"><ion-icon name="create-outline"></ion-icon></a>
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled><ion-icon name="create-outline"></ion-icon></button></td>
{% endif %}
{% endif %}
{% endif %}
{% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequest or request.user|is_reportingmanager %}
<a class="oh-btn oh-btn--light-bkg w-50" data-toggle="oh-modal-toggle"
data-target="#objectCreateModal"
hx-get="{% url 'shift-request-duplicate' shift_request.id %}?{{pg}}"
title="{% trans 'Duplicate' %}" hx-target="#objectCreateModalTarget"
style="cursor: pointer;">
<ion-icon name="copy-outline"></ion-icon>
{% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequest or request.user|is_reportingmanager %}
<a class="oh-btn oh-btn--light-bkg w-50" data-toggle="oh-modal-toggle"
data-target="#objectCreateModal"
hx-get="{% url 'shift-request-duplicate' shift_request.id %}?{{pg}}"
title="{% trans 'Duplicate' %}" hx-target="#objectCreateModalTarget"
style="cursor: pointer;">
<ion-icon name="copy-outline"></ion-icon>
</a>
{% endif %}
{% if request.user.employee_get == shift_request.employee_id or perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
{% if shift_request.approved == False and shift_request.canceled == False %}
<form action="{% url 'shift-request-delete' shift_request.id %}"
onsubmit="return confirm('{% trans "Are you sure you want to delete this shift request?" %}');"
method='post' class="w-75">
{% csrf_token %}
<button type='submit'
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
title="{% trans 'Remove' %}"><ion-icon
name="trash-outline"></ion-icon></button>
</form>
{% elif perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
<form action="{% url 'shift-request-delete' shift_request.id %}"
onsubmit="return confirm('{% trans "Are you sure you want to delete this shift request?" %}');"
method='post' class="w-75">
{% csrf_token %}
<button type='submit'
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
title="{% trans 'Remove' %}"><ion-icon
name="trash-outline"></ion-icon></button>
</form>
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled><ion-icon name="trash-outline"></ion-icon></button></td>
{% endif %}
{% endif %}
</div>
{% endif %}
</div>
{% if perms.base.change_shiftrequest or request.user|is_reportingmanager %}
<div class="oh-sticky-table__td oh-sticky-table__right " onclick="event.stopPropagation();">
<div class="oh-btn-group">
{% if shift_request.approved == False and shift_request.canceled == False %}
<a href="{% url 'shift-request-approve' shift_request.id %}"
title="{% trans 'Approve' %}" onclick="return confirm('{% trans "Do you want to approve this request?" %}')"
class="oh-btn oh-btn--success w-100">
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
</a>
{% else %}
<a href="#" title="{% trans 'Approve' %}"
class="oh-btn oh-btn--success oh-btn--disabled w-100">
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
</a>
{% endif %}
{% if request.user.employee_get == shift_request.employee_id or perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
{% if shift_request.approved == False and shift_request.canceled == False %}
<form action="{% url 'shift-request-delete' shift_request.id %}"
onsubmit="return confirm('{% trans "Are you sure you want to delete this shift request?" %}');"
method='post' class="w-75">
{% csrf_token %}
<button type='submit'
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
title="{% trans 'Remove' %}"><ion-icon
name="trash-outline"></ion-icon></button>
</form>
{% elif perms.base.delete_shiftrequest or request.user|is_reportingmanager %}
<form action="{% url 'shift-request-delete' shift_request.id %}"
onsubmit="return confirm('{% trans "Are you sure you want to delete this shift request?" %}');"
method='post' class="w-75">
{% csrf_token %}
<button type='submit'
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
title="{% trans 'Remove' %}"><ion-icon
name="trash-outline"></ion-icon></button>
</form>
{% else %}
<button class="oh-btn oh-btn--light-bkg w-50" disabled><ion-icon name="trash-outline"></ion-icon></button></td>
{% endif %}
{% if shift_request.canceled == False %}
<a href="{% url 'shift-request-cancel' shift_request.id %}"
title="{% trans 'Reject' %}"
onclick="return confirm('{% trans "Do you want to reject this request?" %}')"
class="oh-btn oh-btn--danger w-100">
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
</a>
{% else %}
<a type="submit" href="#" title="{% trans 'Reject' %}" class="oh-btn oh-btn--danger oh-btn--disabled w-100">
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
{% if perms.base.change_shiftrequest or request.user|is_reportingmanager %}
<div class="oh-sticky-table__td oh-sticky-table__right " onclick="event.stopPropagation();">
<div class="oh-btn-group">
{% if shift_request.approved == False and shift_request.canceled == False %}
<a href="{% url 'shift-request-approve' shift_request.id %}"
title="{% trans 'Approve' %}" onclick="return confirm('{% trans "Do you want to approve this request?" %}')"
class="oh-btn oh-btn--success w-100">
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
</a>
{% else %}
<a href="#" title="{% trans 'Approve' %}"
class="oh-btn oh-btn--success oh-btn--disabled w-100">
<ion-icon class="me-1" name="checkmark-outline"></ion-icon>
</a>
{% endif %}
{% if shift_request.canceled == False %}
<a href="{% url 'shift-request-cancel' shift_request.id %}"
title="{% trans 'Reject' %}"
onclick="return confirm('{% trans "Do you want to reject this request?" %}')"
class="oh-btn oh-btn--danger w-100">
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
</a>
{% else %}
<a type="submit" href="#" title="{% trans 'Reject' %}" class="oh-btn oh-btn--danger oh-btn--disabled w-100">
<ion-icon class="me-1" name="close-circle-outline"></ion-icon>
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>

View File

@@ -1,122 +1,88 @@
{% load i18n static %}
{% load basefilters %}
<style>
#enlargeImageContainer {
position: absolute;
left: -300px;
top: 100px;
height: 200px;
width: 200px;
}
#enlargeImageContainer {
position: absolute;
left: -300px;
top: 100px;
height: 200px;
width: 200px;
}
</style>
{% if messages %}
<div class="oh-alert-container">
{% for message in messages %}
<div class="oh-alert oh-alert--animated {{message.tags}}">{{ message }}</div>
{% endfor %}
</div>
<script>
setTimeout(() => {
$(".oh-modal__close").click();
}, 1000);
reloadMessage();
</script>
{% endif %}
<div class="oh-activity-sidebar__header">
<a
style="cursor: pointer;"
onclick="$('.oh-activity-sidebar--show').removeClass('oh-activity-sidebar--show');">
<ion-icon
name="chevron-forward-outline"
class="oh-activity-sidebar__header-icon me-2 oh-activity-sidebar__close"
data-target="#activitySidebar"
></ion-icon>
</a>
<span class="oh-activity-sidebar__title"> {% trans "Comments" %} </span>
</div>
{% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequestcomment or request.user|is_reportingmanager %}
<form hx-target="#commentContainer" hx-post="{% url 'shift-request-add-comment' request_id %}?{{pd}}" id="commentForm">
{% csrf_token %}
<div>
<input type="text" name="comment" id="commentInput" class="oh-input w-100" placeholder="Comment here">
<button type="submit" id="commentButton" class="oh-btn oh-btn--secondary mt-2 mr-0 oh-btn--w-100-resp" style="display: none;">
{% trans "Comment" %}
</button>
</div>
<div class="oh-inner-sidebar-content__footer"></div>
</form>
{% endif %}
<div class="oh-activity-sidebar__header">
<a style="cursor: pointer;" onclick="$('.oh-activity-sidebar--show').removeClass('oh-activity-sidebar--show');">
<ion-icon name="chevron-forward-outline"
class="oh-activity-sidebar__header-icon me-2 oh-activity-sidebar__close"
data-target="#activitySidebar"></ion-icon>
</a>
<span class="oh-activity-sidebar__title"> {% trans "Comments" %} </span>
</div>
{% if request.user.employee_get == shift_request.employee_id or perms.base.add_shiftrequestcomment or request.user|is_reportingmanager %}
<form hx-target="#commentContainer" hx-post="{% url 'shift-request-add-comment' request_id %}?{{pd}}" id="commentForm">
{% csrf_token %}
<div>
<input type="text" name="comment" id="commentInput" hx-on:keyup="toggleCommentButton(this);"
class="oh-input w-100" placeholder="Comment here">
<button type="submit" id="commentButton" class="oh-btn oh-btn--secondary mt-2 mr-0 oh-btn--w-100-resp"
style="display: none;">
{% trans "Comment" %}
</button>
</div>
<div class="oh-inner-sidebar-content__footer"></div>
</form>
{% endif %}
{% if comments %}
<ol class="oh-activity-sidebar__qa-list" role="list">
{% for comment in comments %}
<li class="oh-activity-sidebar__qa-item" id="commentCard{{comment.id}}">
<span class="oh-activity-sidebar__q">{{ comment.comment }}
{% if request.user.employee_get == shift_request.employee_id or perms.base.delete_shiftrequestcomment or request.user|is_reportingmanager %}
<span class="float-end" hx-on-htmx-after-request="$('#reloadMessagesButton').click();" hx-get='{% url "shift-request-delete-comment" comment.id %}' hx-swap="delete" hx-target="#commentCard{{comment.id}}">
<ion-icon name="close-outline" style="font-size: 24px" role="img" class="md hydrated" aria-label="close outline"></ion-icon></span>
{% if request.user.employee_get == comment.employee_id or perms.base.delete_shiftrequestcomment or request.user|is_reportingmanager %}
<span class="float-end" hx-on:click="setTimeout(() => {reloadMessage(this);},100);"
hx-get='{% url "shift-request-delete-comment" comment.id %}' hx-swap="outerHTML"
hx-target="#commentCard{{comment.id}}">
<ion-icon name="close-outline" style="font-size: 24px" role="img" class="md hydrated"
aria-label="close outline"></ion-icon></span>
{% endif %}
</span>
<div class="d-flex mt-2 mb-2">
{% for file in comment.files.all %}
<a
href="{{ file.file.url }}"
rel="noopener noreferrer"
target="_blank"
><span
class="oh-file-icon oh-file-icon--pdf"
onmouseover="enlargeImage('{{ file.file.url }}',$(this))"
style="width: 40px; height: 40px"
><img
src="{% static 'images/ui/minus-icon.png' %}"
style="display: block; width: 50%; height: 50%"
hx-get="{% url 'delete-shift-comment-file' %}?ids={{ file.id }}&shift_id={{ request_id }}"
hx-target="#commentContainer"
onclick="event.stopPropagation();event.preventDefault()" /></span
></a>
<a href="{{ file.file.url }}" rel="noopener noreferrer" target="_blank" id="shiftReqCommentFile{{file.id}}">
<span class="oh-file-icon oh-file-icon--pdf" onmouseover="enlargeImage('{{ file.file.url }}',$(this))" style="width: 40px; height: 40px">
{% if request.user.employee_get == comment.employee_id or perms.base.delete_baserequestfile or request.user|is_reportingmanager %}
<img src="{% static 'images/ui/minus-icon.png' %}" style="display: block; width: 50%; height: 50%" onclick="event.stopPropagation();event.preventDefault()"
hx-get="{% url 'delete-shift-comment-file' %}?ids={{ file.id }}&shift_id={{ request_id }}&comment_id={{comment.id}}" hx-target="#shiftReqCommentFile{{file.id}}"
hx-swap="outerHTML" hx-on:click="setTimeout(() => {reloadMessage(this);},100);"
/>
{% endif %}
</span>
</a>
{% endfor %}
<form
hx-post="{% url 'view-shift-comment' comment.request_id.id %}?comment_id={{ comment.id }}"
class="add-files-form"
hx-encoding="multipart/form-data"
data-target="#activitySidebar" hx-swap="innerHTML" hx-target="#commentContainer"
>
{% csrf_token %}
<label for="addFile_{{comment.id}}" title="Add Files"
><ion-icon
name="add-outline"
style="font-size: 24px"
role="img"
class="md hydrated"
aria-label="add outline"
></ion-icon
></label>
<input
type="file"
name="files"
class="d-none"
multiple="true"
accept=".jpg, .jpeg, .png, .pdf"
id="addFile_{{comment.id}}"
onchange="submitForm(this)"
/>
<input
type="submit"
class="d-none add_more_submit"
value="save"
/>
</form>
{% if request.user.employee_get == comment.employee_id or perms.base.add_baserequestfile or request.user|is_reportingmanager %}
<form hx-post="{% url 'view-shift-comment' comment.request_id.id %}?comment_id={{ comment.id }}"
class="add-files-form" hx-encoding="multipart/form-data" data-target="#activitySidebar"
hx-swap="innerHTML" hx-target="#commentContainer">
{% csrf_token %}
<label for="addFile_{{comment.id}}" \><ion-icon name="add-outline" style="font-size: 24px" role="img"
class="md hydrated" aria-label="add outline"></ion-icon></label>
<input type="file" name="files" class="d-none" multiple="true" accept=".jpg, .jpeg, .png, .pdf"
id="addFile_{{comment.id}}" onchange="submitForm(this)" />
<input type="submit" class="d-none add_more_submit" value="save" />
</form>
{% endif %}
</div>
<span class="oh-activity-sidebar__a">
{% trans 'by' %}
<img
src="{{ note.note_by.get_avatar }}"
style="width: 1.5em; border-radius: 100%"
/>
<img src="{{ note.note_by.get_avatar }}" style="width: 1.5em; border-radius: 100%" />
{{ comment.employee_id.get_full_name }} @ {{comment.request_id.employee_id.get_full_name }}
{% trans "'s shift request" %}
</span>
@@ -124,52 +90,15 @@
<div id="enlargeImageContainer" class="enlargeImageContainer"></div>
</div>
</li>
{% endfor %}
</ol>
{% else %}
<div class="oh-timeoff-modal__profile-content">
<div class="oh-404">
<div class="">
<span class="oh-timeoff-title fw-bold" style="display: block"
>{% trans "There are no comments to show." %}</span
>
<img
style="display: block; width: 100px; margin: 20px auto"
src="{% static "/images/ui/comment.png" %}"
class=""
/>
<span class="oh-timeoff-title fw-bold" style="display: block">{% trans "There are no comments to show." %}</span>
<img style="display: block; width: 100px; margin: 20px auto" src="{% static "/images/ui/comment.png" %}" class="" />
</div>
</div>
</div>
{% endif %}
<!-- start of comment modal -->
<div
class="oh-modal"
id="shiftcommentModal"
role="dialog"
aria-labelledby="emptagModal"
aria-hidden="true"
>
<div class="oh-modal__dialog" id="shiftRequestCommentForm">
</div>
</div>
<!-- end of comment modal -->
<script>
// Get references to the input field and comment button
const commentInput = document.getElementById('commentInput');
const commentButton = document.getElementById('commentButton');
// Add event listener to the input field
commentInput.addEventListener('input', function() {
// Show the comment button if the input field is not empty, hide it otherwise
if (commentInput.value.trim() !== '') {
commentButton.style.display = 'inline';
} else {
commentButton.style.display = 'none';
}
});
</script>