refactor(module_auth): form validation
This commit is contained in:
@@ -533,7 +533,7 @@ class AppRoleArchiveView(AppRoleView):
|
||||
template_name = "module_iam/iam_role_archive.html"
|
||||
|
||||
|
||||
class PrincipalProfileView(permission.ResourcePermissionRequiredMixin, LoginRequiredMixin, generic.TemplateView):
|
||||
class PrincipalProfileView( LoginRequiredMixin, generic.TemplateView):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_DASHBOARD
|
||||
resource = iam_constant.RESOURCE_MANAGE_DASHBOARD
|
||||
model = IAmPrincipal
|
||||
@@ -553,7 +553,7 @@ class PrincipalProfileView(permission.ResourcePermissionRequiredMixin, LoginRequ
|
||||
return context
|
||||
|
||||
|
||||
class PrincipalProfileEditView(permission.ResourcePermissionRequiredMixin, LoginRequiredMixin, generic.View):
|
||||
class PrincipalProfileEditView(LoginRequiredMixin, generic.View):
|
||||
page_name = iam_constant.RESOURCE_MANAGE_DASHBOARD
|
||||
resource = iam_constant.RESOURCE_MANAGE_DASHBOARD
|
||||
model = IAmPrincipal
|
||||
|
||||
@@ -155,7 +155,7 @@ def notification_for_symptom():
|
||||
try:
|
||||
notification = OneSignalService()
|
||||
response = notification.send_notification(
|
||||
headings="Medication",
|
||||
headings="Symptom",
|
||||
contents=notification_message,
|
||||
include_player_ids=player_ids,
|
||||
)
|
||||
|
||||
@@ -261,10 +261,10 @@ LOGGING = {
|
||||
# jwt configuration
|
||||
# https://django-rest-framework-simplejwt.readthedocs.io/en/latest/settings.html#settings
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": datetime.timedelta(days=15),
|
||||
"ACCESS_TOKEN_LIFETIME": datetime.timedelta(minutes=5),
|
||||
"REFRESH_TOKEN_LIFETIME": datetime.timedelta(days=15),
|
||||
"ROTATE_REFRESH_TOKENS": False,
|
||||
"BLACKLIST_AFTER_ROTATION": False,
|
||||
"BLACKLIST_AFTER_ROTATION": True,
|
||||
"UPDATE_LAST_LOGIN": False,
|
||||
"ALGORITHM": "HS256",
|
||||
"SIGNING_KEY": SECRET_KEY,
|
||||
|
||||
@@ -350,7 +350,7 @@
|
||||
Filter
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink" style="">
|
||||
<a class="dropdown-item" href="javascript:void(0)" onclick="getReportData(7)">Last 7 days</a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" onclick="getReportData('7')">Last 7 days</a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" onclick="getReportData(20)">Last 20 days</a>
|
||||
<a class="dropdown-item" href="javascript:void(0)" onclick="getReportData(30)">Last 30 days</a>
|
||||
{% comment %} <a class="dropdown-item" href="javascript:void(0)" onclick="getReportData(40)">Last 40 days</a> {% endcomment %}
|
||||
@@ -393,13 +393,13 @@ var mealUrl = "{% url 'module_activity:meal_detail' pk=0 %}"
|
||||
var medicationUrl = "{% url 'module_activity:medication_detail' pk=0 %}"
|
||||
var bowelUrl = "{% url 'module_activity:bowel_detail' pk=0 %}"
|
||||
var symptomUrl = "{% url 'module_activity:meal_symptom_detail' pk=0 %}"
|
||||
var reportUrl = "{% url 'module_activity:report_data' principal_id=obj.id %}?date_range=7"
|
||||
var reportUrl = "{% url 'module_activity:report_data' principal_id=obj.id %}?date_range=20"
|
||||
|
||||
// Entry point
|
||||
$(document).ready(function() {
|
||||
tableName = $('#table');
|
||||
//dataTableInstance = initializeDataTable(tableName, activityMainUrl);
|
||||
getReportData();
|
||||
//getReportData();
|
||||
});
|
||||
|
||||
// Function to initialize DataTable
|
||||
@@ -524,6 +524,7 @@ function filterActivityData(dateRange){
|
||||
|
||||
|
||||
function getReportData(timeRange){
|
||||
console.log("data range is ", timeRange)
|
||||
var url = timeRange ? reportUrl.replace("7", timeRange) : reportUrl
|
||||
$('#pills-tab3Content').empty()
|
||||
$.ajax({
|
||||
|
||||
@@ -336,9 +336,7 @@ function viewClickEvent(dataTableInstance) {
|
||||
$('body').on('click', '.view', function(){
|
||||
var id =$(this).data('id');
|
||||
var rowData = dataTableInstance.row($(this).closest('tr')).data();
|
||||
var question = rowData.question;
|
||||
var answer = rowData.answer;
|
||||
console.log(question, answer)
|
||||
|
||||
// Set the data in the modal content
|
||||
$('#questionData').text(question);
|
||||
$('#answerData').text(answer);
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/.test(value);
|
||||
}, "Please enter a valid email address.");
|
||||
|
||||
$.validator.addMethod("noSpace", function(value, element) {
|
||||
return value.indexOf(" ") < 0 && value != "";
|
||||
}, "Spaces are not allowed.");
|
||||
|
||||
// Add custom validation method to check for special characters
|
||||
$.validator.addMethod("noSpecialChars", function(value, element) {
|
||||
return /^[a-zA-Z\s]*$/.test(value); // Allow only letters and whitespace
|
||||
@@ -78,14 +82,16 @@
|
||||
minlength: 2,
|
||||
maxlength: 20,
|
||||
noSpecialChars: true,
|
||||
startsWithLetter: true
|
||||
startsWithLetter: true,
|
||||
noSpace: true
|
||||
},
|
||||
last_name: {
|
||||
required: true,
|
||||
minlength: 2,
|
||||
maxlength: 20,
|
||||
noSpecialChars: true,
|
||||
startsWithLetter: true
|
||||
startsWithLetter: true,
|
||||
noSpace: true
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
@@ -139,6 +145,7 @@
|
||||
submitHandler: function(form) {
|
||||
// Disable the submit button to prevent multiple submissions
|
||||
$('button[type="submit"]').prop('disabled', true);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,6 +87,11 @@
|
||||
format: 'YYYY-MM-DD', // Set the date format to match your validation rule
|
||||
maxDate: today
|
||||
});
|
||||
|
||||
$.validator.addMethod("noSpace", function(value, element) {
|
||||
return value.indexOf(" ") < 0 && value != "";
|
||||
}, "Spaces are not allowed.");
|
||||
|
||||
|
||||
// Add custom validation method to check for special characters
|
||||
$.validator.addMethod("noSpecialChars", function(value, element) {
|
||||
@@ -106,14 +111,16 @@
|
||||
minlength: 2,
|
||||
maxlength:15,
|
||||
noSpecialChars: true,
|
||||
startsWithLetter: true
|
||||
startsWithLetter: true,
|
||||
noSpace: true
|
||||
},
|
||||
last_name: {
|
||||
required: true,
|
||||
minlength: 2,
|
||||
maxlength: 15,
|
||||
noSpecialChars: true,
|
||||
startsWithLetter: true
|
||||
startsWithLetter: true,
|
||||
noSpace: true
|
||||
},
|
||||
date_of_birth: {
|
||||
required: true,
|
||||
@@ -171,6 +178,11 @@
|
||||
unhighlight: function(element, errorClass, validClass) {
|
||||
$(element).removeClass('is-invalid').addClass('is-valid');
|
||||
},
|
||||
submitHandler: function(form) {
|
||||
// Disable the submit button to prevent multiple submissions
|
||||
$('button[type="submit"]').prop('disabled', true);
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -67,57 +67,28 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Message/ reply modal -->
|
||||
<div class="modal fade" id="tabsModalMessageReply" tabindex="-1" role="dialog" aria-labelledby="tabsModalLabel" aria-hidden="true">
|
||||
<!-- modal for View Feedback Question Answer -->
|
||||
<div class="modal fade" id="feedbackmodal" tabindex="-1" role="dialog" aria-labelledby="feedbackmodalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content" >
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="tabsModalLabel">Message / Reply</h5>
|
||||
<h5 class="modal-title" id="feedbackmodalLabel">Feedback</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<p class="mt-3" id="emailData"></p>
|
||||
<p class="mt-3" id="subjectData"></p>
|
||||
<div class="card mb-2">
|
||||
<div class="card-body">
|
||||
<p class="mb-0" id="messageText"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="simple-pill">
|
||||
|
||||
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link active" id="pills-message-tab" data-bs-toggle="pill" data-bs-target="#pills-message" type="button" role="tab" aria-controls="pills-message" aria-selected="true">Message</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="pills-reply-tab" data-bs-toggle="pill" data-bs-target="#pills-reply" type="button" role="tab" aria-controls="pills-reply" aria-selected="false">Reply</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="pills-tabContent">
|
||||
<div class="tab-pane fade show active" id="pills-message" role="tabpanel" aria-labelledby="pills-message-tab" tabindex="0">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="mt-3" id="messageData"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="tab-pane fade" id="pills-reply" role="tabpanel" aria-labelledby="pills-reply-tab" tabindex="0">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="mt-3" id="replyData"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-light-dark" data-bs-dismiss="modal">Discard</button>
|
||||
<button class="btn btn-dark" data-bs-dismiss="modal">Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% block javascript %}
|
||||
@@ -156,7 +127,13 @@ function initializeDataTable(tableName, mainUrl) {
|
||||
{ data: "id", className: "text-center" },
|
||||
{ data: "principal" },
|
||||
{ data: "feedback_reaction" },
|
||||
{ data: "comment" },
|
||||
{
|
||||
data: "comment",
|
||||
render: function (data, type, row) {
|
||||
console.log(data)
|
||||
return `<button class="btn btn-primary view-comment" onclick="showDataModal('${data}')">View</button>`;
|
||||
}
|
||||
}
|
||||
],
|
||||
debug: true,
|
||||
columnDefs: [
|
||||
@@ -201,6 +178,12 @@ function reloadDataTable() {
|
||||
dataTableInstance.ajax.reload();
|
||||
}
|
||||
|
||||
function showDataModal(data) {
|
||||
console.log(data)
|
||||
$('#messageText').text(data);
|
||||
$('#feedbackmodal').modal('show');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user