Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from dibik96/17.0-develop
Browse files Browse the repository at this point in the history
SR-53: Changes in members form validation and member form jquery.
  • Loading branch information
shibu-narayanan authored May 15, 2024
2 parents d3c9226 + 3215623 commit 9c6875c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 45 deletions.
18 changes: 9 additions & 9 deletions g2p_service_provider_benificiary_management/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def update_member(self, **kw):
"family_name": beneficiary.family_name,
"dob": str(beneficiary.birthdate),
"gender": beneficiary.gender,
"id": beneficiary.id,
}
return json.dumps(exist_value)

Expand All @@ -283,6 +284,7 @@ def update_member(self, **kw):
def update_member_submit(self, **kw):
try:
member = request.env["res.partner"].sudo().browse(int(kw.get("member_id")))

res = dict()
if member:
# birthdate = datetime.strptime(kw["birthdate"], "%Y-%m-%d").date()
Expand All @@ -302,21 +304,19 @@ def update_member_submit(self, **kw):
"gender": kw.get("gender"),
}
)
group = request.env["res.partner"].sudo().browse(int(kw.get("group_id")))
# group = request.env["res.partner"].sudo().browse(int(kw.get("group_id")))
member_list = []

for membership in group.group_membership_ids:
for membership in member:
member_list.append(
{
"id": membership.individual.id,
"name": membership.individual.name,
"age": membership.individual.age,
"gender": membership.individual.gender,
"active": membership.individual.active,
"group_id": membership.group.id,
"id": membership.id,
"name": membership.name,
"age": membership.age,
"gender": membership.gender,
"active": membership.active,
}
)

res["member_list"] = member_list
return json.dumps(res)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@ $(document).ready(function () {
});
});

// eslint-disable-next-line no-unused-vars
function validateForm(isCreateForm) {
var requiredFields = document.querySelectorAll(".s_website_form_field [required]");
var isValid = true;

requiredFields.forEach(function (field) {
if (!field.value.trim()) {
// If the field is empty, display an error message next to the field
var errorMessage = document.createElement("span");
errorMessage.className = "error-message";
errorMessage.textContent = "This field is required";
errorMessage.style.color = "red";

// Check if an error message already exists for the field
var existingErrorMessage = field.parentNode.querySelector(".error-message");
if (existingErrorMessage) {
// If an error message already exists, replace it
field.parentNode.replaceChild(errorMessage, existingErrorMessage);
} else {
// Otherwise, insert the error message after the field
field.parentNode.insertBefore(errorMessage, field.nextSibling);
}

// Add red border to indicate the missing field
field.style.border = "1px solid red";
isValid = false;
} else {
// If the field is filled, remove any previous error message and styling
var existingErrorMessage = field.parentNode.querySelector(".error-message");
if (existingErrorMessage) {
existingErrorMessage.parentNode.removeChild(existingErrorMessage);
Expand All @@ -43,10 +38,8 @@ function validateForm(isCreateForm) {
});

if (isValid && isCreateForm) {
// If all required fields are filled and it's a create form, submit the form
document.getElementById("creategroupForm").submit();
} else if (isValid && !isCreateForm) {
// If all required fields are filled and it's not a create form, submit the form
document.getElementById("updategroupForm").submit();
}
}
Expand All @@ -58,6 +51,7 @@ function showToast(message) {
toast_container.css("display", "block");
}

// eslint-disable-next-line no-unused-vars
function hideToast() {
const toast_container = $("#memberDetailModal #toast-container");
toast_container.css("display", "none");
Expand All @@ -66,11 +60,22 @@ function hideToast() {
function resetFormFields() {
$("#memberDetailModal input, #memberDetailModal select").val("");
}
// Serial no
const alltable = document.getElementById("memberlist");
const tbody = alltable.getElementsByTagName("tbody");
const totalRow = tbody[0].children.length;

function addTableSrNo() {
for (let i = 0; i < totalRow; i++) {
tbody[0].children[i].firstElementChild.innerText = i + 1;
}
}
// END serial no

// Replace button
$('[data-bs-target="#memberDetailModal"]').on("click", function () {
$("#update-member-btn").replaceWith(
'<div id="member_submit" type="button" class="btn btn-primary create-new">Add</div>'
'<button id="member_submit" type="button" class="btn btn-primary create-new">Add</button>'
);
resetFormFields();
});
Expand All @@ -87,7 +92,6 @@ $(document).on("click", "#member_submit", function () {
var middleName = $("#memberDetailModal #addl_name").val();
var lastName = $("#memberDetailModal #family_name").val();
var dob = $("#memberDetailModal #birthdate").val();
console.log("DOB###########", dob, Householddob);
var gender = $('#memberDetailModal select[name="gender"]').val();
var relationship = $('#memberDetailModal select[name="relationship"]').val();
var isValid = true;
Expand Down Expand Up @@ -175,7 +179,7 @@ $(document).on("click", "#member_submit", function () {
"</div>" +
"</td>" +
"<td>" +
'<button class="btn btn-icon rounded-0" id="mem-update" store="' +
'<button class="btn btn-icon rounded-0" type="button" id="mem-update" store="' +
member.id +
'" title="Edit">' +
'<i class="fa fa-pencil"></i>' +
Expand All @@ -201,6 +205,7 @@ $(document).on("click", "#member_submit", function () {
$(document).on("click", "#mem-update", function () {
var memberId = $(this).attr("store");
var modal = $("#memberDetailModal");

$.ajax({
url: "/serviceprovider/member/update/",
method: "POST",
Expand All @@ -218,10 +223,11 @@ $(document).on("click", "#mem-update", function () {

// Replace button
$("#member_submit").replaceWith(
'<div id="update-member-btn" store="' +
memberId +
'" class="btn btn-primary create-new">Update</div>'
'<button type="button" id="update-member-btn" store="' +
response.id +
'" class="btn btn-primary create-new">Update</button>'
);
$("#update-member-btn").attr("store", response.id);

// Show the modal
modal.modal("show");
Expand Down Expand Up @@ -281,14 +287,11 @@ $(document).on("click", "#update-member-btn", function () {
// Check if member_list exists in the response
if (response && response.member_list) {
var member_list = response.member_list;
$("#memberDetailModal").modal("hide");

// Get the table body
var tableBody = $("#memberlist tbody");
tableBody.empty();
$("#memberDetailModal").modal("hide");

member_list.forEach(function (member, index) {
var serialNumber = index + 1;
member_list.forEach(function (member) {
var serialNumber = 0;
var newRowHtml =
"<tr>" +
"<td>" +
Expand All @@ -312,16 +315,19 @@ $(document).on("click", "#update-member-btn", function () {
"</div>" +
"</td>" +
"<td>" +
'<button class="btn btn-icon rounded-0" id="mem-update" store="' +
'<button class="btn btn-icon rounded-0" type="button" id="mem-update" store="' +
member.id +
'" title="Edit">' +
'<i class="fa fa-pencil"></i>' +
"</button>" +
"</td>" +
"</tr>";
console.log("newRowHtml########", newRowHtml);
tableBody.append(newRowHtml);

$("#mem-update[store='" + memberId + "']")
.closest("tr")
.replaceWith(newRowHtml);
});
addTableSrNo();
} else {
console.error("FINAL Member list not found in the response.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const tbody = alltable.getElementsByTagName("tbody");
const totalRow = tbody[0].children.length;
const itemsPerPage = 7;
let currentPage = 1;

function addTableSrNo() {
for (let i = 0; i < totalRow; i++) {
tbody[0].children[i].firstElementChild.innerText = i + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
<tr>
<th>Sr.No.</th>
<th>Household Name <i class="fa fa-sort" /></th>
<th>Region <i class="fa fa-sort" /></th>
<th>Kebele <i class="fa fa-sort" /></th>
<th>Members</th>
<th>Last Updated </th>
<th>Enumerator</th>
Expand All @@ -86,12 +84,6 @@
>
<t t-out="group['name']" />
</td>
<td>
<t t-out="group['region']" />
</td>
<td>
<t t-out="group['kebele']" />
</td>
<td>
<t t-out="len(group['group_membership_ids'])" />
</td>
Expand Down Expand Up @@ -170,7 +162,7 @@
</ol>
<div id="toast-container">
<div id="toast-message" />
<button id="toast-close-btn" onclick="hideToast()">
<button type="button" id="toast-close-btn" onclick="hideToast()">
<img
src="/g2p_service_provider_portal_base/static/src/img/[email protected]"
/>
Expand Down Expand Up @@ -507,6 +499,7 @@
type="text"
id="given_name"
name="given_name"
required="required"
class="form-control"
/>
</div>
Expand Down Expand Up @@ -552,6 +545,7 @@
type="text"
id="family_name"
name="family_name"
required="required"
class="form-control"
/>
</div>
Expand Down Expand Up @@ -580,6 +574,7 @@
type="date"
id="birthdate"
name="birthdate"
required="required"
class="form-control date-picker"
/>
</div>
Expand All @@ -604,6 +599,7 @@
<select
class="form-select"
name="gender"
required="required"
>
<option value="">
Select</option>
Expand Down Expand Up @@ -689,6 +685,7 @@
<div id="toast-message" />
<button
id="toast-close-btn"
type="button"
onclick="hideToast()"
>
<img
Expand Down Expand Up @@ -723,10 +720,6 @@
>
Submit
</button>




</div>
</div>
</div>
Expand Down Expand Up @@ -1055,6 +1048,7 @@
type="text"
id="given_name"
name="given_name"
required="required"
class="form-control"
/>
</div>
Expand Down Expand Up @@ -1100,6 +1094,7 @@
type="text"
id="family_name"
name="family_name"
required="required"
class="form-control"
/>
</div>
Expand Down Expand Up @@ -1128,6 +1123,7 @@
type="date"
id="birthdate"
name="birthdate"
required="required"
class="form-control date-picker"
/>
</div>
Expand All @@ -1152,6 +1148,7 @@
<select
class="form-select"
name="gender"
required="required"
>
<option value="">
Select</option>
Expand Down Expand Up @@ -1237,6 +1234,7 @@
<div id="toast-message" />
<button
id="toast-close-btn"
type="button"
onclick="hideToast()"
>
<img
Expand Down

0 comments on commit 9c6875c

Please sign in to comment.