diff --git a/employee/static/employee/actions.js b/employee/static/employee/actions.js index 4a20ef8c2..54d793a80 100644 --- a/employee/static/employee/actions.js +++ b/employee/static/employee/actions.js @@ -29,6 +29,16 @@ var norowMessages = { en: "No rows have been selected.", fr: "Aucune ligne n'a été sélectionnée.", }; + +var selectedemployees = { + ar: " موظفون محددون", + de: " Ausgewählte Mitarbeiter", + es: " Empleados seleccionados", + en: " Selected Employees", + fr: " Employés sélectionnés", +}; + + function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== "") { @@ -63,15 +73,70 @@ $(".all-employee").change(function (e) { } else { $(".all-employee-row").prop("checked", false); } + addingIds() }); -$(".all-employee").change(function (e) { - var is_checked = $(this).is(":checked"); - if (is_checked) { - $(".all-employee-row").prop("checked", true); - } else { - $(".all-employee-row").prop("checked", false); + + +$(".all-employee-row").change(function(){ + addingIds() +}) + + +function addingIds(){ + var ids = JSON.parse($("#selectedInstances").attr("data-ids") || "[]"); + var selectedCount = 0; + + $(".all-employee-row").each(function() { + if ($(this).is(":checked")) { + ids.push(this.id); + } else { + var index = ids.indexOf(this.id); + if (index > -1) { + ids.splice(index, 1); + } + } + }); + var ids = makeListUnique(ids); + var selectedCount = ids.length; + + getCurrentLanguageCode(function(code){ + languageCode = code; + var message = selectedemployees[languageCode]; + + $("#selectedInstances").attr("data-ids", JSON.stringify(ids)); + $('#selectedshow').text(selectedCount + ' -' + message); + }) + +} + + +function tickCheckboxes(uniqueIds) { + + click = $("#selectedInstances").attr("data-clicked") + if ( click === '1'){ + $(".all-employee").prop('checked',true) } -}); + + uniqueIds.forEach(function(id) { + $('#' + id).prop('checked', true); + }); + var selectedCount = uniqueIds.length; + getCurrentLanguageCode(function(code){ + languageCode = code; + var message = selectedemployees[languageCode]; + $('#selectedshow').text(selectedCount + ' -' + message); + }) + +} + + +function makeListUnique(list) { + return Array.from(new Set(list)); +} + +var ids = JSON.parse($("#selectedInstances").attr("data-ids") || "[]"); +tickCheckboxes(ids); + $("#archiveEmployees").click(function (e) { e.preventDefault(); var languageCode = null; @@ -97,11 +162,12 @@ $("#archiveEmployees").click(function (e) { }).then(function (result) { if (result.isConfirmed) { e.preventDefault(); + ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - + + ids.push($("#selectedInstances").attr("data-ids")) + ids = JSON.parse($("#selectedInstances").attr("data-ids")); + $.ajax({ type: "POST", url: "/employee/employee-bulk-archive?is_active=False", @@ -147,12 +213,13 @@ $("#unArchiveEmployees").click(function (e) { confirmButtonText: "Confirm", }).then(function (result) { if (result.isConfirmed) { - var checkedRows = $(".all-employee-row").filter(":checked"); + e.preventDefault(); + ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - + + ids.push($("#selectedInstances").attr("data-ids")) + ids = JSON.parse($("#selectedInstances").attr("data-ids")); + $.ajax({ type: "POST", url: "/employee/employee-bulk-archive?is_active=True", @@ -198,13 +265,13 @@ $("#deleteEmployees").click(function (e) { confirmButtonText: "Confirm", }).then(function (result) { if (result.isConfirmed) { - var checkedRows = $(".all-employee-row").filter(":checked"); + e.preventDefault(); + ids = []; - checkedRows.each(function () { - ids.push($(this).attr("id")); - }); - - $.ajax({ + ids.push($("#selectedInstances").attr("data-ids")) + ids = JSON.parse($("#selectedInstances").attr("data-ids")); + + $.ajax({ type: "POST", url: "/employee/employee-bulk-delete", data: { diff --git a/employee/templates/employee/profile/profile.html b/employee/templates/employee/profile/profile.html index e9fbd0b5f..11e6d8bb7 100644 --- a/employee/templates/employee/profile/profile.html +++ b/employee/templates/employee/profile/profile.html @@ -46,7 +46,9 @@ // Active tab script function activeCandTab() { var activeTab = localStorage.getItem("activeCandTab") - if(activeTab != null){ + if (!$(activeTab).length && $(`[data-target="#personal"]`).length) { + $(`[data-target="#personal"]`)[0].click() + }else if(activeTab != null){ $(".oh-general__tab-link--active").removeClass("oh-general__tab-link--active"); $(`[data-target='${activeTab}']`).addClass("oh-general__tab-link--active"); $(".oh-general__tab-target").addClass("d-none"); diff --git a/employee/templates/employee_nav.html b/employee/templates/employee_nav.html index a7ad42e35..3947e3d38 100644 --- a/employee/templates/employee_nav.html +++ b/employee/templates/employee_nav.html @@ -165,7 +165,7 @@
- {% endif %} {% if data %} + {% endif %} {% if emp %}